Skip to content

Commit 9c78d27

Browse files
committed
Split M3U & M3U8, remove encoding argument in read and write
- Remove encoding arguments - Split M3U provider and playlist in M3U & M3U8
1 parent bb07145 commit 9c78d27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+589
-532
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ sourceSets {
8585

8686

8787
group = 'io.github.borewit'
88-
version = '3.0.1'
88+
version = '4.0.0'
8989
description = 'Lizzy'
9090
java.sourceCompatibility = JavaVersion.VERSION_1_9
9191

src/main/java/io/github/borewit/lizzy/playlist/AbstractPlaylist.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/java/io/github/borewit/lizzy/playlist/AbstractPlaylistProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public abstract class AbstractPlaylistProvider implements SpecificPlaylistProvid
1111
@Override
1212
public SpecificPlaylist readFrom(final InputStream inputStream) throws IOException
1313
{
14-
return this.readFrom(inputStream, null);
14+
return this.readFrom(inputStream);
1515
}
1616

1717
public static BOMInputStream wrapInBomStream(InputStream inputStream)

src/main/java/io/github/borewit/lizzy/playlist/JaxbPlaylistProvider.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
import java.nio.charset.Charset;
1212
import java.nio.charset.StandardCharsets;
1313

14-
public abstract class JaxbPlaylistProvider<T> extends AbstractPlaylistProvider
14+
public abstract class JaxbPlaylistProvider<T> extends ProviderWithTextEncoding
1515
{
1616
private final Class<T> xmlClass;
1717
private JAXBContext jaxbContext = null;
1818

19+
public static final Charset defaultXmlTextEncoding = StandardCharsets.UTF_8;
20+
1921
public JaxbPlaylistProvider(Class<T> xmlClass)
2022
{
23+
super(defaultXmlTextEncoding);
2124
this.xmlClass = xmlClass;
2225
}
2326

@@ -38,32 +41,27 @@ private JAXBContext getJaxbContext() throws JAXBException
3841
}
3942
}
4043

41-
protected Charset getDefaultEncoding() {
42-
return StandardCharsets.UTF_8;
43-
}
44-
45-
protected JAXBElement<T> unmarshal(final InputStream in, final String encoding) throws JAXBException, XMLStreamException
44+
protected JAXBElement<T> unmarshal(final InputStream in) throws JAXBException, XMLStreamException
4645
{
47-
String applyEncoding = encoding == null ? this.getDefaultEncoding().toString() : encoding;
4846
Unmarshaller unmarshaller = this.getJaxbContext().createUnmarshaller();
49-
XMLStreamReader xmlStreamReader = this.getXmlStreamReader(in, applyEncoding);
47+
XMLStreamReader xmlStreamReader = this.getXmlStreamReader(in, this.textEncoding.name());
5048
return unmarshaller.unmarshal(xmlStreamReader, this.getXmlCLass());
5149
}
5250

5351
protected Marshaller makeMarshaller(String encoding) throws JAXBException
5452
{
5553
Marshaller marshaller = this.getJaxbContext().createMarshaller();
5654
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
57-
marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding == null ? this.getDefaultEncoding().name() : encoding);
55+
marshaller.setProperty(Marshaller.JAXB_ENCODING, this.textEncoding.name());
5856
return marshaller;
5957
}
6058

