FrameworkUploader implements Runnable { @VisibleForTesting void buildPackage() throws IOException, UploaderException, InterruptedException { beginUpload(); LOG.info("Compressing tarball"); try (TarArchiveOutputStream out = new TarArchiveOutputStream( targetStream)) { for (String fullPath : filteredInputFiles) { LOG.info("Adding " + fullPath); File file = new File(fullPath); try (FileInputStream inputStream = new FileInputStream(file)) { ArchiveEntry entry = out.createArchiveEntry(file, file.getName()); out.putArchiveEntry(entry); IOUtils.copyBytes(inputStream, out, 1024 * 1024); out.closeArchiveEntry(); } } fsDataStream.hflush(); endUpload(); } finally { if (targetStream != null) { targetStream.close(); } } }  void run(); static void main(String[] args);  }
@Test public void testUpload() throws IOException, UploaderException, InterruptedException { final String fileName = "/upload.tar.gz"; File parent = new File(testDir); try { parent.deleteOnExit(); FrameworkUploader uploader = prepareTree(parent); uploader.target = "file: uploader.buildPackage(); try (TarArchiveInputStream archiveInputStream = new TarArchiveInputStream( new GZIPInputStream( new FileInputStream( parent.getAbsolutePath() + fileName)))) { Set<String> fileNames = new HashSet<>(); Set<Long> sizes = new HashSet<>(); TarArchiveEntry entry1 = archiveInputStream.getNextTarEntry(); fileNames.add(entry1.getName()); sizes.add(entry1.getSize()); TarArchiveEntry entry2 = archiveInputStream.getNextTarEntry(); fileNames.add(entry2.getName()); sizes.add(entry2.getSize()); Assert.assertTrue( "File name error", fileNames.contains("a.jar")); Assert.assertTrue( "File size error", sizes.contains((long) 13)); Assert.assertTrue( "File name error", fileNames.contains("b.jar")); Assert.assertTrue( "File size error", sizes.contains((long) 14)); } } finally { FileUtils.deleteDirectory(parent); } }