@Test(expected = IllegalArgumentException.class) public void chartNotFound() throws Exception { InputStream is = getClass().getResourceAsStream("mysql_negative-1.4.0.tgz"); underTest.getChartFromInputStream(is); }
public InputStream getChartFromInputStream(final InputStream is) throws IOException { try (GzipCompressorInputStream gzis = new GzipCompressorInputStream(is)) { try (TarArchiveInputStream tais = new TarArchiveInputStream(gzis)) { ArchiveEntry currentEntry; while ((currentEntry = tais.getNextEntry()) != null) { if (currentEntry.getName().endsWith(CHART_NAME)) { byte[] buf = new byte[(int) currentEntry.getSize()]; tais.read(buf, 0, buf.length); return new ByteArrayInputStream(buf); } } } } throw new IllegalArgumentException(String.format("%s not found", CHART_NAME)); }
TgzParser { public InputStream getChartFromInputStream(final InputStream is) throws IOException { try (GzipCompressorInputStream gzis = new GzipCompressorInputStream(is)) { try (TarArchiveInputStream tais = new TarArchiveInputStream(gzis)) { ArchiveEntry currentEntry; while ((currentEntry = tais.getNextEntry()) != null) { if (currentEntry.getName().endsWith(CHART_NAME)) { byte[] buf = new byte[(int) currentEntry.getSize()]; tais.read(buf, 0, buf.length); return new ByteArrayInputStream(buf); } } } } throw new IllegalArgumentException(String.format("%s not found", CHART_NAME)); } }
TgzParser { public InputStream getChartFromInputStream(final InputStream is) throws IOException { try (GzipCompressorInputStream gzis = new GzipCompressorInputStream(is)) { try (TarArchiveInputStream tais = new TarArchiveInputStream(gzis)) { ArchiveEntry currentEntry; while ((currentEntry = tais.getNextEntry()) != null) { if (currentEntry.getName().endsWith(CHART_NAME)) { byte[] buf = new byte[(int) currentEntry.getSize()]; tais.read(buf, 0, buf.length); return new ByteArrayInputStream(buf); } } } } throw new IllegalArgumentException(String.format("%s not found", CHART_NAME)); }  }
TgzParser { public InputStream getChartFromInputStream(final InputStream is) throws IOException { try (GzipCompressorInputStream gzis = new GzipCompressorInputStream(is)) { try (TarArchiveInputStream tais = new TarArchiveInputStream(gzis)) { ArchiveEntry currentEntry; while ((currentEntry = tais.getNextEntry()) != null) { if (currentEntry.getName().endsWith(CHART_NAME)) { byte[] buf = new byte[(int) currentEntry.getSize()]; tais.read(buf, 0, buf.length); return new ByteArrayInputStream(buf); } } } } throw new IllegalArgumentException(String.format("%s not found", CHART_NAME)); }  InputStream getChartFromInputStream(final InputStream is); }
TgzParser { public InputStream getChartFromInputStream(final InputStream is) throws IOException { try (GzipCompressorInputStream gzis = new GzipCompressorInputStream(is)) { try (TarArchiveInputStream tais = new TarArchiveInputStream(gzis)) { ArchiveEntry currentEntry; while ((currentEntry = tais.getNextEntry()) != null) { if (currentEntry.getName().endsWith(CHART_NAME)) { byte[] buf = new byte[(int) currentEntry.getSize()]; tais.read(buf, 0, buf.length); return new ByteArrayInputStream(buf); } } } } throw new IllegalArgumentException(String.format("%s not found", CHART_NAME)); }  InputStream getChartFromInputStream(final InputStream is);  }