@@ -46,7 +46,8 @@ public List<SubscriptionItem> fromInputStream(@Nonnull final InputStream content
4646 }
4747
4848 @ Override
49- public List <SubscriptionItem > fromInputStream (@ Nonnull final InputStream contentInputStream , String contentType )
49+ public List <SubscriptionItem > fromInputStream (@ Nonnull final InputStream contentInputStream ,
50+ @ Nonnull final String contentType )
5051 throws ExtractionException {
5152 switch (contentType ) {
5253 case "json" :
@@ -100,27 +101,24 @@ public List<SubscriptionItem> fromJsonInputStream(@Nonnull final InputStream con
100101
101102 public List <SubscriptionItem > fromZipInputStream (@ Nonnull final InputStream contentInputStream )
102103 throws ExtractionException {
103- final ZipInputStream zipInputStream = new ZipInputStream (contentInputStream );
104-
105- try {
104+ try (final ZipInputStream zipInputStream = new ZipInputStream (contentInputStream )) {
106105 ZipEntry zipEntry ;
107106 while ((zipEntry = zipInputStream .getNextEntry ()) != null ) {
108107 if (zipEntry .getName ().toLowerCase ().endsWith (".csv" )) {
109108 try {
110109 final List <SubscriptionItem > csvItems = fromCsvInputStream (zipInputStream );
111110
112- // Return it only if it has items (it exits early if it's the wrong file format)
113- // Otherwise try the next file
111+ // Return it only if it has items (it exits early if it's the wrong file
112+ // format), otherwise try the next file
114113 if (csvItems .size () > 0 ) {
115114 return csvItems ;
116115 }
117- } catch (ExtractionException e ) {
116+ } catch (final ExtractionException e ) {
118117 // Ignore error and go to next file
119- // (maybe log it?)
120118 }
121119 }
122120 }
123- } catch (IOException e ) {
121+ } catch (final IOException e ) {
124122 throw new InvalidSourceException ("Error reading contents of zip file" , e );
125123 }
126124
@@ -146,7 +144,7 @@ public List<SubscriptionItem> fromCsvInputStream(@Nonnull final InputStream cont
146144 try (BufferedReader br = new BufferedReader (new InputStreamReader (contentInputStream ))) {
147145 final List <SubscriptionItem > subscriptionItems = new ArrayList <>();
148146
149- // Ignore header
147+ // ignore header and skip first line
150148 currentLine = 1 ;
151149 line = br .readLine ();
152150
@@ -160,13 +158,13 @@ public List<SubscriptionItem> fromCsvInputStream(@Nonnull final InputStream cont
160158 }
161159
162160 // First comma
163- int i1 = line .indexOf ("," );
161+ final int i1 = line .indexOf ("," );
164162 if (i1 == -1 ) {
165163 continue ;
166164 }
167165
168166 // Second comma
169- int i2 = line .indexOf ("," , i1 + 1 );
167+ final int i2 = line .indexOf ("," , i1 + 1 );
170168 if (i2 == -1 ) {
171169 continue ;
172170 }
@@ -188,18 +186,20 @@ public List<SubscriptionItem> fromCsvInputStream(@Nonnull final InputStream cont
188186 // Channel title from third entry
189187 final String channelTitle = line .substring (i2 + 1 , i3 );
190188
191- final SubscriptionItem newItem = new SubscriptionItem (service .getServiceId (), channelUrl , channelTitle );
189+ final SubscriptionItem newItem
190+ = new SubscriptionItem (service .getServiceId (), channelUrl , channelTitle );
192191 subscriptionItems .add (newItem );
193192 }
194193
195194 return subscriptionItems ;
196- } catch (IOException e ) {
195+ } catch (final IOException e ) {
197196 if (line == null ) {
198197 line = "<null>" ;
199198 } else if (line .length () > 10 ) {
200199 line = line .substring (0 , 10 ) + "..." ;
201200 }
202- throw new InvalidSourceException ("Error reading CSV file, line = '" + line + "', line number = " + currentLine );
201+ throw new InvalidSourceException ("Error reading CSV file on line = \" " + line
202+ + "\" , line number = " + currentLine , e );
203203 }
204204 }
205205}
0 commit comments