TarArchiver implements FilesArchiver { @Override public <T> T appendBigFile(String path, FileAppender<T> appender) throws IOException { File tempFile = File.createTempFile("tarArchiver", ".tmp"); try { T result; try (FileOutputStream fos = new FileOutputStream(tempFile)) { result = appender.append(fos); } appendFile(path, tempFile); return result; } finally { tempFile.delete(); } } protected  TarArchiver(TarArchiveOutputStream tarOutput);  TarArchiver(File tarFile); @Override T appendFile(String path, FileAppender<T> appender); @Override T appendBigFile(String path, FileAppender<T> appender); @Override void appendFile(String path, File file); @Override synchronized void close();  }
@Test public void testAppendBigFile() throws Exception { String fileName = "hello"; final byte[] content = "Hello".getBytes(); File tempFile = File.createTempFile("tarArchiverTest", ".tar"); try { try (TarArchiver instance = new TarArchiver(tempFile)) { Boolean result = instance.appendBigFile(fileName, new FilesArchiver.FileAppender<Boolean>() { @Override public Boolean append(OutputStream outputStream) throws IOException { outputStream.write(content); return true; } }); assertTrue(result); } try (TarArchiveInputStream in = new TarArchiveInputStream( new FileInputStream(tempFile))) { ArchiveEntry nextEntry = in.getNextEntry(); String name = nextEntry.getName(); assertEquals(fileName, name); byte[] buff = new byte[content.length]; in.read(buff, 0, content.length); assertArrayEquals(content, buff); } } finally { tempFile.delete(); } }