61-
public void writeTo(Object xmlPlaylist, final OutputStream out, final String encoding) throws IOException
59+
public void writeTo(Object xmlPlaylist, final OutputStream out) throws IOException
6260
{
6361
try
6462
{
6563
// Marshal the playlist.
66-
Marshaller marshaller = makeMarshaller(encoding);
64+
Marshaller marshaller = makeMarshaller(this.textEncoding.name());
6765

6866
marshaller.marshal(xmlPlaylist, out);
6967
out.flush(); // May throw IOException.

src/main/java/io/github/borewit/lizzy/playlist/PlaylistFormat.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public enum PlaylistFormat
66
atom,
77
b4s,
88
m3u,
9+
m3u8,
910
mpcpl,
1011
pla,
1112
plist,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.github.borewit.lizzy.playlist;
2+
3+
import java.nio.charset.Charset;
4+
5+
public abstract class PlaylistWithTextEncoding implements SpecificPlaylist
6+
{
7+
protected final ProviderWithTextEncoding providerWithTextEncoding;
8+
9+
protected PlaylistWithTextEncoding(ProviderWithTextEncoding providerWithTextEncoding) {
10+
this.providerWithTextEncoding = providerWithTextEncoding;
11+
}
12+
13+
public void setTextEncoding(Charset textEncoding) {
14+
this.providerWithTextEncoding.setTextEncoding(textEncoding);
15+
}
16+
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.borewit.lizzy.playlist;
2+
3+
import java.nio.charset.Charset;
4+
5+
abstract class ProviderWithTextEncoding implements SpecificPlaylistProvider
6+
{
7+
protected Charset textEncoding;
8+
9+
protected ProviderWithTextEncoding(Charset defaultTextEncoding) {
10+
this.textEncoding = defaultTextEncoding;
11+
}
12+
13+
public void setTextEncoding(Charset textEncoding) {
14+
this.textEncoding = textEncoding;
15+
}
16+
}

src/main/java/io/github/borewit/lizzy/playlist/SpecificPlaylist.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,13 @@ public interface SpecificPlaylist
4242
*/
4343
SpecificPlaylistProvider getProvider();
4444

45-
/**
46-
* Writes this specific playlist to the specified output stream.
47-
* When done, the stream may be flushed, but not closed.
48-
*
49-
* @param out an output stream. Shall not be <code>null</code>.
50-
* @param encoding the content encoding of the output resource, or <code>null</code> if not known.
51-
* @throws NullPointerException if <code>out</code> is <code>null</code>.
52-
* @throws Exception if any error occurs during the marshalling process.
53-
* @see SpecificPlaylistFactory#readFrom
54-
* @see SpecificPlaylistProvider#readFrom
55-
*/
56-
void writeTo(OutputStream out, String encoding) throws IOException;
57-
5845
/**
5946
* Writes this specific playlist to the specified output stream, using default encoding
6047
* When done, the stream may be flushed, but not closed.
6148
*
6249
* @param out an output stream. Shall not be <code>null</code>.
6350
* @throws NullPointerException if <code>out</code> is <code>null</code>.
64-
* @throws Exception if any error occurs during the marshalling process.
51+
* @throws IOException if any error occurs during the marshalling process.
6552
* @see SpecificPlaylistFactory#readFrom
6653
* @see SpecificPlaylistProvider#readFrom
6754
*/

src/main/java/io/github/borewit/lizzy/playlist/SpecificPlaylistFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ public SpecificPlaylist readFrom(Path playlistPath, OpenOption... options) throw
117117
{
118118
try
119119
{
120-
final String encoding = playlistPath.toString().toLowerCase().endsWith(".m3u8") ? "UTF-8" : null;
121-
SpecificPlaylist specificPlaylist = playlistProvider.readFrom(is, encoding);
120+
SpecificPlaylist specificPlaylist = playlistProvider.readFrom(is);
122121
if (specificPlaylist != null)
123122
return specificPlaylist;
124123
}
@@ -164,7 +163,7 @@ public SpecificPlaylist readFrom(final URL url) throws IOException
164163
final InputStream in = urlConnection.getInputStream(); // May throw IOException, UnknownServiceException.
165164
try
166165
{
167-
ret = service.readFrom(in, contentEncoding); // May throw Exception. Shall not throw NullPointerException because of in.
166+
ret = service.readFrom(in); // May throw Exception. Shall not throw NullPointerException because of in.
168167
if (ret == null) continue;
169168
break;
170169
}

src/main/java/io/github/borewit/lizzy/playlist/SpecificPlaylistProvider.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,19 @@ public interface SpecificPlaylistProvider
5353
*/
5454
ContentType[] getContentTypes();
5555

56-
/**
57-
* Reads a playlist from the specified input-stream.
58-
* When done, the stream remains open.
59-
*
60-
* @param inputStream an input stream. Shall not be <code>null</code>.
61-
* @return a new playlist instance, or <code>null</code> if the format has been recognized, but the playlist is malformed.
62-
* @throws NullPointerException if <code>in</code> is <code>null</code>.
63-
* @throws NullPointerException if <code>logger</code> is <code>null</code>.
64-
* @throws IOException if any error occurs during the unmarshalling process.
65-
* @see SpecificPlaylist#writeTo
66-
* @see SpecificPlaylistFactory#readFrom
67-
*/
68-
SpecificPlaylist readFrom(InputStream inputStream) throws IOException;
69-
7056
/**
7157
* Reads a playlist from the specified input stream.
7258
* When done, the stream remains open.
7359
*
7460
* @param inputStream an input stream. Shall not be <code>null</code>.
75-
* @param encoding the content encoding of the input resource, or <code>null</code> if not known.
7661
* @return a new playlist instance, or <code>null</code> if the format has been recognized, but the playlist is malformed.
7762
* @throws NullPointerException if <code>in</code> is <code>null</code>.
7863
* @throws NullPointerException if <code>logger</code> is <code>null</code>.
7964
* @throws IOException if any error occurs during the unmarshalling process.
80-
* @see #readFrom(InputStream, String)
8165
* @see SpecificPlaylistFactory#readFrom
8266
* @see SpecificPlaylist#writeTo
8367
*/
84-
SpecificPlaylist readFrom(InputStream inputStream, String encoding) throws IOException;
68+
SpecificPlaylist readFrom(InputStream inputStream) throws IOException;
8569

8670
/**
8771
* Builds a specific representation of the given generic playlist.

0 commit comments

Comments
 (0)