@Test public void getYamlFromTgzTestCustomArchive() throws Exception { InputStream is = getClass().getResourceAsStream("mongodb-4.0.4.tgz"); InputStream chartFromInputStream = underTest.getChartFromInputStream(is); String fileContent = IOUtils.toString(new InputStreamReader(chartFromInputStream)); String expected = "appVersion: 3.6.6\n" + "description: NoSQL document-oriented database that stores JSON-like documents with\n" + " dynamic schemas, simplifying the integration of data in content-driven applications.\n" + "engine: gotpl\n" + "home: https: + "icon: https: + "keywords:\n" + "- mongodb\n" + "- database\n" + "- nosql\n" + "- cluster\n" + "- replicaset\n" + "- replication\n" + "maintainers:\n" + "- email: containers@bitnami.com\n" + " name: Bitnami\n" + "name: mongodb\n" + "sources:\n" + "- https: + "version: 4.0.4\n"; assertThat(fileContent, is(expected)); }
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);  }