Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public List<SubscriptionItem> fromInputStream(@Nonnull final InputStream content
}

@Override
public List<SubscriptionItem> fromInputStream(@Nonnull final InputStream contentInputStream, String contentType)
public List<SubscriptionItem> fromInputStream(@Nonnull final InputStream contentInputStream,
@Nonnull final String contentType)
throws ExtractionException {
switch (contentType) {
case "json":
Expand Down Expand Up @@ -100,27 +101,24 @@ public List<SubscriptionItem> fromJsonInputStream(@Nonnull final InputStream con

public List<SubscriptionItem> 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<SubscriptionItem> 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);
}

Expand All @@ -146,7 +144,7 @@ public List<SubscriptionItem> fromCsvInputStream(@Nonnull final InputStream cont
try (BufferedReader br = new BufferedReader(new InputStreamReader(contentInputStream))) {
final List<SubscriptionItem> subscriptionItems = new ArrayList<>();

// Ignore header
// ignore header and skip first line
currentLine = 1;
line = br.readLine();

Expand All @@ -160,13 +158,13 @@ public List<SubscriptionItem> fromCsvInputStream(@Nonnull final InputStream cont
}

// 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;
}
Expand All @@ -188,18 +186,20 @@ public List<SubscriptionItem> fromCsvInputStream(@Nonnull final InputStream cont
// 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 = "<null>";
} 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public List<ContentSource> getSupportedSources() {
*
* @throws InvalidSourceException when the channelUrl doesn't exist or is invalid
*/
public List<SubscriptionItem> fromChannelUrl(String channelUrl) throws IOException, ExtractionException {
throw new UnsupportedOperationException("Service " + service.getServiceInfo().getName() + " doesn't support extracting from a channel url");
public List<SubscriptionItem> fromChannelUrl(final String channelUrl)
throws IOException, ExtractionException {
throw new UnsupportedOperationException("Service " + service.getServiceInfo().getName()
+ " doesn't support extracting from a channel url");
}

/**
Expand All @@ -83,7 +85,8 @@ public List<SubscriptionItem> fromInputStream(@Nonnull final InputStream content
*
* @throws InvalidSourceException when the content read from the InputStream is invalid and can not be parsed
*/
public List<SubscriptionItem> fromInputStream(@Nonnull final InputStream contentInputStream, String contentType)
public List<SubscriptionItem> 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");
Expand Down