Hello, I think I may have found a regression in ArchiveFormatFactory.createArchiveInputStream. Please run the JUnit testcase at the end of this mail. It demonstrates the archive detection working with 1.10, but failing from 1.11 through 1.14 The file "COMPRESS-117.tar" is taken from commons-compress-1.9-src.zip. If it's not a bug, please let me know. Reading in COMPRESS-117 JIRA, I believe it fixed exactly this situation.
import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import org.apache.commons.compress.archivers.ArchiveException; import org.apache.commons.compress.archivers.ArchiveInputStream; import org.apache.commons.compress.archivers.ArchiveStreamFactory; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.junit.Assert; import org.junit.Test; public class TarDetectionRegressionTest { @Test public void check() throws IOException, ArchiveException { /* * we can read the archive normally */ try (InputStream in = open()) { try (TarArchiveInputStream tar = new TarArchiveInputStream(in)) { checkContents(tar); } } /* * but we cannot detect the stream signature with commons-compress version >= 1.11 * 1.10: works * 1.11: fail * 1.12: fail * 1.13: fail * 1.14: fail */ try (InputStream in = open()) { ArchiveInputStream s = new ArchiveStreamFactory().createArchiveInputStream(in); Assert.assertTrue(s instanceof TarArchiveInputStream); checkContents((TarArchiveInputStream) s); } } private void checkContents(TarArchiveInputStream tar) throws IOException { Assert.assertEquals("test1.xml", tar.getNextEntry().getName()); Assert.assertEquals("test2.xml", tar.getNextEntry().getName()); } private InputStream open() throws FileNotFoundException { return new BufferedInputStream( new FileInputStream("src/test/resources/COMPRESS-117.tar")); } }