@Test public void passGenerateOriginalItemsGZIP() { TransmissionPolicyManager tpm = new TransmissionPolicyManager(true); TransmissionDispatcher mockedDispatcher = Mockito.mock(TransmissionDispatcher.class); TransmissionHandlerArgs args = new TransmissionHandlerArgs(); args.setResponseCode(206); args.setTransmission(new Transmission(fourItems, "application/x-json-stream", "gzip")); args.setTransmissionDispatcher(mockedDispatcher); PartialSuccessHandler eh = new PartialSuccessHandler(tpm); List<String> originalItems = eh.generateOriginalItems(args); Assert.assertEquals(4, originalItems.size()); }
List<String> generateOriginalItems(TransmissionHandlerArgs args) { List<String> originalItems = new ArrayList<String>(); if ("gzip".equalsIgnoreCase(args.getTransmission().getWebContentEncodingType())) { GZIPInputStream gis = null; BufferedReader bufferedReader = null; try { gis = new GZIPInputStream( new ByteArrayInputStream(args.getTransmission().getContent())); bufferedReader = new BufferedReader(new InputStreamReader(gis)); String line; while ((line = bufferedReader.readLine()) != null) { originalItems.add(line); } } catch (IOException ex) { logger.error("IOException: Error while reading the GZIP stream", ex); } catch (Throwable t) { logger.error("Error while reading the GZIP stream", t); } finally { if (gis != null) { try { gis.close(); } catch (IOException ex){ logger.warn("Error while closing the GZIP stream", ex); } } if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException ex){ logger.warn("Error while closing the buffered reader", ex); } } } } else { for (String s : new String(args.getTransmission().getContent()).split("\r\n")) { originalItems.add(s); } } return originalItems; }
PartialSuccessHandler implements TransmissionHandler { List<String> generateOriginalItems(TransmissionHandlerArgs args) { List<String> originalItems = new ArrayList<String>(); if ("gzip".equalsIgnoreCase(args.getTransmission().getWebContentEncodingType())) { GZIPInputStream gis = null; BufferedReader bufferedReader = null; try { gis = new GZIPInputStream( new ByteArrayInputStream(args.getTransmission().getContent())); bufferedReader = new BufferedReader(new InputStreamReader(gis)); String line; while ((line = bufferedReader.readLine()) != null) { originalItems.add(line); } } catch (IOException ex) { logger.error("IOException: Error while reading the GZIP stream", ex); } catch (Throwable t) { logger.error("Error while reading the GZIP stream", t); } finally { if (gis != null) { try { gis.close(); } catch (IOException ex){ logger.warn("Error while closing the GZIP stream", ex); } } if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException ex){ logger.warn("Error while closing the buffered reader", ex); } } } } else { for (String s : new String(args.getTransmission().getContent()).split("\r\n")) { originalItems.add(s); } } return originalItems; } }
PartialSuccessHandler implements TransmissionHandler { List<String> generateOriginalItems(TransmissionHandlerArgs args) { List<String> originalItems = new ArrayList<String>(); if ("gzip".equalsIgnoreCase(args.getTransmission().getWebContentEncodingType())) { GZIPInputStream gis = null; BufferedReader bufferedReader = null; try { gis = new GZIPInputStream( new ByteArrayInputStream(args.getTransmission().getContent())); bufferedReader = new BufferedReader(new InputStreamReader(gis)); String line; while ((line = bufferedReader.readLine()) != null) { originalItems.add(line); } } catch (IOException ex) { logger.error("IOException: Error while reading the GZIP stream", ex); } catch (Throwable t) { logger.error("Error while reading the GZIP stream", t); } finally { if (gis != null) { try { gis.close(); } catch (IOException ex){ logger.warn("Error while closing the GZIP stream", ex); } } if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException ex){ logger.warn("Error while closing the buffered reader", ex); } } } } else { for (String s : new String(args.getTransmission().getContent()).split("\r\n")) { originalItems.add(s); } } return originalItems; } PartialSuccessHandler(TransmissionPolicyManager policy); }
PartialSuccessHandler implements TransmissionHandler { List<String> generateOriginalItems(TransmissionHandlerArgs args) { List<String> originalItems = new ArrayList<String>(); if ("gzip".equalsIgnoreCase(args.getTransmission().getWebContentEncodingType())) { GZIPInputStream gis = null; BufferedReader bufferedReader = null; try { gis = new GZIPInputStream( new ByteArrayInputStream(args.getTransmission().getContent())); bufferedReader = new BufferedReader(new InputStreamReader(gis)); String line; while ((line = bufferedReader.readLine()) != null) { originalItems.add(line); } } catch (IOException ex) { logger.error("IOException: Error while reading the GZIP stream", ex); } catch (Throwable t) { logger.error("Error while reading the GZIP stream", t); } finally { if (gis != null) { try { gis.close(); } catch (IOException ex){ logger.warn("Error while closing the GZIP stream", ex); } } if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException ex){ logger.warn("Error while closing the buffered reader", ex); } } } } else { for (String s : new String(args.getTransmission().getContent()).split("\r\n")) { originalItems.add(s); } } return originalItems; } PartialSuccessHandler(TransmissionPolicyManager policy); @Override void onTransmissionSent(TransmissionHandlerArgs args); }
PartialSuccessHandler implements TransmissionHandler { List<String> generateOriginalItems(TransmissionHandlerArgs args) { List<String> originalItems = new ArrayList<String>(); if ("gzip".equalsIgnoreCase(args.getTransmission().getWebContentEncodingType())) { GZIPInputStream gis = null; BufferedReader bufferedReader = null; try { gis = new GZIPInputStream( new ByteArrayInputStream(args.getTransmission().getContent())); bufferedReader = new BufferedReader(new InputStreamReader(gis)); String line; while ((line = bufferedReader.readLine()) != null) { originalItems.add(line); } } catch (IOException ex) { logger.error("IOException: Error while reading the GZIP stream", ex); } catch (Throwable t) { logger.error("Error while reading the GZIP stream", t); } finally { if (gis != null) { try { gis.close(); } catch (IOException ex){ logger.warn("Error while closing the GZIP stream", ex); } } if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException ex){ logger.warn("Error while closing the buffered reader", ex); } } } } else { for (String s : new String(args.getTransmission().getContent()).split("\r\n")) { originalItems.add(s); } } return originalItems; } PartialSuccessHandler(TransmissionPolicyManager policy); @Override void onTransmissionSent(TransmissionHandlerArgs args);  }