diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSubscriptionExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSubscriptionExtractor.java index aafb1cd18..6bd553a85 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSubscriptionExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSubscriptionExtractor.java @@ -46,7 +46,8 @@ public class YoutubeSubscriptionExtractor extends SubscriptionExtractor { } @Override - public List fromInputStream(@Nonnull final InputStream contentInputStream, String contentType) + public List fromInputStream(@Nonnull final InputStream contentInputStream, + @Nonnull final String contentType) throws ExtractionException { switch (contentType) { case "json": @@ -100,27 +101,24 @@ public class YoutubeSubscriptionExtractor extends SubscriptionExtractor { public List fromZipInputStream(@Nonnull final InputStream contentInputStream) throws ExtractionException { - final ZipInputStream zipInputStream = new ZipInputStream(contentInputStream); - - try { + try (final ZipInputStream zipInputStream = new ZipInputStream(contentInputStream)) { ZipEntry zipEntry; while ((zipEntry = zipInputStream.getNextEntry()) != null) { if (zipEntry.getName().toLowerCase().endsWith(".csv")) { try { final List csvItems = fromCsvInputStream(zipInputStream); - // Return it only if it has items (it exits early if it's the wrong file format) - // Otherwise try the next file + // Return it only if it has items (it exits early if it's the wrong file + // format), otherwise try the next file if (csvItems.size() > 0) { return csvItems; } - } catch (ExtractionException e) { + } catch (final ExtractionException e) { // Ignore error and go to next file - // (maybe log it?) } } } - } catch (IOException e) { + } catch (final IOException e) { throw new InvalidSourceException("Error reading contents of zip file", e); } @@ -146,7 +144,7 @@ public class YoutubeSubscriptionExtractor extends SubscriptionExtractor { try (BufferedReader br = new BufferedReader(new InputStreamReader(contentInputStream))) { final List subscriptionItems = new ArrayList<>(); - // Ignore header + // ignore header and skip first line currentLine = 1; line = br.readLine(); @@ -160,13 +158,13 @@ public class YoutubeSubscriptionExtractor extends SubscriptionExtractor { } // First comma - int i1 = line.indexOf(","); + final int i1 = line.indexOf(","); if (i1 == -1) { continue; } // Second comma - int i2 = line.indexOf(",", i1 + 1); + final int i2 = line.indexOf(",", i1 + 1); if (i2 == -1) { continue; } @@ -188,18 +186,20 @@ public class YoutubeSubscriptionExtractor extends SubscriptionExtractor { // Channel title from third entry final String channelTitle = line.substring(i2 + 1, i3); - final SubscriptionItem newItem = new SubscriptionItem(service.getServiceId(), channelUrl, channelTitle); + final SubscriptionItem newItem + = new SubscriptionItem(service.getServiceId(), channelUrl, channelTitle); subscriptionItems.add(newItem); } return subscriptionItems; - } catch (IOException e) { + } catch (final IOException e) { if (line == null) { line = ""; } else if (line.length() > 10) { line = line.substring(0, 10) + "..."; } - throw new InvalidSourceException("Error reading CSV file, line = '" + line + "', line number = " + currentLine); + throw new InvalidSourceException("Error reading CSV file on line = \"" + line + + "\", line number = " + currentLine, e); } } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/subscription/SubscriptionExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/subscription/SubscriptionExtractor.java index b2a2d75ef..cc223630f 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/subscription/SubscriptionExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/subscription/SubscriptionExtractor.java @@ -63,8 +63,10 @@ public abstract class SubscriptionExtractor { * * @throws InvalidSourceException when the channelUrl doesn't exist or is invalid */ - public List fromChannelUrl(String channelUrl) throws IOException, ExtractionException { - throw new UnsupportedOperationException("Service " + service.getServiceInfo().getName() + " doesn't support extracting from a channel url"); + public List fromChannelUrl(final String channelUrl) + throws IOException, ExtractionException { + throw new UnsupportedOperationException("Service " + service.getServiceInfo().getName() + + " doesn't support extracting from a channel url"); } /** @@ -83,7 +85,8 @@ public abstract class SubscriptionExtractor { * * @throws InvalidSourceException when the content read from the InputStream is invalid and can not be parsed */ - public List fromInputStream(@Nonnull final InputStream contentInputStream, String contentType) + public List fromInputStream(@Nonnull final InputStream contentInputStream, + @Nonnull final String contentType) throws ExtractionException { throw new UnsupportedOperationException("Service " + service.getServiceInfo().getName() + " doesn't support extracting from an InputStream");