├── .gitignore ├── src ├── test │ ├── resources │ │ ├── bla.dump │ │ ├── bla.jar │ │ ├── bla.pack │ │ ├── bla.tgz │ │ ├── bla.zip │ │ ├── moby.zip │ │ ├── bla.tar.xz │ │ ├── bla.z.dump │ │ ├── test1.xml │ │ ├── 8.star.tar.gz │ │ ├── bla.tar.bz2 │ │ ├── bla.txt.bz2 │ │ ├── bla.xml.bz2 │ │ ├── multiple.bz2 │ │ ├── multiple.gz │ │ ├── multiple.xz │ │ ├── ordertest.zip │ │ ├── testAIFF.aif │ │ ├── 8.posix.tar.gz │ │ ├── test-winzip.zip │ │ ├── test2.xml │ │ ├── COMPRESS-114.tar │ │ ├── COMPRESS-131.bz2 │ │ ├── COMPRESS-208.zip │ │ ├── archives │ │ │ ├── SunOS.zip │ │ │ ├── FreeBSD.zip │ │ │ ├── SunOS_.cpio │ │ │ ├── FreeBSD_bin.cpio │ │ │ ├── FreeBSD_hpbin.cpio │ │ │ ├── files.txt │ │ │ ├── SunOS.ar │ │ │ ├── FreeBSD.ar │ │ │ ├── SunOS_odc.cpio │ │ │ ├── FreeBSD_crc.cpio │ │ │ ├── SunOS_-c.cpio │ │ │ ├── SunOS_crc.cpio │ │ │ └── FreeBSD_newc.cpio │ │ ├── preepoch-star.tar │ │ ├── utf8-7zip-test.zip │ │ ├── testCompress209.doc │ │ ├── utf8-winzip-test.zip │ │ ├── zip64support.tar.bz2 │ │ ├── longpath │ │ │ ├── minotaur-0.jar │ │ │ ├── minotaur-M.jar │ │ │ ├── minotaur-c.zip │ │ │ ├── minotaur-z.zip │ │ │ ├── minotaur.jar │ │ │ ├── minotaur.zip │ │ │ ├── minotaur.ar │ │ │ ├── files.txt │ │ │ └── minotaur.cpio │ │ ├── password-encrypted.zip │ │ ├── simple-aix-native-tar.tar │ │ ├── apache-maven-2.2.1.zip.001 │ │ ├── longfile_bsd.ar │ │ ├── OSX_ArchiveWithNestedArchive.zip │ │ ├── test4.xml │ │ ├── longfile_gnu.ar │ │ ├── test.txt │ │ ├── test3.xml │ │ ├── test with spaces.txt │ │ └── bla.ar │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── compress │ │ ├── archivers │ │ ├── memory │ │ │ ├── MemoryArchiveEntry.java │ │ │ ├── MemoryArchiveTestCase.java │ │ │ └── MemoryArchiveInputStream.java │ │ ├── tar │ │ │ ├── SparseFilesTest.java │ │ │ └── BigFilesIT.java │ │ ├── dump │ │ │ ├── DumpArchiveEntryTest.java │ │ │ ├── DumpArchiveUtilTest.java │ │ │ └── DumpArchiveInputStreamTest.java │ │ ├── cpio │ │ │ ├── CpioArchiveInputStreamTest.java │ │ │ ├── CpioUtilTest.java │ │ │ └── CpioArchiveOutputStreamTest.java │ │ ├── ar │ │ │ ├── ArArchiveInputStreamTest.java │ │ │ └── ArArchiveOutputStreamTest.java │ │ ├── jar │ │ │ └── JarArchiveOutputStreamTest.java │ │ ├── zip │ │ │ ├── ZipShortTest.java │ │ │ ├── ZipArchiveInputStreamTest.java │ │ │ ├── ZipLongTest.java │ │ │ ├── ZipUtilTest.java │ │ │ └── EncryptedArchiveTest.java │ │ └── ExceptionMessageTest.java │ │ ├── ChainingTestCase.java │ │ ├── utils │ │ ├── CharsetsTest.java │ │ └── CountingStreamTest.java │ │ ├── DetectCompressorTestCase.java │ │ ├── ArchiveUtilsTest.java │ │ └── compressors │ │ └── XZUtilsTestCase.java ├── site │ ├── resources │ │ └── images │ │ │ ├── compress-logo-white.png │ │ │ └── compress-logo-white.xcf │ ├── site.xml │ └── xdoc │ │ └── conventions.xml └── main │ ├── java │ └── org │ │ └── apache │ │ └── commons │ │ └── compress │ │ ├── utils │ │ ├── package.html │ │ ├── CountingOutputStream.java │ │ ├── CountingInputStream.java │ │ └── IOUtils.java │ │ ├── compressors │ │ ├── package.html │ │ ├── bzip2 │ │ │ ├── package.html │ │ │ └── BZip2Constants.java │ │ ├── CompressorOutputStream.java │ │ ├── gzip │ │ │ ├── package.html │ │ │ └── GzipCompressorOutputStream.java │ │ ├── pack200 │ │ │ ├── Pack200Strategy.java │ │ │ ├── InMemoryCachingStreamBridge.java │ │ │ ├── TempFileCachingStreamBridge.java │ │ │ └── StreamBridge.java │ │ ├── CompressorException.java │ │ └── CompressorInputStream.java │ │ ├── archivers │ │ ├── ar │ │ │ └── package.html │ │ ├── cpio │ │ │ └── package.html │ │ ├── package.html │ │ ├── zip │ │ │ ├── package.html │ │ │ ├── Zip64Mode.java │ │ │ ├── Zip64RequiredException.java │ │ │ ├── UnixStat.java │ │ │ ├── ZipConstants.java │ │ │ ├── UnicodePathExtraField.java │ │ │ ├── UnicodeCommentExtraField.java │ │ │ ├── ZipExtraField.java │ │ │ └── FallbackZipEncoding.java │ │ ├── jar │ │ │ ├── package.html │ │ │ ├── JarArchiveOutputStream.java │ │ │ ├── JarArchiveInputStream.java │ │ │ └── JarArchiveEntry.java │ │ ├── dump │ │ │ ├── ShortFileException.java │ │ │ ├── UnrecognizedFormatException.java │ │ │ ├── DumpArchiveException.java │ │ │ ├── UnsupportedCompressionAlgorithmException.java │ │ │ ├── InvalidFormatException.java │ │ │ ├── Dirent.java │ │ │ ├── package.html │ │ │ └── DumpArchiveConstants.java │ │ ├── tar │ │ │ ├── package.html │ │ │ └── TarArchiveSparseEntry.java │ │ ├── ArchiveEntry.java │ │ ├── ArchiveException.java │ │ └── Lister.java │ │ └── changes │ │ ├── package.html │ │ ├── Change.java │ │ └── ChangeSetResults.java │ └── assembly │ ├── src.xml │ └── bin.xml ├── .gitattributes ├── NOTICE.txt ├── .classpath ├── README.txt ├── .project ├── RELEASE-NOTES.txt ├── PROPOSAL.txt ├── pmd-ruleset.xml ├── META-INF └── MANIFEST.MF └── doap_compress.rdf /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .project 3 | .classpath 4 | .settings 5 | *~ 6 | /bin 7 | -------------------------------------------------------------------------------- /src/test/resources/bla.dump: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/bla.dump -------------------------------------------------------------------------------- /src/test/resources/bla.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/bla.jar -------------------------------------------------------------------------------- /src/test/resources/bla.pack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/bla.pack -------------------------------------------------------------------------------- /src/test/resources/bla.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/bla.tgz -------------------------------------------------------------------------------- /src/test/resources/bla.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/bla.zip -------------------------------------------------------------------------------- /src/test/resources/moby.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/moby.zip -------------------------------------------------------------------------------- /src/test/resources/bla.tar.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/bla.tar.xz -------------------------------------------------------------------------------- /src/test/resources/bla.z.dump: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/bla.z.dump -------------------------------------------------------------------------------- /src/test/resources/test1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/test/resources/8.star.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/8.star.tar.gz -------------------------------------------------------------------------------- /src/test/resources/bla.tar.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/bla.tar.bz2 -------------------------------------------------------------------------------- /src/test/resources/bla.txt.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/bla.txt.bz2 -------------------------------------------------------------------------------- /src/test/resources/bla.xml.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/bla.xml.bz2 -------------------------------------------------------------------------------- /src/test/resources/multiple.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/multiple.bz2 -------------------------------------------------------------------------------- /src/test/resources/multiple.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/multiple.gz -------------------------------------------------------------------------------- /src/test/resources/multiple.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/multiple.xz -------------------------------------------------------------------------------- /src/test/resources/ordertest.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/ordertest.zip -------------------------------------------------------------------------------- /src/test/resources/testAIFF.aif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/testAIFF.aif -------------------------------------------------------------------------------- /src/test/resources/8.posix.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/8.posix.tar.gz -------------------------------------------------------------------------------- /src/test/resources/test-winzip.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/test-winzip.zip -------------------------------------------------------------------------------- /src/test/resources/test2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/test/resources/COMPRESS-114.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/COMPRESS-114.tar -------------------------------------------------------------------------------- /src/test/resources/COMPRESS-131.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/COMPRESS-131.bz2 -------------------------------------------------------------------------------- /src/test/resources/COMPRESS-208.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/COMPRESS-208.zip -------------------------------------------------------------------------------- /src/test/resources/archives/SunOS.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/archives/SunOS.zip -------------------------------------------------------------------------------- /src/test/resources/preepoch-star.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/preepoch-star.tar -------------------------------------------------------------------------------- /src/test/resources/utf8-7zip-test.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/utf8-7zip-test.zip -------------------------------------------------------------------------------- /src/test/resources/archives/FreeBSD.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/archives/FreeBSD.zip -------------------------------------------------------------------------------- /src/test/resources/archives/SunOS_.cpio: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/archives/SunOS_.cpio -------------------------------------------------------------------------------- /src/test/resources/testCompress209.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/testCompress209.doc -------------------------------------------------------------------------------- /src/test/resources/utf8-winzip-test.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/utf8-winzip-test.zip -------------------------------------------------------------------------------- /src/test/resources/zip64support.tar.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/zip64support.tar.bz2 -------------------------------------------------------------------------------- /src/test/resources/longpath/minotaur-0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/longpath/minotaur-0.jar -------------------------------------------------------------------------------- /src/test/resources/longpath/minotaur-M.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/longpath/minotaur-M.jar -------------------------------------------------------------------------------- /src/test/resources/longpath/minotaur-c.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/longpath/minotaur-c.zip -------------------------------------------------------------------------------- /src/test/resources/longpath/minotaur-z.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/longpath/minotaur-z.zip -------------------------------------------------------------------------------- /src/test/resources/longpath/minotaur.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/longpath/minotaur.jar -------------------------------------------------------------------------------- /src/test/resources/longpath/minotaur.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/longpath/minotaur.zip -------------------------------------------------------------------------------- /src/test/resources/password-encrypted.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/password-encrypted.zip -------------------------------------------------------------------------------- /src/test/resources/archives/FreeBSD_bin.cpio: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/archives/FreeBSD_bin.cpio -------------------------------------------------------------------------------- /src/test/resources/simple-aix-native-tar.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/simple-aix-native-tar.tar -------------------------------------------------------------------------------- /src/test/resources/apache-maven-2.2.1.zip.001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/apache-maven-2.2.1.zip.001 -------------------------------------------------------------------------------- /src/test/resources/archives/FreeBSD_hpbin.cpio: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/archives/FreeBSD_hpbin.cpio -------------------------------------------------------------------------------- /src/test/resources/longfile_bsd.ar: -------------------------------------------------------------------------------- 1 | ! 2 | #1/28 1311256511 1000 1000 100644 42 ` 3 | this_is_a_long_file_name.txtHello, world! 4 | -------------------------------------------------------------------------------- /src/site/resources/images/compress-logo-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/site/resources/images/compress-logo-white.png -------------------------------------------------------------------------------- /src/site/resources/images/compress-logo-white.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/site/resources/images/compress-logo-white.xcf -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | src/test/resources/longfile_gnu.ar eol=lf 2 | src/test/resources/longfile_bsd.ar eol=lf 3 | src/test/resources/longpath/minotaur.ar eol=lf 4 | -------------------------------------------------------------------------------- /src/test/resources/OSX_ArchiveWithNestedArchive.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/commons-compress/trunk/src/test/resources/OSX_ArchiveWithNestedArchive.zip -------------------------------------------------------------------------------- /src/test/resources/test4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | German Umlauts: ÜÄÖß 5 | Stored as UTF-8 (Mac OSX 10.4.x) 6 | 7 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache Commons Compress 2 | Copyright 2002-2012 The Apache Software Foundation 3 | 4 | This product includes software developed by 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /src/test/resources/archives/files.txt: -------------------------------------------------------------------------------- 1 | # Sizes and filenames in the archives 2 | 27 1 3 | 27 12 4 | 27 123 5 | 27 1234 6 | 27 12345 7 | 27 123450 8 | 26 123456 9 | 25 123457 10 | 24 123458 11 | 23 123459 12 | -------------------------------------------------------------------------------- /src/test/resources/longfile_gnu.ar: -------------------------------------------------------------------------------- 1 | ! 2 | // 30 ` 3 | this_is_a_long_file_name.txt/ 4 | /0 1311256511 1000 1000 100644 14 ` 5 | Hello, world! 6 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/test/resources/test.txt: -------------------------------------------------------------------------------- 1 | 111111111111111111111111111000101011 2 | 111111111111111111111111111000101011 3 | 111111111111111111111111111000101011 4 | 111111111111111111111111111000101011 5 | 111111111111111111111111111000101011 6 | 111111111111111111111111111000101011 7 | 111111111111111111111111111000101011 8 | 111111111111111111111111111000101011 9 | 111111111111111111111111111000101011 10 | 111111111111111111111111111000101011 -------------------------------------------------------------------------------- /src/test/resources/test3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Lorem ipsum dolor sit amet, consetetur sadipscing elitr, 5 | sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, 6 | sed diam voluptua. 7 | At vero eos et accusam et justo duo dolores et ea rebum. 8 | Stet clita kasd gubergren, no sea takimata sanctus est 9 | Lorem ipsum dolor sit amet. 10 | 11 | -------------------------------------------------------------------------------- /src/test/resources/test with spaces.txt: -------------------------------------------------------------------------------- 1 | TEST WITH SPACES IN FILENAME 2 | 111111111111111111111111111000101011 3 | 111111111111111111111111111000101011 4 | 111111111111111111111111111000101011 5 | 111111111111111111111111111000101011 6 | 111111111111111111111111111000101011 7 | 111111111111111111111111111000101011 8 | 111111111111111111111111111000101011 9 | 111111111111111111111111111000101011 10 | 111111111111111111111111111000101011 11 | 111111111111111111111111111000101011 -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Apache Commons Compress was derived from various sources, including: 2 | 3 | Original BZip2 classes contributed by Keiron Liddle 4 | , Aftex Software to the Apache Ant project 5 | They are based on a port of Julian Seward's libbzip2. 6 | 7 | Original Tar classes from contributors of the Apache Ant project 8 | 9 | Original Zip classes from contributors of the Apache Ant project 10 | 11 | Original CPIO classes contributed by Markus Kuss and the jRPM project 12 | (jrpm.sourceforge.net) 13 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.apache.commons.compress 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.jdt.core.javanature 26 | org.eclipse.pde.PluginNature 27 | 28 | 29 | -------------------------------------------------------------------------------- /RELEASE-NOTES.txt: -------------------------------------------------------------------------------- 1 | Apache Commons Compress 1.4.1 RELEASE NOTES 2 | 3 | Apache Commons Compress software defines an API for working with compression and archive formats. 4 | These include: bzip2, gzip, pack200 and ar, cpio, jar, tar, zip, dump. 5 | 6 | Release 1.4.1 7 | 8 | Changes in this version include: 9 | 10 | Fixed Bugs: 11 | 12 | o Ported libbzip2's fallback sort algorithm to 13 | BZip2CompressorOutputStream to speed up compression in certain edge 14 | cases. 15 | 16 | Using specially crafted inputs this can be used as a denial of 17 | service attack. See 18 | http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-2098 19 | 20 | 21 | For complete information on Commons Compress, including instructions on how to submit bug reports, 22 | patches, or suggestions for improvement, see the Apache Commons Compress website: 23 | 24 | http://commons.apache.org/compress/ 25 | -------------------------------------------------------------------------------- /src/test/resources/bla.ar: -------------------------------------------------------------------------------- 1 | ! 2 | test1.xml 1201445869 501 501 100644 610 ` 3 | 4 | 5 | 6 | <<<<<<< HEAD:testdata/test.xml 7 | ======= 8 | as 9 | >>>>>>> 75cb63ff7005344589b57d17338b64783f8f430c:testdata/test.xml 10 | 11 | 1521 12 | 10.248.40.111 13 | JDBC 14 | false 15 | appsrv 16 | Dev-DB 17 | O10gIN1 18 | oracle.jdbc.driver.OracleDriver 19 | thin 20 | 21 | 22 | test2.xml 1201445869 501 501 100644 82 ` 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/test/resources/longpath/minotaur.ar: -------------------------------------------------------------------------------- 1 | ! 2 | // 350 ` 3 | file12345678901234567890.txt/ 4 | file1234567890123456789012345678901234567890123456789012345678901234567890.txt/ 5 | file123456789012345678901234567890123456789012345678901234567890.txt/ 6 | file123456789012345678901234567890.txt/ 7 | file1234567890.txt/ 8 | file1234567890123456789012345678901234567890.txt/ 9 | file12345678901234567890123456789012345678901234567890.txt/ 10 | /0 1273319811 1721 1721 100664 0 ` 11 | /30 1273319842 1721 1721 100664 0 ` 12 | /110 1273319835 1721 1721 100664 0 ` 13 | file.txt/ 1273319777 1721 1721 100664 0 ` 14 | /180 1273319817 1721 1721 100664 0 ` 15 | /220 1273319794 1721 1721 100664 0 ` 16 | /240 1273319823 1721 1721 100664 0 ` 17 | /290 1273319828 1721 1721 100664 0 ` 18 | -------------------------------------------------------------------------------- /src/test/resources/archives/SunOS.ar: -------------------------------------------------------------------------------- 1 | ! 2 | 1/ 1238264462 2606 1 100644 27 ` 3 | abcdefghijklmnopqrstuvwxyz 4 | 5 | 12/ 1238277260 2606 1 100644 27 ` 6 | abcdefghijklmnopqrstuvwxyz 7 | 8 | 123/ 1238277265 2606 1 100644 27 ` 9 | abcdefghijklmnopqrstuvwxyz 10 | 11 | 1234/ 1238277275 2606 1 100644 27 ` 12 | abcdefghijklmnopqrstuvwxyz 13 | 14 | 12345/ 1238277277 2606 1 100644 27 ` 15 | abcdefghijklmnopqrstuvwxyz 16 | 17 | 123450/ 1238277385 2606 1 100644 27 ` 18 | abcdefghijklmnopqrstuvwxyz 19 | 20 | 123456/ 1238277620 2606 1 100644 26 ` 21 | bcdefghijklmnopqrstuvwxyz 22 | 123457/ 1238277660 2606 1 100644 25 ` 23 | cdefghijklmnopqrstuvwxyz 24 | 25 | 123458/ 1238277670 2606 1 100644 24 ` 26 | defghijklmnopqrstuvwxyz 27 | 123459/ 1238277679 2606 1 100644 23 ` 28 | efghijklmnopqrstuvwxyz 29 | 30 | -------------------------------------------------------------------------------- /src/test/resources/archives/FreeBSD.ar: -------------------------------------------------------------------------------- 1 | ! 2 | 1/ 1238278221 1721 1721 100664 27 ` 3 | abcdefghijklmnopqrstuvwxyz 4 | 5 | 12/ 1238278221 1721 1721 100664 27 ` 6 | abcdefghijklmnopqrstuvwxyz 7 | 8 | 123/ 1238278221 1721 1721 100664 27 ` 9 | abcdefghijklmnopqrstuvwxyz 10 | 11 | 1234/ 1238278222 1721 1721 100664 27 ` 12 | abcdefghijklmnopqrstuvwxyz 13 | 14 | 12345/ 1238278222 1721 1721 100664 27 ` 15 | abcdefghijklmnopqrstuvwxyz 16 | 17 | 123450/ 1238278222 1721 1721 100644 27 ` 18 | abcdefghijklmnopqrstuvwxyz 19 | 20 | 123456/ 1238278222 1721 1721 100664 26 ` 21 | bcdefghijklmnopqrstuvwxyz 22 | 123457/ 1238278222 1721 1721 100644 25 ` 23 | cdefghijklmnopqrstuvwxyz 24 | 25 | 123458/ 1238278222 1721 1721 100644 24 ` 26 | defghijklmnopqrstuvwxyz 27 | 123459/ 1238278222 1721 1721 100644 23 ` 28 | efghijklmnopqrstuvwxyz 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/utils/package.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |

Contains utilities used internally by the compress library.

22 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/compressors/package.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |

Provides a unified API and factories for dealing with 22 | compressed streams.

23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/ar/package.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |

Provides stream classes for reading and writing archives using 22 | the AR format.

23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/cpio/package.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |

Provides stream classes for reading and writing archives using 22 | the CPIO format.

23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/package.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |

Provides a unified API and factories for dealing with archives 22 | in different formats.

23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/zip/package.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |

Provides stream classes for reading and writing archives using 22 | the ZIP format.

23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/compressors/bzip2/package.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |

Provides stream classes for compressing and decompressing 22 | streams using the BZip2 algorithm.

23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/compressors/CompressorOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.compressors; 20 | 21 | import java.io.OutputStream; 22 | 23 | public abstract class CompressorOutputStream extends OutputStream { 24 | // TODO 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/jar/package.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |

Provides stream classes for reading and writing archives using 22 | the ZIP format with some extensions for the special case of JAR 23 | archives.

24 | 25 | 26 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/changes/package.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |

EXPERIMENTAL support for changesets that are applied to 22 | archives.

23 | 24 |

This API is considered unstable and may be modified or even 25 | removed in future releases.

26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/compressors/gzip/package.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |

Provides stream classes for compressing and decompressing 22 | streams using the GZip algorithm.

23 | 24 |

The classes in this package are wrappers around {@link 25 | java.util.zip.GZIPInputStream java.util.zip.GZIPInputStream} and 26 | {@link java.util.zip.GZIPOutputStream 27 | java.util.zip.GZIPOutputStream}.

28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/dump/ShortFileException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.dump; 20 | 21 | 22 | /** 23 | * Short File Exception. There was an unexpected EOF when reading 24 | * the input stream. 25 | */ 26 | public class ShortFileException extends DumpArchiveException { 27 | private static final long serialVersionUID = 1L; 28 | 29 | public ShortFileException() { 30 | super("unexpected EOF"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/dump/UnrecognizedFormatException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.dump; 20 | 21 | 22 | /** 23 | * Unrecognized Format Exception. This is either not a recognized dump archive or there's 24 | * a bad tape segment header. 25 | */ 26 | public class UnrecognizedFormatException extends DumpArchiveException { 27 | private static final long serialVersionUID = 1L; 28 | 29 | public UnrecognizedFormatException() { 30 | super("this is not a recognized format."); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/tar/package.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |

Provides stream classes for reading and writing archives using 22 | the TAR format.

23 | 24 |

There are many different format dialects that call themselves 25 | TAR. The classes of this package can read and write archives in 26 | the traditional pre-POSIX ustar format and support GNU 27 | specific extensions for long filenames that GNU tar itself by 28 | now refers to as oldgnu.

29 | 30 | 31 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.compress.compressors.bzip2; 21 | 22 | /** 23 | * Constants for both the compress and decompress BZip2 classes. 24 | */ 25 | interface BZip2Constants { 26 | 27 | int BASEBLOCKSIZE = 100000; 28 | int MAX_ALPHA_SIZE = 258; 29 | int MAX_CODE_LEN = 23; 30 | int RUNA = 0; 31 | int RUNB = 1; 32 | int N_GROUPS = 6; 33 | int G_SIZE = 50; 34 | int N_ITERS = 4; 35 | int MAX_SELECTORS = (2 + (900000 / G_SIZE)); 36 | int NUM_OVERSHOOT_BYTES = 20; 37 | 38 | } -------------------------------------------------------------------------------- /PROPOSAL.txt: -------------------------------------------------------------------------------- 1 | Proposal for Compress Package 2 | 3 | (0) rationale 4 | 5 | Ant contains packages to deal with tar, bzip2 and zip archives that 6 | have been reused in various projects in- and outside of Apache. 7 | 8 | Compress provides a focused home for these packages together with 9 | new external contributions for the ar and cpio formats with a focus on 10 | being a reusable library - unlike the code in Ant. 11 | 12 | (1) scope of the package 13 | 14 | The package provides a unified API for different archiving and 15 | compression formats together with implementations for these 16 | algorithms. 17 | 18 | (1.5) interaction with other packages 19 | 20 | No interactions planned ATM. 21 | 22 | (2) identify the initial source for the package 23 | 24 | Compress' code is already part of the sandbox. 25 | 26 | (2.1) identify the base name for the package 27 | 28 | org.apache.commons.compress 29 | 30 | (2.2) identify the coding conventions for this package 31 | 32 | The code uses the conventions from the Jakarta Turbine package. 33 | 34 | (3) identify any Commons resources to be created 35 | 36 | (3.1) mailing list 37 | 38 | No changes. 39 | 40 | (3.2) SVN repositories 41 | 42 | The package will need to move from the sandbox. 43 | 44 | (3.3) JIRA 45 | 46 | A new Commons Compress JIRA project shall be created and the issues of 47 | the Compress Component of the Commons Sandbox project migrated to the 48 | new project. 49 | 50 | (4) identify the initial set of committers to be listed in the Status File. 51 | 52 | Henri Yandell 53 | Stefan Bodewig 54 | Torsten Curdt 55 | -------------------------------------------------------------------------------- /src/test/resources/archives/SunOS_odc.cpio: -------------------------------------------------------------------------------- 1 | 07070700000000000110064400505600000100000117777711163465216000002000000000331abcdefghijklmnopqrstuvwxyz 2 | 070707000000000002100644005056000001000001177777111635162140000030000000003312abcdefghijklmnopqrstuvwxyz 3 | 0707070000000000031006440050560000010000011777771116351622100000400000000033123abcdefghijklmnopqrstuvwxyz 4 | 07070700000000000410064400505600000100000117777711163516233000005000000000331234abcdefghijklmnopqrstuvwxyz 5 | 070707000000000005100644005056000001000001177777111635162350000060000000003312345abcdefghijklmnopqrstuvwxyz 6 | 0707070000000000061006440050560000010000011777771116351641100000700000000033123450abcdefghijklmnopqrstuvwxyz 7 | 0707070000000000071006440050560000010000011777771116351676400000700000000032123456bcdefghijklmnopqrstuvwxyz 8 | 0707070000000000101006440050560000010000011777771116351703400000700000000031123457cdefghijklmnopqrstuvwxyz 9 | 0707070000000000111006440050560000010000011777771116351704600000700000000030123458defghijklmnopqrstuvwxyz 10 | 0707070000000000121006440050560000010000011777771116351705700000700000000027123459efghijklmnopqrstuvwxyz 11 | 0707070000000000000000000000000000000000010000000000000000000001300000000000TRAILER!!! -------------------------------------------------------------------------------- /pmd-ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 25 | Standard Ruleset but excluding the "no octal 26 | constants" rule 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.dump; 20 | 21 | import java.io.IOException; 22 | 23 | 24 | /** 25 | * Dump Archive Exception 26 | */ 27 | public class DumpArchiveException extends IOException { 28 | private static final long serialVersionUID = 1L; 29 | 30 | public DumpArchiveException() { 31 | } 32 | 33 | public DumpArchiveException(String msg) { 34 | super(msg); 35 | } 36 | 37 | public DumpArchiveException(Throwable cause) { 38 | super(); 39 | initCause(cause); 40 | } 41 | 42 | public DumpArchiveException(String msg, Throwable cause) { 43 | super(msg); 44 | initCause(cause); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/dump/UnsupportedCompressionAlgorithmException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.dump; 20 | 21 | 22 | /** 23 | * Unsupported compression algorithm. The dump archive uses an unsupported 24 | * compression algorithm (BZLIB2 or LZO). 25 | */ 26 | public class UnsupportedCompressionAlgorithmException 27 | extends DumpArchiveException { 28 | private static final long serialVersionUID = 1L; 29 | 30 | public UnsupportedCompressionAlgorithmException() { 31 | super("this file uses an unsupported compression algorithm."); 32 | } 33 | 34 | public UnsupportedCompressionAlgorithmException(String alg) { 35 | super("this file uses an unsupported compression algorithm: " + alg + 36 | "."); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | Commons Compress 24 | /images/compress-logo-white.png 25 | /index.html 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/dump/InvalidFormatException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.dump; 20 | 21 | 22 | /** 23 | * Invalid Format Exception. There was an error decoding a 24 | * tape segment header. 25 | */ 26 | public class InvalidFormatException extends DumpArchiveException { 27 | private static final long serialVersionUID = 1L; 28 | protected long offset; 29 | 30 | public InvalidFormatException() { 31 | super("there was an error decoding a tape segment"); 32 | } 33 | 34 | public InvalidFormatException(long offset) { 35 | super("there was an error decoding a tape segment header at offset " + 36 | offset + "."); 37 | this.offset = offset; 38 | } 39 | 40 | public long getOffset() { 41 | return offset; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/compressors/pack200/Pack200Strategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.compress.compressors.pack200; 21 | 22 | import java.io.IOException; 23 | 24 | /** 25 | * The different modes the Pack200 streams can use to wrap input and 26 | * output. 27 | * @since 1.3 28 | */ 29 | public enum Pack200Strategy { 30 | /** Cache output in memory */ 31 | IN_MEMORY() { 32 | @Override 33 | StreamBridge newStreamBridge() { 34 | return new InMemoryCachingStreamBridge(); 35 | } 36 | }, 37 | /** Cache output in a temporary file */ 38 | TEMP_FILE() { 39 | @Override 40 | StreamBridge newStreamBridge() throws IOException { 41 | return new TempFileCachingStreamBridge(); 42 | } 43 | }; 44 | 45 | abstract StreamBridge newStreamBridge() throws IOException; 46 | } -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/compressors/pack200/InMemoryCachingStreamBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.compress.compressors.pack200; 21 | 22 | import java.io.ByteArrayInputStream; 23 | import java.io.ByteArrayOutputStream; 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * StreamSwitcher that caches all data written to the output side in 29 | * memory. 30 | * @since 1.3 31 | */ 32 | class InMemoryCachingStreamBridge extends StreamBridge { 33 | InMemoryCachingStreamBridge() { 34 | super(new ByteArrayOutputStream()); 35 | } 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | @Override 41 | InputStream getInputView() throws IOException { 42 | return new ByteArrayInputStream(((ByteArrayOutputStream) out) 43 | .toByteArray()); 44 | } 45 | } -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.memory; 20 | 21 | import java.util.Date; 22 | 23 | import org.apache.commons.compress.archivers.ArchiveEntry; 24 | 25 | public final class MemoryArchiveEntry implements ArchiveEntry { 26 | 27 | private final String name; 28 | 29 | public MemoryArchiveEntry(final String pName) { 30 | name = pName; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public long getSize() { 38 | // TODO Auto-generated method stub 39 | return 0; 40 | } 41 | 42 | public boolean isDirectory() { 43 | // TODO Auto-generated method stub 44 | return false; 45 | } 46 | 47 | /** {@inheritDoc} */ 48 | public Date getLastModifiedDate() { 49 | return new Date(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/ArchiveEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers; 20 | 21 | import java.util.Date; 22 | 23 | /** 24 | * Represents an entry of an archive. 25 | */ 26 | public interface ArchiveEntry { 27 | 28 | /** The name of the entry in the archive. May refer to a file or directory or other item */ 29 | public String getName(); 30 | 31 | /** The (uncompressed) size of the entry. May be -1 (SIZE_UNKNOWN) if the size is unknown */ 32 | public long getSize(); 33 | 34 | /** Special value indicating that the size is unknown */ 35 | public static final long SIZE_UNKNOWN = -1; 36 | 37 | /** True if the entry refers to a directory */ 38 | public boolean isDirectory(); 39 | 40 | /** 41 | * The last modified date of the entry. 42 | * 43 | * @since 1.1 44 | */ 45 | public Date getLastModifiedDate(); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | src 19 | 20 | tar.gz 21 | zip 22 | 23 | ${artifactId}-${commons.release.version}-src 24 | 25 | 26 | 27 | build.xml 28 | LICENSE.txt 29 | NOTICE.txt 30 | README.txt 31 | RELEASE-NOTES.txt 32 | pom.xml 33 | STATUS 34 | findbugs-exclude-filter.xml 35 | pmd-ruleset.xml 36 | 37 | 38 | 39 | src 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/zip/Zip64Mode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.zip; 20 | 21 | /** 22 | * The different modes {@link ZipArchiveOutputStream} can operate in. 23 | * 24 | * @see ZipArchiveOutputStream#setUseZip64 25 | * 26 | * @since 1.3 27 | */ 28 | public enum Zip64Mode { 29 | /** 30 | * Use Zip64 extensions for all entries, even if it is clear it is 31 | * not required. 32 | */ 33 | Always, 34 | /** 35 | * Don't use Zip64 extensions for any entries. 36 | * 37 | *

This will cause a {@link Zip64RequiredException} to be 38 | * thrown if {@link ZipArchiveOutputStream} detects it needs Zip64 39 | * support.

40 | */ 41 | Never, 42 | /** 43 | * Use Zip64 extensions for all entries where they are required, 44 | * don't use them for entries that clearly don't require them. 45 | */ 46 | AsNeeded 47 | } 48 | -------------------------------------------------------------------------------- /src/main/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | bin 19 | 20 | tar.gz 21 | zip 22 | 23 | false 24 | 25 | 26 | 27 | LICENSE.txt 28 | NOTICE.txt 29 | README.txt 30 | RELEASE-NOTES.txt 31 | 32 | 33 | 34 | target 35 | 36 | 37 | *.jar 38 | 39 | 40 | 41 | target/site/apidocs 42 | apidocs 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/compressors/CompressorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.compressors; 20 | 21 | /** 22 | * Compressor related exception 23 | */ 24 | public class CompressorException extends Exception { 25 | 26 | /** Serial */ 27 | private static final long serialVersionUID = -2932901310255908814L; 28 | 29 | /** 30 | * Constructs a new exception with the specified detail message. The cause 31 | * is not initialized. 32 | * 33 | * @param message 34 | * the detail message 35 | */ 36 | public CompressorException(String message) { 37 | super(message); 38 | } 39 | 40 | /** 41 | * Constructs a new exception with the specified detail message and cause. 42 | * 43 | * @param message 44 | * the detail message 45 | * @param cause 46 | * the cause 47 | */ 48 | public CompressorException(String message, Throwable cause) { 49 | super(message, cause); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/ArchiveException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers; 20 | 21 | /** 22 | * Archiver related Exception 23 | */ 24 | public class ArchiveException extends Exception { 25 | 26 | /** Serial */ 27 | private static final long serialVersionUID = 2772690708123267100L; 28 | 29 | /** 30 | * Constructs a new exception with the specified detail message. The cause 31 | * is not initialized. 32 | * 33 | * @param message 34 | * the detail message 35 | */ 36 | public ArchiveException(String message) { 37 | super(message); 38 | } 39 | 40 | /** 41 | * Constructs a new exception with the specified detail message and cause. 42 | * 43 | * @param message 44 | * the detail message 45 | * @param cause 46 | * the cause 47 | */ 48 | public ArchiveException(String message, Exception cause) { 49 | super(message); 50 | this.initCause(cause); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.tar; 20 | 21 | import java.io.File; 22 | import java.io.FileInputStream; 23 | import java.net.URI; 24 | import java.net.URL; 25 | 26 | import junit.framework.TestCase; 27 | 28 | public class SparseFilesTest extends TestCase { 29 | 30 | public void testOldGNU() throws Throwable { 31 | URL tar = getClass().getResource("/oldgnu_sparse.tar"); 32 | File file = new File(new URI(tar.toString())); 33 | TarArchiveInputStream tin = null; 34 | try { 35 | tin = new TarArchiveInputStream(new FileInputStream(file)); 36 | TarArchiveEntry ae = tin.getNextTarEntry(); 37 | assertEquals("sparsefile", ae.getName()); 38 | assertTrue(ae.isGNUSparse()); 39 | assertFalse(tin.canReadEntryData(ae)); 40 | } finally { 41 | if (tin != null) { 42 | tin.close(); 43 | } 44 | } 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.dump; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | 23 | import org.junit.Test; 24 | 25 | public class DumpArchiveEntryTest { 26 | @Test 27 | public void publicNameAddsTrailingSlashForDirectories() { 28 | DumpArchiveEntry ent = new DumpArchiveEntry("foo", "bar", -1, 29 | DumpArchiveEntry.TYPE 30 | .DIRECTORY); 31 | assertEquals("bar", ent.getSimpleName()); 32 | assertEquals("foo", ent.getOriginalName()); 33 | assertEquals("foo/", ent.getName()); 34 | } 35 | 36 | @Test 37 | public void publicNameRemovesLeadingDotSlash() { 38 | DumpArchiveEntry ent = new DumpArchiveEntry("./foo", "bar"); 39 | assertEquals("bar", ent.getSimpleName()); 40 | assertEquals("./foo", ent.getOriginalName()); 41 | assertEquals("foo", ent.getName()); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/zip/Zip64RequiredException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.zip; 20 | 21 | import java.util.zip.ZipException; 22 | 23 | /** 24 | * Exception thrown when attempting to write data that requires Zip64 25 | * support to an archive and {@link ZipArchiveOutputStream#setUseZip64 26 | * UseZip64} has been set to {@link Zip64Mode#Never Never}. 27 | * @since 1.3 28 | */ 29 | public class Zip64RequiredException extends ZipException { 30 | 31 | private static final long serialVersionUID = 20110809L; 32 | 33 | /** 34 | * Helper to format "entry too big" messages. 35 | */ 36 | static String getEntryTooBigMessage(ZipArchiveEntry ze) { 37 | return ze.getName() + "'s size exceeds the limit of 4GByte."; 38 | } 39 | 40 | static final String ARCHIVE_TOO_BIG_MESSAGE = 41 | "archive's size exceeds the limit of 4GByte."; 42 | 43 | static final String TOO_MANY_ENTRIES_MESSAGE = 44 | "archive contains more than 65535 entries."; 45 | 46 | public Zip64RequiredException(String reason) { 47 | super(reason); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.dump; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | 23 | import org.junit.Test; 24 | 25 | public class DumpArchiveUtilTest { 26 | 27 | @Test 28 | public void convert64() { 29 | assertEquals(0xABCDEF0123456780L, 30 | DumpArchiveUtil.convert64(new byte[] { 31 | (byte) 0x80, 0x67, 0x45, 0x23, 1, (byte) 0xEF, 32 | (byte) 0xCD, (byte) 0xAB 33 | }, 0)); 34 | } 35 | 36 | @Test 37 | public void convert32() { 38 | assertEquals(0xABCDEF01, 39 | DumpArchiveUtil.convert32(new byte[] { 40 | 1, (byte) 0xEF, (byte) 0xCD, (byte) 0xAB 41 | }, 0)); 42 | } 43 | 44 | @Test 45 | public void convert16() { 46 | assertEquals(0xABCD, 47 | DumpArchiveUtil.convert16(new byte[] { 48 | (byte) 0xCD, (byte) 0xAB 49 | }, 0)); 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/compressors/pack200/TempFileCachingStreamBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.compress.compressors.pack200; 21 | 22 | import java.io.File; 23 | import java.io.FileInputStream; 24 | import java.io.FileOutputStream; 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | 28 | /** 29 | * StreamSwitcher that caches all data written to the output side in 30 | * a temporary file. 31 | * @since 1.3 32 | */ 33 | class TempFileCachingStreamBridge extends StreamBridge { 34 | private final File f; 35 | 36 | TempFileCachingStreamBridge() throws IOException { 37 | f = File.createTempFile("commons-compress", "packtemp"); 38 | f.deleteOnExit(); 39 | out = new FileOutputStream(f); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | @Override 46 | InputStream getInputView() throws IOException { 47 | out.close(); 48 | return new FileInputStream(f) { 49 | @Override 50 | public void close() throws IOException { 51 | super.close(); 52 | f.delete(); 53 | } 54 | }; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Created-By: Apache Maven Bundle Plugin 3 | Built-By: thallgren 4 | Build-Jdk: 1.6.0_22 5 | Extension-Name: org.apache.commons.compress 6 | Implementation-Title: Commons Compress 7 | Implementation-Vendor: The Apache Software Foundation 8 | Implementation-Vendor-Id: org.apache 9 | Implementation-Version: 1.3 10 | Main-Class: org.apache.commons.compress.archivers.Lister 11 | Specification-Title: Commons Compress 12 | Specification-Vendor: The Apache Software Foundation 13 | Specification-Version: 1.3 14 | X-Compile-Source-JDK: 1.5 15 | X-Compile-Target-JDK: 1.5 16 | Export-Package: org.apache.commons.compress.compressors.pack200;versio 17 | n="1.3",org.apache.commons.compress.changes;version="1.3",org.apache. 18 | commons.compress.archivers.ar;version="1.3",org.apache.commons.compre 19 | ss.archivers.jar;version="1.3",org.apache.commons.compress.archivers. 20 | cpio;version="1.3",org.apache.commons.compress.archivers;version="1.3 21 | ",org.apache.commons.compress.archivers.tar;version="1.3",org.apache. 22 | commons.compress.archivers.zip;version="1.3",org.apache.commons.compr 23 | ess.archivers.dump;version="1.3",org.apache.commons.compress.compress 24 | ors.bzip2;version="1.3",org.apache.commons.compress.compressors;versi 25 | on="1.3",org.apache.commons.compress.utils;version="1.3",org.apache.c 26 | ommons.compress.compressors.gzip;version="1.3" 27 | Bundle-Name: Commons Compress 28 | Bundle-Vendor: The Apache Software Foundation 29 | Bundle-Version: 1.5.0.qualifier 30 | Bundle-ManifestVersion: 2 31 | Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt 32 | Bundle-Description: Apache Commons Compress software defines an API fo 33 | r working with compression and archive formats. These include: bzip2 34 | , gzip, pack200 and ar, cpio, jar, tar, zip, dump. 35 | Bundle-DocURL: http://commons.apache.org/compress/ 36 | Include-Resource: META-INF/LICENSE.txt=LICENSE.txt,META-INF/NOTICE.txt 37 | =NOTICE.txt 38 | Bundle-SymbolicName: org.apache.commons.compress 39 | Bundle-RequiredExecutionEnvironment: JavaSE-1.6, 40 | J2SE-1.5 41 | -------------------------------------------------------------------------------- /src/test/resources/archives/FreeBSD_crc.cpio: -------------------------------------------------------------------------------- 1 | 070702061d1a63000081b4000006b9000006b90000000149cea04d0000001b00000000000000bb00000000000000000000000200000b291abcdefghijklmnopqrstuvwxyz 2 | 070702061d1a61000081b4000006b9000006b90000000149cea04d0000001b00000000000000bb00000000000000000000000300000b2912abcdefghijklmnopqrstuvwxyz 3 | 070702061d1a60000081b4000006b9000006b90000000149cea04d0000001b00000000000000bb00000000000000000000000400000b29123abcdefghijklmnopqrstuvwxyz 4 | 07070201c08024000081b4000006b9000006b90000000149cea04e0000001b00000000000000bb00000000000000000000000500000b291234abcdefghijklmnopqrstuvwxyz 5 | 07070201c08023000081b4000006b9000006b90000000149cea04e0000001b00000000000000bb00000000000000000000000600000b2912345abcdefghijklmnopqrstuvwxyz 6 | 070702061d1704000081a4000006b9000006b90000000149cea04e0000001b00000000000000bb00000000000000000000000700000b29123450abcdefghijklmnopqrstuvwxyz 7 | 07070201c08022000081b4000006b9000006b90000000149cea04e0000001a00000000000000bb00000000000000000000000700000ac8123456bcdefghijklmnopqrstuvwxyz 8 | 070702061d177b000081a4000006b9000006b90000000149cea04e0000001900000000000000bb00000000000000000000000700000a66123457cdefghijklmnopqrstuvwxyz 9 | 070702061d177f000081a4000006b9000006b90000000149cea04e0000001800000000000000bb00000000000000000000000700000a03123458defghijklmnopqrstuvwxyz 10 | 070702061d1783000081a4000006b9000006b90000000149cea04e0000001700000000000000bb0000000000000000000000070000099f123459efghijklmnopqrstuvwxyz 11 | 07070200000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000b00000000TRAILER!!! -------------------------------------------------------------------------------- /src/test/resources/archives/SunOS_-c.cpio: -------------------------------------------------------------------------------- 1 | 07070100289305000081a400000a2e000000010000000149ce6a8e0000001b000000b500010005ffffffffffffffff00000002000000001abcdefghijklmnopqrstuvwxyz 2 | 07070100289306000081a400000a2e000000010000000149ce9c8c0000001b000000b500010005ffffffffffffffff000000030000000012abcdefghijklmnopqrstuvwxyz 3 | 0707010058e278000081a400000a2e000000010000000149ce9c910000001b000000b500010005ffffffffffffffff0000000400000000123abcdefghijklmnopqrstuvwxyz 4 | 0707010058f486000081a400000a2e000000010000000149ce9c9b0000001b000000b500010005ffffffffffffffff00000005000000001234abcdefghijklmnopqrstuvwxyz 5 | 0707010058f5d4000081a400000a2e000000010000000149ce9c9d0000001b000000b500010005ffffffffffffffff000000060000000012345abcdefghijklmnopqrstuvwxyz 6 | 070701004beba0000081a400000a2e000000010000000149ce9d090000001b000000b500010005ffffffffffffffff0000000700000000123450abcdefghijklmnopqrstuvwxyz 7 | 0707010058f62d000081a400000a2e000000010000000149ce9df40000001a000000b500010005ffffffffffffffff0000000700000000123456bcdefghijklmnopqrstuvwxyz 8 | 070701004beb9a000081a400000a2e000000010000000149ce9e1c00000019000000b500010005ffffffffffffffff0000000700000000123457cdefghijklmnopqrstuvwxyz 9 | 070701004beb9d000081a400000a2e000000010000000149ce9e2600000018000000b500010005ffffffffffffffff0000000700000000123458defghijklmnopqrstuvwxyz 10 | 070701004beb9e000081a400000a2e000000010000000149ce9e2f00000017000000b500010005ffffffffffffffff0000000700000000123459efghijklmnopqrstuvwxyz 11 | 07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000b00000000TRAILER!!! -------------------------------------------------------------------------------- /src/test/resources/archives/SunOS_crc.cpio: -------------------------------------------------------------------------------- 1 | 07070200289305000081a400000a2e000000010000000149ce6a8e0000001b000000b500010005ffffffffffffffff0000000200000b291abcdefghijklmnopqrstuvwxyz 2 | 07070200289306000081a400000a2e000000010000000149ce9c8c0000001b000000b500010005ffffffffffffffff0000000300000b2912abcdefghijklmnopqrstuvwxyz 3 | 0707020058e278000081a400000a2e000000010000000149ce9c910000001b000000b500010005ffffffffffffffff0000000400000b29123abcdefghijklmnopqrstuvwxyz 4 | 0707020058f486000081a400000a2e000000010000000149ce9c9b0000001b000000b500010005ffffffffffffffff0000000500000b291234abcdefghijklmnopqrstuvwxyz 5 | 0707020058f5d4000081a400000a2e000000010000000149ce9c9d0000001b000000b500010005ffffffffffffffff0000000600000b2912345abcdefghijklmnopqrstuvwxyz 6 | 070702004beba0000081a400000a2e000000010000000149ce9d090000001b000000b500010005ffffffffffffffff0000000700000b29123450abcdefghijklmnopqrstuvwxyz 7 | 0707020058f62d000081a400000a2e000000010000000149ce9df40000001a000000b500010005ffffffffffffffff0000000700000ac8123456bcdefghijklmnopqrstuvwxyz 8 | 070702004beb9a000081a400000a2e000000010000000149ce9e1c00000019000000b500010005ffffffffffffffff0000000700000a66123457cdefghijklmnopqrstuvwxyz 9 | 070702004beb9d000081a400000a2e000000010000000149ce9e2600000018000000b500010005ffffffffffffffff0000000700000a03123458defghijklmnopqrstuvwxyz 10 | 070702004beb9e000081a400000a2e000000010000000149ce9e2f00000017000000b500010005ffffffffffffffff000000070000099f123459efghijklmnopqrstuvwxyz 11 | 07070200000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000b00000000TRAILER!!! -------------------------------------------------------------------------------- /src/test/resources/archives/FreeBSD_newc.cpio: -------------------------------------------------------------------------------- 1 | 070701061d1a63000081b4000006b9000006b90000000149cea04d0000001b00000000000000bb000000000000000000000002000000001abcdefghijklmnopqrstuvwxyz 2 | 070701061d1a61000081b4000006b9000006b90000000149cea04d0000001b00000000000000bb0000000000000000000000030000000012abcdefghijklmnopqrstuvwxyz 3 | 070701061d1a60000081b4000006b9000006b90000000149cea04d0000001b00000000000000bb00000000000000000000000400000000123abcdefghijklmnopqrstuvwxyz 4 | 07070101c08024000081b4000006b9000006b90000000149cea04e0000001b00000000000000bb000000000000000000000005000000001234abcdefghijklmnopqrstuvwxyz 5 | 07070101c08023000081b4000006b9000006b90000000149cea04e0000001b00000000000000bb0000000000000000000000060000000012345abcdefghijklmnopqrstuvwxyz 6 | 070701061d1704000081a4000006b9000006b90000000149cea04e0000001b00000000000000bb00000000000000000000000700000000123450abcdefghijklmnopqrstuvwxyz 7 | 07070101c08022000081b4000006b9000006b90000000149cea04e0000001a00000000000000bb00000000000000000000000700000000123456bcdefghijklmnopqrstuvwxyz 8 | 070701061d177b000081a4000006b9000006b90000000149cea04e0000001900000000000000bb00000000000000000000000700000000123457cdefghijklmnopqrstuvwxyz 9 | 070701061d177f000081a4000006b9000006b90000000149cea04e0000001800000000000000bb00000000000000000000000700000000123458defghijklmnopqrstuvwxyz 10 | 070701061d1783000081a4000006b9000006b90000000149cea04e0000001700000000000000bb00000000000000000000000700000000123459efghijklmnopqrstuvwxyz 11 | 07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000b00000000TRAILER!!! -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.cpio; 20 | 21 | import java.io.FileInputStream; 22 | 23 | import org.apache.commons.compress.AbstractTestCase; 24 | 25 | public class CpioArchiveInputStreamTest extends AbstractTestCase { 26 | 27 | public void testCpioUnarchive() throws Exception { 28 | StringBuffer expected = new StringBuffer(); 29 | expected.append("./test1.xml\n"); 30 | expected.append("./test2.xml\n"); 31 | expected.append("\n"); 32 | 33 | 34 | CpioArchiveInputStream in = 35 | new CpioArchiveInputStream(new FileInputStream(getFile("bla.cpio"))); 36 | CpioArchiveEntry entry= null; 37 | 38 | StringBuffer result = new StringBuffer(); 39 | while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) { 40 | result.append(entry.getName()); 41 | int tmp; 42 | while ((tmp = in.read()) != -1) { 43 | result.append((char) tmp); 44 | } 45 | } 46 | in.close(); 47 | assertEquals(result.toString(), expected.toString()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/zip/UnixStat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.zip; 20 | 21 | /** 22 | * Constants from stat.h on Unix systems. 23 | */ 24 | // CheckStyle:InterfaceIsTypeCheck OFF - backward compatible 25 | public interface UnixStat { 26 | 27 | /** 28 | * Bits used for permissions (and sticky bit) 29 | */ 30 | int PERM_MASK = 07777; 31 | /** 32 | * Indicates symbolic links. 33 | */ 34 | int LINK_FLAG = 0120000; 35 | /** 36 | * Indicates plain files. 37 | */ 38 | int FILE_FLAG = 0100000; 39 | /** 40 | * Indicates directories. 41 | */ 42 | int DIR_FLAG = 040000; 43 | 44 | // ---------------------------------------------------------- 45 | // somewhat arbitrary choices that are quite common for shared 46 | // installations 47 | // ----------------------------------------------------------- 48 | 49 | /** 50 | * Default permissions for symbolic links. 51 | */ 52 | int DEFAULT_LINK_PERM = 0777; 53 | 54 | /** 55 | * Default permissions for directories. 56 | */ 57 | int DEFAULT_DIR_PERM = 0755; 58 | 59 | /** 60 | * Default permissions for plain files. 61 | */ 62 | int DEFAULT_FILE_PERM = 0644; 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.memory; 20 | 21 | import java.io.IOException; 22 | 23 | import junit.framework.TestCase; 24 | 25 | import org.apache.commons.compress.archivers.ArchiveEntry; 26 | 27 | public final class MemoryArchiveTestCase extends TestCase { 28 | 29 | public void testReading() throws IOException { 30 | 31 | final MemoryArchiveInputStream is = new MemoryArchiveInputStream(new String[][] { 32 | { "test1", "content1" }, 33 | { "test2", "content2" }, 34 | }); 35 | 36 | final ArchiveEntry entry1 = is.getNextEntry(); 37 | assertNotNull(entry1); 38 | assertEquals("test1", entry1.getName()); 39 | final String content1 = is.readString(); 40 | assertEquals("content1", content1); 41 | 42 | final ArchiveEntry entry2 = is.getNextEntry(); 43 | assertNotNull(entry2); 44 | assertEquals("test2", entry2.getName()); 45 | final String content2 = is.readString(); 46 | assertEquals("content2", content2); 47 | 48 | final ArchiveEntry entry3 = is.getNextEntry(); 49 | assertNull(entry3); 50 | 51 | is.close(); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.jar; 20 | 21 | import java.io.IOException; 22 | import java.io.OutputStream; 23 | 24 | import org.apache.commons.compress.archivers.ArchiveEntry; 25 | import org.apache.commons.compress.archivers.zip.JarMarker; 26 | import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; 27 | import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; 28 | 29 | /** 30 | * Subclass that adds a special extra field to the very first entry 31 | * which allows the created archive to be used as an executable jar on 32 | * Solaris. 33 | * 34 | * @NotThreadSafe 35 | */ 36 | public class JarArchiveOutputStream extends ZipArchiveOutputStream { 37 | 38 | private boolean jarMarkerAdded = false; 39 | 40 | public JarArchiveOutputStream(final OutputStream out) { 41 | super(out); 42 | } 43 | 44 | // @throws ClassCastException if entry is not an instance of ZipArchiveEntry 45 | @Override 46 | public void putArchiveEntry(ArchiveEntry ze) throws IOException { 47 | if (!jarMarkerAdded) { 48 | ((ZipArchiveEntry)ze).addAsFirstExtraField(JarMarker.getInstance()); 49 | jarMarkerAdded = true; 50 | } 51 | super.putArchiveEntry(ze); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.compressors.gzip; 20 | 21 | import java.io.IOException; 22 | import java.io.OutputStream; 23 | import java.util.zip.GZIPOutputStream; 24 | 25 | import org.apache.commons.compress.compressors.CompressorOutputStream; 26 | 27 | public class GzipCompressorOutputStream extends CompressorOutputStream { 28 | 29 | private final GZIPOutputStream out; 30 | 31 | public GzipCompressorOutputStream( final OutputStream outputStream ) throws IOException { 32 | out = new GZIPOutputStream(outputStream); 33 | } 34 | 35 | /** {@inheritDoc} */ 36 | @Override 37 | public void write(int b) throws IOException { 38 | out.write(b); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | * 44 | * @since 1.1 45 | */ 46 | @Override 47 | public void write(byte[] b) throws IOException { 48 | out.write(b); 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | * 54 | * @since 1.1 55 | */ 56 | @Override 57 | public void write(byte[] b, int from, int length) throws IOException { 58 | out.write(b, from, length); 59 | } 60 | 61 | @Override 62 | public void close() throws IOException { 63 | out.close(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.dump; 20 | 21 | import java.io.FileInputStream; 22 | 23 | import org.apache.commons.compress.AbstractTestCase; 24 | import org.apache.commons.compress.archivers.ArchiveException; 25 | 26 | public class DumpArchiveInputStreamTest extends AbstractTestCase { 27 | 28 | public void testNotADumpArchive() throws Exception { 29 | FileInputStream is = new FileInputStream(getFile("bla.zip")); 30 | try { 31 | new DumpArchiveInputStream(is); 32 | fail("expected an exception"); 33 | } catch (ArchiveException ex) { 34 | // expected 35 | assertTrue(ex.getCause() instanceof ShortFileException); 36 | } finally { 37 | is.close(); 38 | } 39 | } 40 | 41 | public void testNotADumpArchiveButBigEnough() throws Exception { 42 | FileInputStream is = new FileInputStream(getFile("zip64support.tar.bz2")); 43 | try { 44 | new DumpArchiveInputStream(is); 45 | fail("expected an exception"); 46 | } catch (ArchiveException ex) { 47 | // expected 48 | assertTrue(ex.getCause() instanceof UnrecognizedFormatException); 49 | } finally { 50 | is.close(); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.memory; 20 | 21 | import java.io.IOException; 22 | 23 | import org.apache.commons.compress.archivers.ArchiveEntry; 24 | import org.apache.commons.compress.archivers.ArchiveInputStream; 25 | 26 | public final class MemoryArchiveInputStream extends ArchiveInputStream { 27 | 28 | private final String[] filenames; 29 | private final String[] content; 30 | private int p; 31 | 32 | public MemoryArchiveInputStream( final String[][] pFiles ) { 33 | filenames = new String[pFiles.length]; 34 | content = new String[pFiles.length]; 35 | 36 | for (int i = 0; i < pFiles.length; i++) { 37 | String[] nameAndContent = pFiles[i]; 38 | filenames[i] = nameAndContent[0]; 39 | content[i] = nameAndContent[1]; 40 | } 41 | p = 0; 42 | } 43 | 44 | @Override 45 | public ArchiveEntry getNextEntry() throws IOException { 46 | if (p >= filenames.length) { 47 | return null; 48 | } 49 | 50 | return new MemoryArchiveEntry(filenames[p]); 51 | } 52 | 53 | public String readString() { 54 | return content[p++]; 55 | } 56 | 57 | @Override 58 | public int read() throws IOException { 59 | return 0; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | package org.apache.commons.compress.archivers.zip; 19 | 20 | /** 21 | * Various constants used throughout the package. 22 | * 23 | * @since 1.3 24 | */ 25 | final class ZipConstants { 26 | private ZipConstants() { } 27 | 28 | /** Masks last eight bits */ 29 | static final int BYTE_MASK = 0xFF; 30 | 31 | /** length of a ZipShort in bytes */ 32 | static final int SHORT = 2; 33 | 34 | /** length of a ZipLong in bytes */ 35 | static final int WORD = 4; 36 | 37 | /** length of a ZipEightByteInteger in bytes */ 38 | static final int DWORD = 8; 39 | 40 | /** Initial ZIP specification version */ 41 | static final int INITIAL_VERSION = 10; 42 | 43 | /** ZIP specification version that introduced data descriptor method */ 44 | static final int DATA_DESCRIPTOR_MIN_VERSION = 20; 45 | 46 | /** ZIP specification version that introduced ZIP64 */ 47 | static final int ZIP64_MIN_VERSION = 45; 48 | 49 | /** 50 | * Value stored in two-byte size and similar fields if ZIP64 51 | * extensions are used. 52 | */ 53 | static final int ZIP64_MAGIC_SHORT = 0xFFFF; 54 | 55 | /** 56 | * Value stored in four-byte size and similar fields if ZIP64 57 | * extensions are used. 58 | */ 59 | static final long ZIP64_MAGIC = 0xFFFFFFFFL; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveSparseEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.tar; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * This class represents a sparse entry in a Tar archive. 25 | * 26 | *

27 | * The C structure for a sparse entry is: 28 | *

29 |  * struct posix_header {
30 |  * struct sparse sp[21]; // TarConstants.SPARSELEN_GNU_SPARSE     - offset 0
31 |  * char isextended;      // TarConstants.ISEXTENDEDLEN_GNU_SPARSE - offset 504
32 |  * };
33 |  * 
34 | * Whereas, "struct sparse" is: 35 | *
36 |  * struct sparse {
37 |  * char offset[12];   // offset 0
38 |  * char numbytes[12]; // offset 12
39 |  * };
40 |  * 
41 | */ 42 | 43 | public class TarArchiveSparseEntry implements TarConstants { 44 | /** If an extension sparse header follows. */ 45 | private boolean isExtended; 46 | 47 | /** 48 | * Construct an entry from an archive's header bytes. File is set 49 | * to null. 50 | * 51 | * @param headerBuf The header bytes from a tar archive entry. 52 | * @throws IOException on unknown format 53 | */ 54 | public TarArchiveSparseEntry(byte[] headerBuf) throws IOException { 55 | int offset = 0; 56 | offset += SPARSELEN_GNU_SPARSE; 57 | isExtended = TarUtils.parseBoolean(headerBuf, offset); 58 | } 59 | 60 | public boolean isExtended() { 61 | return isExtended; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/ChainingTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress; 20 | 21 | import java.io.File; 22 | import java.io.FileInputStream; 23 | 24 | import org.apache.commons.compress.archivers.tar.TarArchiveEntry; 25 | import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; 26 | import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; 27 | import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; 28 | 29 | 30 | public class ChainingTestCase extends AbstractTestCase { 31 | 32 | public void testTarGzip() throws Exception { 33 | File file = new File("src/test/resources/bla.tgz"); 34 | final TarArchiveInputStream is = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(file))); 35 | final TarArchiveEntry entry = (TarArchiveEntry)is.getNextEntry(); 36 | assertNotNull(entry); 37 | assertEquals("test1.xml", entry.getName()); 38 | is.close(); 39 | } 40 | 41 | public void testTarBzip2() throws Exception { 42 | File file = new File("src/test/resources/bla.tar.bz2"); 43 | final TarArchiveInputStream is = new TarArchiveInputStream(new BZip2CompressorInputStream(new FileInputStream(file))); 44 | final TarArchiveEntry entry = (TarArchiveEntry)is.getNextEntry(); 45 | assertNotNull(entry); 46 | assertEquals("test1.xml", entry.getName()); 47 | is.close(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.cpio; 20 | 21 | import static org.junit.Assert.assertArrayEquals; 22 | import static org.junit.Assert.assertEquals; 23 | 24 | import org.junit.Test; 25 | 26 | public class CpioUtilTest { 27 | 28 | @Test 29 | public void oldBinMagic2ByteArrayNotSwapped() { 30 | assertArrayEquals(new byte[] { (byte) 0xc7, 0x71 }, 31 | CpioUtil.long2byteArray(CpioConstants.MAGIC_OLD_BINARY, 32 | 2, false)); 33 | } 34 | 35 | @Test 36 | public void oldBinMagic2ByteArraySwapped() { 37 | assertArrayEquals(new byte[] { 0x71, (byte) 0xc7, }, 38 | CpioUtil.long2byteArray(CpioConstants.MAGIC_OLD_BINARY, 39 | 2, true)); 40 | } 41 | 42 | @Test 43 | public void oldBinMagicFromByteArrayNotSwapped() { 44 | assertEquals(CpioConstants.MAGIC_OLD_BINARY, 45 | CpioUtil.byteArray2long(new byte[] { (byte) 0xc7, 0x71 }, 46 | false)); 47 | } 48 | 49 | @Test 50 | public void oldBinMagicFromByteArraySwapped() { 51 | assertEquals(CpioConstants.MAGIC_OLD_BINARY, 52 | CpioUtil.byteArray2long(new byte[] { 0x71, (byte) 0xc7 }, 53 | true)); 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/dump/Dirent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.dump; 20 | 21 | /** 22 | * Directory entry. 23 | */ 24 | class Dirent { 25 | private int ino; 26 | private int parentIno; 27 | private int type; 28 | private String name; 29 | 30 | /** 31 | * Constructor 32 | * 33 | * @param ino 34 | * @param parentIno 35 | * @param type 36 | * @param name 37 | */ 38 | Dirent(int ino, int parentIno, int type, String name) { 39 | this.ino = ino; 40 | this.parentIno = parentIno; 41 | this.type = type; 42 | this.name = name; 43 | } 44 | 45 | /** 46 | * Get ino. 47 | * @return the i-node 48 | */ 49 | int getIno() { 50 | return ino; 51 | } 52 | 53 | /** 54 | * Get ino of parent directory. 55 | * @return the parent i-node 56 | */ 57 | int getParentIno() { 58 | return parentIno; 59 | } 60 | 61 | /** 62 | * Get entry type. 63 | * @return the entry type 64 | */ 65 | int getType() { 66 | return type; 67 | } 68 | 69 | /** 70 | * Get name of directory entry. 71 | * @return the directory name 72 | */ 73 | String getName() { 74 | return name; 75 | } 76 | 77 | /** 78 | * @see java.lang.Object#toString() 79 | */ 80 | @Override 81 | public String toString() { 82 | return String.format("[%d]: %s", Integer.valueOf(ino), name); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/compressors/pack200/StreamBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.compress.compressors.pack200; 21 | 22 | import java.io.FilterOutputStream; 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | import java.io.OutputStream; 26 | 27 | /** 28 | * Provides an InputStream to read all data written to this 29 | * OutputStream. 30 | * 31 | * @ThreadSafe 32 | * @since 1.3 33 | */ 34 | abstract class StreamBridge extends FilterOutputStream { 35 | private InputStream input; 36 | private final Object INPUT_LOCK = new Object(); 37 | 38 | protected StreamBridge(OutputStream out) { 39 | super(out); 40 | } 41 | 42 | protected StreamBridge() { 43 | this(null); 44 | } 45 | 46 | /** 47 | * Provides the input view. 48 | */ 49 | InputStream getInput() throws IOException { 50 | synchronized (INPUT_LOCK) { 51 | if (input == null) { 52 | input = getInputView(); 53 | } 54 | } 55 | return input; 56 | } 57 | 58 | /** 59 | * Creates the input view. 60 | */ 61 | abstract InputStream getInputView() throws IOException; 62 | 63 | /** 64 | * Closes input and output and releases all associated resources. 65 | */ 66 | void stop() throws IOException { 67 | close(); 68 | synchronized (INPUT_LOCK) { 69 | if (input != null) { 70 | input.close(); 71 | input = null; 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.ar; 20 | 21 | import java.io.BufferedInputStream; 22 | import java.io.FileInputStream; 23 | 24 | import org.apache.commons.compress.AbstractTestCase; 25 | import org.apache.commons.compress.archivers.ArchiveEntry; 26 | import org.apache.commons.compress.utils.ArchiveUtils; 27 | 28 | public class ArArchiveInputStreamTest extends AbstractTestCase { 29 | 30 | public void testReadLongNamesGNU() throws Exception { 31 | checkLongNameEntry("longfile_gnu.ar"); 32 | } 33 | 34 | public void testReadLongNamesBSD() throws Exception { 35 | checkLongNameEntry("longfile_bsd.ar"); 36 | } 37 | 38 | private void checkLongNameEntry(String archive) throws Exception { 39 | FileInputStream fis = new FileInputStream(getFile(archive)); 40 | ArArchiveInputStream s = null; 41 | try { 42 | s = new ArArchiveInputStream(new BufferedInputStream(fis)); 43 | ArchiveEntry e = s.getNextEntry(); 44 | assertEquals("this_is_a_long_file_name.txt", e.getName()); 45 | assertEquals(14, e.getSize()); 46 | byte[] hello = new byte[14]; 47 | s.read(hello); 48 | assertEquals("Hello, world!\n", ArchiveUtils.toAsciiString(hello)); 49 | assertNull(s.getNextEntry()); 50 | } finally { 51 | if (s != null) { 52 | s.close(); 53 | } 54 | fis.close(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/utils/CountingOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.utils; 20 | 21 | import java.io.FilterOutputStream; 22 | import java.io.IOException; 23 | import java.io.OutputStream; 24 | 25 | /** 26 | * Stream that tracks the number of bytes read. 27 | * @since 1.3 28 | * @NotThreadSafe 29 | */ 30 | public class CountingOutputStream extends FilterOutputStream { 31 | private long bytesWritten = 0; 32 | 33 | public CountingOutputStream(final OutputStream out) { 34 | super(out); 35 | } 36 | 37 | @Override 38 | public void write(int b) throws IOException { 39 | out.write(b); 40 | count(1); 41 | } 42 | @Override 43 | public void write(byte[] b) throws IOException { 44 | write(b, 0, b.length); 45 | } 46 | @Override 47 | public void write(byte[] b, int off, int len) throws IOException { 48 | out.write(b, off, len); 49 | count(len); 50 | } 51 | 52 | /** 53 | * Increments the counter of already written bytes. 54 | * Doesn't increment if the EOF has been hit (written == -1) 55 | * 56 | * @param written the number of bytes written 57 | */ 58 | protected void count(long written) { 59 | if (written != -1) { 60 | bytesWritten += written; 61 | } 62 | } 63 | 64 | /** 65 | * Returns the current number of bytes written to this stream. 66 | * @return the number of written bytes 67 | */ 68 | public long getBytesWritten() { 69 | return bytesWritten; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/compressors/CompressorInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.compressors; 20 | 21 | import java.io.InputStream; 22 | 23 | public abstract class CompressorInputStream extends InputStream { 24 | private long bytesRead = 0; 25 | 26 | /** 27 | * Increments the counter of already read bytes. 28 | * Doesn't increment if the EOF has been hit (read == -1) 29 | * 30 | * @param read the number of bytes read 31 | * 32 | * @since 1.1 33 | */ 34 | protected void count(int read) { 35 | count((long) read); 36 | } 37 | 38 | /** 39 | * Increments the counter of already read bytes. 40 | * Doesn't increment if the EOF has been hit (read == -1) 41 | * 42 | * @param read the number of bytes read 43 | */ 44 | protected void count(long read) { 45 | if(read != -1) { 46 | bytesRead = bytesRead + read; 47 | } 48 | } 49 | 50 | /** 51 | * Returns the current number of bytes read from this stream. 52 | * @return the number of read bytes 53 | * @deprecated this method may yield wrong results for large 54 | * archives, use #getBytesRead instead 55 | */ 56 | @Deprecated 57 | public int getCount() { 58 | return (int) bytesRead; 59 | } 60 | 61 | /** 62 | * Returns the current number of bytes read from this stream. 63 | * @return the number of read bytes 64 | * 65 | * @since 1.1 66 | */ 67 | public long getBytesRead() { 68 | return bytesRead; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.jar; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | 24 | import org.apache.commons.compress.archivers.ArchiveEntry; 25 | import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; 26 | import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; 27 | 28 | /** 29 | * Implements an input stream that can read entries from jar files. 30 | * 31 | * @NotThreadSafe 32 | */ 33 | public class JarArchiveInputStream extends ZipArchiveInputStream { 34 | 35 | public JarArchiveInputStream( final InputStream inputStream ) { 36 | super(inputStream); 37 | } 38 | 39 | public JarArchiveEntry getNextJarEntry() throws IOException { 40 | ZipArchiveEntry entry = getNextZipEntry(); 41 | return entry == null ? null : new JarArchiveEntry(entry); 42 | } 43 | 44 | @Override 45 | public ArchiveEntry getNextEntry() throws IOException { 46 | return getNextJarEntry(); 47 | } 48 | 49 | /** 50 | * Checks if the signature matches what is expected for a jar file 51 | * (in this case it is the same as for a zip file). 52 | * 53 | * @param signature 54 | * the bytes to check 55 | * @param length 56 | * the number of bytes to check 57 | * @return true, if this stream is a jar archive stream, false otherwise 58 | */ 59 | public static boolean matches(byte[] signature, int length ) { 60 | return ZipArchiveInputStream.matches(signature, length); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/utils/CharsetsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.compress.utils; 19 | 20 | import java.nio.charset.Charset; 21 | 22 | import junit.framework.Assert; 23 | 24 | import org.junit.Test; 25 | 26 | /** 27 | * Sanity checks for {@link Charsets}. 28 | * 29 | * @version $Id$ 30 | */ 31 | public class CharsetsTest { 32 | 33 | @Test 34 | public void testToCharset() { 35 | Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((String) null)); 36 | Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((Charset) null)); 37 | Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset(Charset.defaultCharset())); 38 | Assert.assertEquals(Charset.forName("UTF-8"), Charsets.toCharset(Charset.forName("UTF-8"))); 39 | } 40 | 41 | @Test 42 | public void testIso8859_1() { 43 | Assert.assertEquals("ISO-8859-1", Charsets.ISO_8859_1.name()); 44 | } 45 | 46 | @Test 47 | public void testUsAscii() { 48 | Assert.assertEquals("US-ASCII", Charsets.US_ASCII.name()); 49 | } 50 | 51 | @Test 52 | public void testUtf16() { 53 | Assert.assertEquals("UTF-16", Charsets.UTF_16.name()); 54 | } 55 | 56 | @Test 57 | public void testUtf16Be() { 58 | Assert.assertEquals("UTF-16BE", Charsets.UTF_16BE.name()); 59 | } 60 | 61 | @Test 62 | public void testUtf16Le() { 63 | Assert.assertEquals("UTF-16LE", Charsets.UTF_16LE.name()); 64 | } 65 | 66 | @Test 67 | public void testUtf8() { 68 | Assert.assertEquals("UTF-8", Charsets.UTF_8.name()); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/resources/longpath/files.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # 17 | # File prefixes correspond to the following OSes: 18 | # cygwin - CYGWIN_NT-5.1 1.7.1(0.218/5/3) 19 | # hudson - SunOS 5.10 20 | # minotaur - FreeBSD 8.0-STABLE 21 | # vmgump - Linux 2.6.24-27-server 22 | # winXP_ant - Ant 1.7.1 on Windows/XP 23 | # 24 | compress-test/ 25 | compress-test/dir1/ 26 | compress-test/dir1/dir2/ 27 | compress-test/dir1/dir2/dir3/ 28 | compress-test/dir1/dir2/dir3/dir4/ 29 | compress-test/dir1/dir2/dir3/dir4/dir5/ 30 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/ 31 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/ 32 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/ 33 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/ 34 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/ 35 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file12345678901234567890.txt 36 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file1234567890123456789012345678901234567890123456789012345678901234567890.txt 37 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file123456789012345678901234567890123456789012345678901234567890.txt 38 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file.txt 39 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file123456789012345678901234567890.txt 40 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file1234567890.txt 41 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file1234567890123456789012345678901234567890.txt 42 | compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file12345678901234567890123456789012345678901234567890.txt -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/utils/CountingInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.utils; 20 | 21 | import java.io.FilterInputStream; 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | 25 | /** 26 | * Stream that tracks the number of bytes read. 27 | * @since 1.3 28 | * @NotThreadSafe 29 | */ 30 | public class CountingInputStream extends FilterInputStream { 31 | private long bytesRead; 32 | 33 | public CountingInputStream(final InputStream in) { 34 | super(in); 35 | } 36 | 37 | @Override 38 | public int read() throws IOException { 39 | int r = in.read(); 40 | if (r >= 0) { 41 | count(1); 42 | } 43 | return r; 44 | } 45 | @Override 46 | public int read(byte[] b) throws IOException { 47 | return read(b, 0, b.length); 48 | } 49 | @Override 50 | public int read(byte[] b, int off, int len) throws IOException { 51 | int r = in.read(b, off, len); 52 | if (r >= 0) { 53 | count(r); 54 | } 55 | return r; 56 | } 57 | /** 58 | * Increments the counter of already read bytes. 59 | * Doesn't increment if the EOF has been hit (read == -1) 60 | * 61 | * @param read the number of bytes read 62 | */ 63 | protected final void count(long read) { 64 | if (read != -1) { 65 | bytesRead += read; 66 | } 67 | } 68 | 69 | /** 70 | * Returns the current number of bytes read from this stream. 71 | * @return the number of read bytes 72 | */ 73 | public long getBytesRead() { 74 | return bytesRead; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.jar; 20 | 21 | import java.security.cert.Certificate; 22 | import java.util.jar.Attributes; 23 | import java.util.jar.JarEntry; 24 | import java.util.zip.ZipEntry; 25 | import java.util.zip.ZipException; 26 | 27 | import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; 28 | 29 | /** 30 | * 31 | * @NotThreadSafe 32 | */ 33 | public class JarArchiveEntry extends ZipArchiveEntry { 34 | 35 | private Attributes manifestAttributes = null; 36 | private Certificate[] certificates = null; 37 | 38 | public JarArchiveEntry(ZipEntry entry) throws ZipException { 39 | super(entry); 40 | } 41 | 42 | public JarArchiveEntry(String name) { 43 | super(name); 44 | } 45 | 46 | public JarArchiveEntry(ZipArchiveEntry entry) throws ZipException { 47 | super(entry); 48 | } 49 | 50 | public JarArchiveEntry(JarEntry entry) throws ZipException { 51 | super(entry); 52 | 53 | } 54 | 55 | public Attributes getManifestAttributes() { 56 | return manifestAttributes; 57 | } 58 | 59 | public Certificate[] getCertificates() { 60 | if (certificates != null) { 61 | Certificate[] certs = new Certificate[certificates.length]; 62 | System.arraycopy(certificates, 0, certs, 0, certs.length); 63 | return certs; 64 | } 65 | return null; 66 | } 67 | 68 | @Override 69 | public boolean equals(Object o) { 70 | return super.equals(o); 71 | } 72 | 73 | @Override 74 | public int hashCode() { 75 | return super.hashCode(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/dump/package.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |

This package provides stream classes for reading archives 22 | using the Unix DUMP format. This format is similar to (and 23 | contemporary with) TAR but reads the raw filesystem directly. 24 | This means that writers are filesystem-specific even though the 25 | created archives are filesystem-agnostic. 26 |

27 | 28 |

Unlike other formats DUMP offers clean support for sparse files, 29 | extended attributes, and other file metadata. In addition DUMP 30 | supports incremental dump files can capture (most) file deletion. 31 | It also provides a native form of compression and will soon support 32 | native encryption as well. 33 |

34 | 35 |

In practice TAR archives are used for both distribution 36 | and backups. DUMP archives are used exclusively for backups. 37 |

38 | 39 |

Like any 30+-year-old application there are a number of variants. 40 | For pragmatic reasons we will only support archives with the 41 | 'new' tape header and inode formats. Other restrictions: 42 | 43 |

    44 |
  • We only support ZLIB compression. The format 45 | also permits LZO and BZLIB compression.
  • 46 |
  • Sparse files will have the holes filled.
  • 47 |
  • MacOS finder and resource streams are ignored.
  • 48 |
  • Extended attributes are not currently provided.
  • 49 |
  • SELinux labels are not currently provided.
  • 50 |
51 |

52 | 53 |

As of Apache Commons Compress 1.3 support for the dump format is 54 | read-only.

55 | 56 | 57 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/utils/IOUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.utils; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | import java.io.OutputStream; 24 | 25 | /** 26 | * Utility functions 27 | * @Immutable 28 | */ 29 | public final class IOUtils { 30 | 31 | /** Private constructor to prevent instantiation of this utility class. */ 32 | private IOUtils(){ 33 | } 34 | 35 | /** 36 | * Copies the content of a InputStream into an OutputStream. 37 | * Uses a default buffer size of 8024 bytes. 38 | * 39 | * @param input 40 | * the InputStream to copy 41 | * @param output 42 | * the target Stream 43 | * @throws IOException 44 | * if an error occurs 45 | */ 46 | public static long copy(final InputStream input, final OutputStream output) throws IOException { 47 | return copy(input, output, 8024); 48 | } 49 | 50 | /** 51 | * Copies the content of a InputStream into an OutputStream 52 | * 53 | * @param input 54 | * the InputStream to copy 55 | * @param output 56 | * the target Stream 57 | * @param buffersize 58 | * the buffer size to use 59 | * @throws IOException 60 | * if an error occurs 61 | */ 62 | public static long copy(final InputStream input, final OutputStream output, int buffersize) throws IOException { 63 | final byte[] buffer = new byte[buffersize]; 64 | int n = 0; 65 | long count=0; 66 | while (-1 != (n = input.read(buffer))) { 67 | output.write(buffer, 0, n); 68 | count += n; 69 | } 70 | return count; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/site/xdoc/conventions.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | Conventions 21 | 22 | 23 | 24 |
25 |

26 | The developers of this component decided to follow the recommended standards 27 | but not to include Checkstyle (or similar tools) into Commons Compress. 28 |

29 |
30 |
31 |

32 | Commons Compress does not aim to be threadsafe at the moment. But the developers 33 | agreed to document multithreading behaviour in the javadocs. 34 |

35 |

36 | We use some of the annotations from 37 | JCIP 38 | as JavaDoc tags. The used tags are: 39 | 40 |

    41 |
  • @GuardedBy (field or method)
  • 42 |
  • @Immutable (class)
  • 43 |
  • @NotThreadSafe (class)
  • 44 |
  • @ThreadSafe (class)
  • 45 |
46 | 47 | For example: 48 | 49 | /** 50 | * Utility class that represents a four byte integer with conversion 51 | * rules for the big endian byte order of ZIP files. 52 | * 53 | * @Immutable 54 | */ 55 | public final class ZipLong implements Cloneable { 56 | 57 | 58 | and: 59 | 60 | 61 | private final char [] highChars; 62 | //@GuardedBy("this") 63 | private Simple8BitZipEncoding encoding; 64 | 65 |

66 |
67 | 68 | 69 |
70 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/Lister.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers; 20 | 21 | import java.io.BufferedInputStream; 22 | import java.io.File; 23 | import java.io.FileInputStream; 24 | import java.io.InputStream; 25 | 26 | /** 27 | * Simple command line application that lists the contents of an archive. 28 | * 29 | *

The name of the archive must be given as a command line argument.

30 | *

The optional second argument defines the archive type, in case the format is not recognised.

31 | * 32 | * @since 1.1 33 | */ 34 | public final class Lister { 35 | private static final ArchiveStreamFactory factory = new ArchiveStreamFactory(); 36 | 37 | public static void main(String[] args) throws Exception { 38 | if (args.length == 0) { 39 | usage(); 40 | return; 41 | } 42 | System.out.println("Analysing "+args[0]); 43 | File f = new File(args[0]); 44 | if (!f.isFile()) { 45 | System.err.println(f + " doesn't exist or is a directory"); 46 | } 47 | InputStream fis = new BufferedInputStream(new FileInputStream(f)); 48 | ArchiveInputStream ais; 49 | if (args.length > 1) { 50 | ais = factory.createArchiveInputStream(args[1], fis); 51 | } else { 52 | ais = factory.createArchiveInputStream(fis); 53 | } 54 | System.out.println("Created "+ais.toString()); 55 | ArchiveEntry ae; 56 | while((ae=ais.getNextEntry()) != null){ 57 | System.out.println(ae.getName()); 58 | } 59 | ais.close(); 60 | fis.close(); 61 | } 62 | 63 | private static void usage() { 64 | System.out.println("Parameters: archive-name [archive-type]"); 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /src/test/resources/longpath/minotaur.cpio: -------------------------------------------------------------------------------- 1 | 0707077777771502240407750032710032710000030000001137125042400001600000000000compress-test0707077777771502250407750032710032710000030000001137125043100002300000000000compress-test/dir10707077777771536250407750032710032710000030000001137125043600003000000000000compress-test/dir1/dir20707077777771664760407750032710032710000030000001137125044100003500000000000compress-test/dir1/dir2/dir30707077777771725040407750032710032710000030000001137125044500004200000000000compress-test/dir1/dir2/dir3/dir40707077777771734130407750032710032710000030000001137125045100004700000000000compress-test/dir1/dir2/dir3/dir4/dir50707077777771734160407750032710032710000030000001137125045500005400000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir60707077777771734520407750032710032710000030000001137125046200006100000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir70707077777771734550407750032710032710000030000001137125047100006600000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir80707077777771735160407750032710032710000030000001137125051200007300000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir90707077777771735210407750032710032710000020000001137125064200010100000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir100707077777771735361006640032710032710000010000001137125060300013600000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file12345678901234567890.txt0707077777771735641006640032710032710000010000001137125064200022000000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file1234567890123456789012345678901234567890123456789012345678901234567890.txt0707077777771735541006640032710032710000010000001137125063300020600000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file123456789012345678901234567890123456789012345678901234567890.txt0707077777771735261006640032710032710000010000001137125054100011200000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file.txt0707077777771735461006640032710032710000010000001137125061100015000000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file123456789012345678901234567890.txt0707077777771735331006640032710032710000010000001137125056200012400000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file1234567890.txt0707077777771735471006640032710032710000010000001137125061700016200000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file1234567890123456789012345678901234567890.txt0707077777771735511006640032710032710000010000001137125062400017400000000000compress-test/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/file12345678901234567890123456789012345678901234567890.txt0707070000000000000000000000000000000000010000000000000000000001300000000000TRAILER!!! -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/DetectCompressorTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress; 20 | 21 | import java.io.BufferedInputStream; 22 | import java.io.File; 23 | import java.io.FileInputStream; 24 | import java.io.FileNotFoundException; 25 | import java.net.URL; 26 | 27 | import junit.framework.TestCase; 28 | 29 | import org.apache.commons.compress.compressors.CompressorException; 30 | import org.apache.commons.compress.compressors.CompressorInputStream; 31 | import org.apache.commons.compress.compressors.CompressorStreamFactory; 32 | import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; 33 | import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; 34 | 35 | public final class DetectCompressorTestCase extends TestCase { 36 | 37 | public DetectCompressorTestCase(String name) { 38 | super(name); 39 | } 40 | 41 | final ClassLoader classLoader = getClass().getClassLoader(); 42 | final CompressorStreamFactory factory = new CompressorStreamFactory(); 43 | 44 | public void testDetection() throws Exception { 45 | 46 | final CompressorInputStream bzip2 = getStreamFor("bla.txt.bz2"); 47 | assertNotNull(bzip2); 48 | assertTrue(bzip2 instanceof BZip2CompressorInputStream); 49 | 50 | final CompressorInputStream gzip = getStreamFor("bla.tgz"); 51 | assertNotNull(gzip); 52 | assertTrue(gzip instanceof GzipCompressorInputStream); 53 | 54 | } 55 | 56 | private CompressorInputStream getStreamFor(String resource) 57 | throws CompressorException, FileNotFoundException { 58 | 59 | final URL rsc = classLoader.getResource(resource); 60 | assertNotNull("Could not find resource "+resource,rsc); 61 | return factory.createCompressorInputStream( 62 | new BufferedInputStream(new FileInputStream( 63 | new File(rsc.getFile())))); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.cpio; 20 | 21 | import java.io.File; 22 | import java.io.FileInputStream; 23 | import java.io.FileOutputStream; 24 | import java.io.InputStream; 25 | 26 | import org.apache.commons.compress.AbstractTestCase; 27 | import org.apache.commons.compress.utils.IOUtils; 28 | 29 | public class CpioArchiveOutputStreamTest extends AbstractTestCase { 30 | 31 | public void testWriteOldBinary() throws Exception { 32 | final File f = getFile("test1.xml"); 33 | final File output = new File(dir, "test.cpio"); 34 | final FileOutputStream out = new FileOutputStream(output); 35 | InputStream in = null; 36 | try { 37 | final CpioArchiveOutputStream os = 38 | new CpioArchiveOutputStream(out, CpioConstants 39 | .FORMAT_OLD_BINARY); 40 | os.putArchiveEntry(new CpioArchiveEntry(CpioConstants 41 | .FORMAT_OLD_BINARY, 42 | f, "test1.xml")); 43 | IOUtils.copy(in = new FileInputStream(f), os); 44 | in.close(); 45 | in = null; 46 | os.closeArchiveEntry(); 47 | os.close(); 48 | } finally { 49 | if (in != null) { 50 | in.close(); 51 | } 52 | out.close(); 53 | } 54 | 55 | try { 56 | in = new CpioArchiveInputStream(new FileInputStream(output)); 57 | CpioArchiveEntry e = ((CpioArchiveInputStream) in) 58 | .getNextCPIOEntry(); 59 | assertEquals("test1.xml", e.getName()); 60 | assertNull(((CpioArchiveInputStream) in).getNextEntry()); 61 | } finally { 62 | if (in != null) { 63 | in.close(); 64 | } 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.dump; 20 | 21 | /** 22 | * Various constants associated with dump archives. 23 | */ 24 | public final class DumpArchiveConstants { 25 | public static final int TP_SIZE = 1024; 26 | public static final int NTREC = 10; 27 | public static final int HIGH_DENSITY_NTREC = 32; 28 | public static final int OFS_MAGIC = 60011; 29 | public static final int NFS_MAGIC = 60012; 30 | public static final int FS_UFS2_MAGIC = 0x19540119; 31 | public static final int CHECKSUM = 84446; 32 | public static final int LBLSIZE = 16; 33 | public static final int NAMELEN = 64; 34 | 35 | /* do not instantiate */ 36 | private DumpArchiveConstants() { 37 | } 38 | 39 | /** 40 | * The type of tape segment. 41 | */ 42 | public enum SEGMENT_TYPE { 43 | TAPE(1), 44 | INODE(2), 45 | BITS(3), 46 | ADDR(4), 47 | END(5), 48 | CLRI(6); 49 | 50 | int code; 51 | 52 | private SEGMENT_TYPE(int code) { 53 | this.code = code; 54 | } 55 | 56 | public static SEGMENT_TYPE find(int code) { 57 | for (SEGMENT_TYPE t : values()) { 58 | if (t.code == code) { 59 | return t; 60 | } 61 | } 62 | 63 | return null; 64 | } 65 | } 66 | 67 | /** 68 | * The type of compression. 69 | */ 70 | public enum COMPRESSION_TYPE { 71 | ZLIB(0), 72 | BZLIB(1), 73 | LZO(2); 74 | 75 | int code; 76 | 77 | private COMPRESSION_TYPE(int code) { 78 | this.code = code; 79 | } 80 | 81 | public static COMPRESSION_TYPE find(int code) { 82 | for (COMPRESSION_TYPE t : values()) { 83 | if (t.code == code) { 84 | return t; 85 | } 86 | } 87 | 88 | return null; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.jar; 20 | 21 | import java.io.File; 22 | import java.io.FileOutputStream; 23 | import java.io.IOException; 24 | 25 | import junit.framework.TestCase; 26 | 27 | import org.apache.commons.compress.AbstractTestCase; 28 | import org.apache.commons.compress.archivers.zip.JarMarker; 29 | import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; 30 | import org.apache.commons.compress.archivers.zip.ZipExtraField; 31 | import org.apache.commons.compress.archivers.zip.ZipFile; 32 | 33 | public class JarArchiveOutputStreamTest extends TestCase { 34 | 35 | public void testJarMarker() throws IOException { 36 | File testArchive = File.createTempFile("jar-aostest", ".jar"); 37 | testArchive.deleteOnExit(); 38 | JarArchiveOutputStream out = null; 39 | ZipFile zf = null; 40 | try { 41 | 42 | out = new JarArchiveOutputStream(new FileOutputStream(testArchive)); 43 | out.putArchiveEntry(new ZipArchiveEntry("foo/")); 44 | out.closeArchiveEntry(); 45 | out.putArchiveEntry(new ZipArchiveEntry("bar/")); 46 | out.closeArchiveEntry(); 47 | out.finish(); 48 | out.close(); 49 | out = null; 50 | 51 | zf = new ZipFile(testArchive); 52 | ZipArchiveEntry ze = zf.getEntry("foo/"); 53 | assertNotNull(ze); 54 | ZipExtraField[] fes = ze.getExtraFields(); 55 | assertEquals(1, fes.length); 56 | assertTrue(fes[0] instanceof JarMarker); 57 | 58 | ze = zf.getEntry("bar/"); 59 | assertNotNull(ze); 60 | fes = ze.getExtraFields(); 61 | assertEquals(0, fes.length); 62 | } finally { 63 | if (out != null) { 64 | try { 65 | out.close(); 66 | } catch (IOException e) { /* swallow */ } 67 | } 68 | ZipFile.closeQuietly(zf); 69 | AbstractTestCase.tryHardToDelete(testArchive); 70 | } 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/utils/CountingStreamTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.utils; 20 | 21 | import static org.junit.Assert.assertArrayEquals; 22 | import static org.junit.Assert.assertEquals; 23 | 24 | import java.io.ByteArrayInputStream; 25 | import java.io.ByteArrayOutputStream; 26 | 27 | import org.junit.Test; 28 | 29 | public class CountingStreamTest { 30 | 31 | @Test 32 | public void output() throws Exception { 33 | // I don't like "test all at once" tests either, but the class 34 | // is so trivial 35 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 36 | CountingOutputStream o = new CountingOutputStream(bos); 37 | o.write(1); 38 | assertEquals(1, o.getBytesWritten()); 39 | o.write(new byte[] { 2, 3 }); 40 | assertEquals(3, o.getBytesWritten()); 41 | o.write(new byte[] { 2, 3, 4, 5, }, 2, 1); 42 | assertEquals(4, o.getBytesWritten()); 43 | o.count(-1); 44 | assertEquals(4, o.getBytesWritten()); 45 | o.count(-2); 46 | assertEquals(2, o.getBytesWritten()); 47 | o.close(); 48 | assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bos.toByteArray()); 49 | } 50 | 51 | @Test 52 | public void input() throws Exception { 53 | // I don't like "test all at once" tests either, but the class 54 | // is so trivial 55 | ByteArrayInputStream bis = 56 | new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }); 57 | CountingInputStream i = new CountingInputStream(bis); 58 | assertEquals(1, i.read()); 59 | assertEquals(1, i.getBytesRead()); 60 | byte[] b = new byte[2]; 61 | i.read(b); 62 | assertEquals(3, i.getBytesRead()); 63 | assertArrayEquals(new byte[] { 2, 3 }, b); 64 | b = new byte[3]; 65 | i.read(b, 1, 1); 66 | assertArrayEquals(new byte[] { 0, 4, 0 }, b); 67 | assertEquals(4, i.getBytesRead()); 68 | i.count(-1); 69 | assertEquals(4, i.getBytesRead()); 70 | i.count(-2); 71 | assertEquals(2, i.getBytesRead()); 72 | i.close(); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress; 20 | 21 | import org.apache.commons.compress.utils.ArchiveUtils; 22 | 23 | public class ArchiveUtilsTest extends AbstractTestCase { 24 | 25 | private static final int bytesToTest = 50; 26 | private static final byte[] byteTest = new byte[bytesToTest]; 27 | static { 28 | for(int i=0; i < byteTest.length ;) { 29 | byteTest[i]=(byte) i; 30 | byteTest[i+1]=(byte) -i; 31 | i += 2; 32 | } 33 | } 34 | public void testCompareBA(){ 35 | byte[] buffer1 = {1,2,3}; 36 | byte[] buffer2 = {1,2,3,0}; 37 | byte[] buffer3 = {1,2,3}; 38 | assertTrue(ArchiveUtils.isEqual(buffer1, buffer2, true)); 39 | assertFalse(ArchiveUtils.isEqual(buffer1, buffer2, false)); 40 | assertFalse(ArchiveUtils.isEqual(buffer1, buffer2)); 41 | assertTrue(ArchiveUtils.isEqual(buffer2, buffer1, true)); 42 | assertFalse(ArchiveUtils.isEqual(buffer2, buffer1, false)); 43 | assertFalse(ArchiveUtils.isEqual(buffer2, buffer1)); 44 | assertTrue(ArchiveUtils.isEqual(buffer1, buffer3)); 45 | assertTrue(ArchiveUtils.isEqual(buffer3, buffer1)); 46 | } 47 | 48 | public void testCompareAscii(){ 49 | byte[] buffer1 = {'a','b','c'}; 50 | byte[] buffer2 = {'d','e','f',0}; 51 | assertTrue(ArchiveUtils.matchAsciiBuffer("abc", buffer1)); 52 | assertFalse(ArchiveUtils.matchAsciiBuffer("abc\0", buffer1)); 53 | assertTrue(ArchiveUtils.matchAsciiBuffer("def\0", buffer2)); 54 | assertFalse(ArchiveUtils.matchAsciiBuffer("def", buffer2)); 55 | } 56 | 57 | public void testAsciiConversions() { 58 | asciiToByteAndBackOK(""); 59 | asciiToByteAndBackOK("abcd"); 60 | asciiToByteAndBackFail("\u8025"); 61 | } 62 | 63 | private void asciiToByteAndBackOK(String inputString) { 64 | assertEquals(inputString, ArchiveUtils.toAsciiString(ArchiveUtils.toAsciiBytes(inputString))); 65 | } 66 | 67 | private void asciiToByteAndBackFail(String inputString) { 68 | assertFalse(inputString.equals(ArchiveUtils.toAsciiString(ArchiveUtils.toAsciiBytes(inputString)))); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/zip/UnicodePathExtraField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.zip; 20 | 21 | /** 22 | * Info-ZIP Unicode Path Extra Field (0x7075): 23 | * 24 | *

Stores the UTF-8 version of the file name field as stored in the 25 | * local header and central directory header.

26 | * 27 | *
28 |  *         Value         Size        Description
29 |  *         -----         ----        -----------
30 |  * (UPath) 0x7075        Short       tag for this extra block type ("up")
31 |  *         TSize         Short       total data size for this block
32 |  *         Version       1 byte      version of this extra field, currently 1
33 |  *         NameCRC32     4 bytes     File Name Field CRC32 Checksum
34 |  *         UnicodeName   Variable    UTF-8 version of the entry File Name
35 |  * 
36 | * @NotThreadSafe super-class is not thread-safe 37 | */ 38 | public class UnicodePathExtraField extends AbstractUnicodeExtraField { 39 | 40 | public static final ZipShort UPATH_ID = new ZipShort(0x7075); 41 | 42 | public UnicodePathExtraField () { 43 | } 44 | 45 | /** 46 | * Assemble as unicode path extension from the name given as 47 | * text as well as the encoded bytes actually written to the archive. 48 | * 49 | * @param text The file name 50 | * @param bytes the bytes actually written to the archive 51 | * @param off The offset of the encoded filename in bytes. 52 | * @param len The length of the encoded filename or comment in 53 | * bytes. 54 | */ 55 | public UnicodePathExtraField(String text, byte[] bytes, int off, int len) { 56 | super(text, bytes, off, len); 57 | } 58 | 59 | /** 60 | * Assemble as unicode path extension from the name given as 61 | * text as well as the encoded bytes actually written to the archive. 62 | * 63 | * @param name The file name 64 | * @param bytes the bytes actually written to the archive 65 | */ 66 | public UnicodePathExtraField(String name, byte[] bytes) { 67 | super(name, bytes); 68 | } 69 | 70 | /** {@inheritDoc} */ 71 | public ZipShort getHeaderId() { 72 | return UPATH_ID; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/zip/ZipShortTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.zip; 20 | 21 | import junit.framework.TestCase; 22 | 23 | /** 24 | * JUnit 3 testcases for org.apache.commons.compress.archivers.zip.ZipShort. 25 | * 26 | */ 27 | public class ZipShortTest extends TestCase { 28 | 29 | public ZipShortTest(String name) { 30 | super(name); 31 | } 32 | 33 | /** 34 | * Test conversion to bytes. 35 | */ 36 | public void testToBytes() { 37 | ZipShort zs = new ZipShort(0x1234); 38 | byte[] result = zs.getBytes(); 39 | assertEquals("length getBytes", 2, result.length); 40 | assertEquals("first byte getBytes", 0x34, result[0]); 41 | assertEquals("second byte getBytes", 0x12, result[1]); 42 | } 43 | 44 | /** 45 | * Test conversion from bytes. 46 | */ 47 | public void testFromBytes() { 48 | byte[] val = new byte[] {0x34, 0x12}; 49 | ZipShort zs = new ZipShort(val); 50 | assertEquals("value from bytes", 0x1234, zs.getValue()); 51 | } 52 | 53 | /** 54 | * Test the contract of the equals method. 55 | */ 56 | public void testEquals() { 57 | ZipShort zs = new ZipShort(0x1234); 58 | ZipShort zs2 = new ZipShort(0x1234); 59 | ZipShort zs3 = new ZipShort(0x5678); 60 | 61 | assertTrue("reflexive", zs.equals(zs)); 62 | 63 | assertTrue("works", zs.equals(zs2)); 64 | assertTrue("works, part two", !zs.equals(zs3)); 65 | 66 | assertTrue("symmetric", zs2.equals(zs)); 67 | 68 | assertTrue("null handling", !zs.equals(null)); 69 | assertTrue("non ZipShort handling", !zs.equals(new Integer(0x1234))); 70 | } 71 | 72 | /** 73 | * Test sign handling. 74 | */ 75 | public void testSign() { 76 | ZipShort zs = new ZipShort(new byte[] {(byte)0xFF, (byte)0xFF}); 77 | assertEquals(0x0000FFFF, zs.getValue()); 78 | } 79 | 80 | public void testClone() { 81 | ZipShort s1 = new ZipShort(42); 82 | ZipShort s2 = (ZipShort) s1.clone(); 83 | assertNotSame(s1, s2); 84 | assertEquals(s1, s2); 85 | assertEquals(s1.getValue(), s2.getValue()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/compressors/XZUtilsTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.compressors; 20 | 21 | import junit.framework.TestCase; 22 | 23 | import org.apache.commons.compress.compressors.xz.XZUtils; 24 | 25 | public class XZUtilsTestCase extends TestCase { 26 | 27 | public void testIsCompressedFilename() { 28 | assertFalse(XZUtils.isCompressedFilename("")); 29 | assertFalse(XZUtils.isCompressedFilename(".xz")); 30 | 31 | assertTrue(XZUtils.isCompressedFilename("x.txz")); 32 | assertTrue(XZUtils.isCompressedFilename("x.xz")); 33 | assertTrue(XZUtils.isCompressedFilename("x-xz")); 34 | 35 | assertFalse(XZUtils.isCompressedFilename("xxgz")); 36 | assertFalse(XZUtils.isCompressedFilename("xzz")); 37 | assertFalse(XZUtils.isCompressedFilename("xaz")); 38 | 39 | assertFalse(XZUtils.isCompressedFilename("x.txz ")); 40 | assertFalse(XZUtils.isCompressedFilename("x.txz\n")); 41 | assertFalse(XZUtils.isCompressedFilename("x.txz.y")); 42 | } 43 | 44 | public void testGetUncompressedFilename() { 45 | assertEquals("", XZUtils.getUncompressedFilename("")); 46 | assertEquals(".xz", XZUtils.getUncompressedFilename(".xz")); 47 | 48 | assertEquals("x.tar", XZUtils.getUncompressedFilename("x.txz")); 49 | assertEquals("x", XZUtils.getUncompressedFilename("x.xz")); 50 | assertEquals("x", XZUtils.getUncompressedFilename("x-xz")); 51 | 52 | assertEquals("x.txz ", XZUtils.getUncompressedFilename("x.txz ")); 53 | assertEquals("x.txz\n", XZUtils.getUncompressedFilename("x.txz\n")); 54 | assertEquals("x.txz.y", XZUtils.getUncompressedFilename("x.txz.y")); 55 | } 56 | 57 | public void testGetCompressedFilename() { 58 | assertEquals(".xz", XZUtils.getCompressedFilename("")); 59 | assertEquals("x.xz", XZUtils.getCompressedFilename("x")); 60 | 61 | assertEquals("x.txz", XZUtils.getCompressedFilename("x.tar")); 62 | 63 | assertEquals("x.wmf .xz", XZUtils.getCompressedFilename("x.wmf ")); 64 | assertEquals("x.wmf\n.xz", XZUtils.getCompressedFilename("x.wmf\n")); 65 | assertEquals("x.wmf.y.xz", XZUtils.getCompressedFilename("x.wmf.y")); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/zip/UnicodeCommentExtraField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.zip; 20 | 21 | /** 22 | * Info-ZIP Unicode Comment Extra Field (0x6375): 23 | * 24 | *

Stores the UTF-8 version of the file comment as stored in the 25 | * central directory header.

26 | * 27 | *
28 |  *         Value         Size        Description
29 |  *         -----         ----        -----------
30 |  *  (UCom) 0x6375        Short       tag for this extra block type ("uc")
31 |  *         TSize         Short       total data size for this block
32 |  *         Version       1 byte      version of this extra field, currently 1
33 |  *         ComCRC32      4 bytes     Comment Field CRC32 Checksum
34 |  *         UnicodeCom    Variable    UTF-8 version of the entry comment
35 |  * 
36 | * @NotThreadSafe super-class is not thread-safe 37 | */ 38 | public class UnicodeCommentExtraField extends AbstractUnicodeExtraField { 39 | 40 | public static final ZipShort UCOM_ID = new ZipShort(0x6375); 41 | 42 | public UnicodeCommentExtraField () { 43 | } 44 | 45 | /** 46 | * Assemble as unicode comment extension from the name given as 47 | * text as well as the encoded bytes actually written to the archive. 48 | * 49 | * @param text The file name 50 | * @param bytes the bytes actually written to the archive 51 | * @param off The offset of the encoded comment in bytes. 52 | * @param len The length of the encoded comment or comment in 53 | * bytes. 54 | */ 55 | public UnicodeCommentExtraField(String text, byte[] bytes, int off, 56 | int len) { 57 | super(text, bytes, off, len); 58 | } 59 | 60 | /** 61 | * Assemble as unicode comment extension from the comment given as 62 | * text as well as the bytes actually written to the archive. 63 | * 64 | * @param comment The file comment 65 | * @param bytes the bytes actually written to the archive 66 | */ 67 | public UnicodeCommentExtraField(String comment, byte[] bytes) { 68 | super(comment, bytes); 69 | } 70 | 71 | /** {@inheritDoc} */ 72 | public ZipShort getHeaderId() { 73 | return UCOM_ID; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.tar; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | import static org.junit.Assert.assertNotNull; 23 | import static org.junit.Assert.assertNull; 24 | 25 | import java.util.Random; 26 | 27 | import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; 28 | import org.junit.Test; 29 | 30 | public class BigFilesIT { 31 | 32 | @Test 33 | public void readFileBiggerThan8GByteStar() throws Exception { 34 | readFileBiggerThan8GByte("/8.star.tar.gz"); 35 | } 36 | 37 | @Test 38 | public void readFileBiggerThan8GBytePosix() throws Exception { 39 | readFileBiggerThan8GByte("/8.posix.tar.gz"); 40 | } 41 | 42 | private void readFileBiggerThan8GByte(String name) throws Exception { 43 | GzipCompressorInputStream in = null; 44 | TarArchiveInputStream tin = null; 45 | try { 46 | in = 47 | new GzipCompressorInputStream(BigFilesIT.class 48 | .getResourceAsStream(name)); 49 | tin = new TarArchiveInputStream(in); 50 | TarArchiveEntry e = tin.getNextTarEntry(); 51 | assertNotNull(e); 52 | assertEquals(8200l * 1024 * 1024, e.getSize()); 53 | 54 | long read = 0; 55 | Random r = new Random(System.currentTimeMillis()); 56 | int readNow; 57 | byte[] buf = new byte[1024 * 1024]; 58 | while ((readNow = tin.read(buf, 0, buf.length)) > 0) { 59 | // testing all bytes for a value of 0 is going to take 60 | // too long, just pick a few ones randomly 61 | for (int i = 0; i < 100; i++) { 62 | int idx = r.nextInt(readNow); 63 | assertEquals("testing byte " + (read + idx), 0, buf[idx]); 64 | } 65 | read += readNow; 66 | } 67 | assertEquals(8200l * 1024 * 1024, read); 68 | assertNull(tin.getNextTarEntry()); 69 | } finally { 70 | if (tin != null) { 71 | tin.close(); 72 | } 73 | if (in != null) { 74 | in.close(); 75 | } 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.zip; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | import static org.junit.Assert.assertTrue; 23 | 24 | import java.io.BufferedInputStream; 25 | import java.io.File; 26 | import java.io.FileInputStream; 27 | import java.net.URI; 28 | import java.net.URL; 29 | 30 | import org.junit.Ignore; 31 | import org.junit.Test; 32 | 33 | public class ZipArchiveInputStreamTest { 34 | 35 | /** 36 | * @see "https://issues.apache.org/jira/browse/COMPRESS-176" 37 | */ 38 | @Test 39 | public void winzipBackSlashWorkaround() throws Exception { 40 | URL zip = getClass().getResource("/test-winzip.zip"); 41 | ZipArchiveInputStream in = null; 42 | try { 43 | in = new ZipArchiveInputStream(new FileInputStream(new File(new URI(zip.toString())))); 44 | ZipArchiveEntry zae = in.getNextZipEntry(); 45 | zae = in.getNextZipEntry(); 46 | zae = in.getNextZipEntry(); 47 | assertEquals("\u00e4/", zae.getName()); 48 | } finally { 49 | if (in != null) { 50 | in.close(); 51 | } 52 | } 53 | } 54 | 55 | /** 56 | * @see "https://issues.apache.org/jira/browse/COMPRESS-189" 57 | */ 58 | @Test 59 | @Ignore 60 | public void properUseOfInflater() throws Exception { 61 | URL zip = getClass().getResource("/COMPRESS-189.zip"); 62 | ZipFile zf = null; 63 | ZipArchiveInputStream in = null; 64 | try { 65 | zf = new ZipFile(new File(new URI(zip.toString()))); 66 | ZipArchiveEntry zae = zf.getEntry("USD0558682-20080101.ZIP"); 67 | in = new ZipArchiveInputStream(new BufferedInputStream(zf.getInputStream(zae))); 68 | ZipArchiveEntry innerEntry; 69 | while ((innerEntry = in.getNextZipEntry()) != null) { 70 | if (innerEntry.getName().endsWith("XML")) { 71 | assertTrue(0 < in.read()); 72 | } 73 | } 74 | } finally { 75 | if (zf != null) { 76 | zf.close(); 77 | } 78 | if (in != null) { 79 | in.close(); 80 | } 81 | } 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/changes/Change.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.changes; 20 | 21 | import java.io.InputStream; 22 | 23 | import org.apache.commons.compress.archivers.ArchiveEntry; 24 | 25 | /** 26 | * Change holds meta information about a change. 27 | * 28 | * @Immutable 29 | */ 30 | class Change { 31 | private final String targetFile; // entry name to delete 32 | private final ArchiveEntry entry; // new entry to add 33 | private final InputStream input; // source for new entry 34 | private final boolean replaceMode; // change should replaceMode existing entries 35 | 36 | // Type of change 37 | private final int type; 38 | // Possible type values 39 | static final int TYPE_DELETE = 1; 40 | static final int TYPE_ADD = 2; 41 | static final int TYPE_MOVE = 3; // NOT USED 42 | static final int TYPE_DELETE_DIR = 4; 43 | 44 | /** 45 | * Constructor. Takes the filename of the file to be deleted 46 | * from the stream as argument. 47 | * @param pFilename the filename of the file to delete 48 | */ 49 | Change(final String pFilename, int type) { 50 | if(pFilename == null) { 51 | throw new NullPointerException(); 52 | } 53 | this.targetFile = pFilename; 54 | this.type = type; 55 | this.input = null; 56 | this.entry = null; 57 | this.replaceMode = true; 58 | } 59 | 60 | /** 61 | * Construct a change which adds an entry. 62 | * 63 | * @param pEntry the entry details 64 | * @param pInput the InputStream for the entry data 65 | */ 66 | Change(final ArchiveEntry pEntry, final InputStream pInput, boolean replace) { 67 | if(pEntry == null || pInput == null) { 68 | throw new NullPointerException(); 69 | } 70 | this.entry = pEntry; 71 | this.input = pInput; 72 | type = TYPE_ADD; 73 | targetFile = null; 74 | this.replaceMode = replace; 75 | } 76 | 77 | ArchiveEntry getEntry() { 78 | return entry; 79 | } 80 | 81 | InputStream getInput() { 82 | return input; 83 | } 84 | 85 | String targetFile() { 86 | return targetFile; 87 | } 88 | 89 | int type() { 90 | return type; 91 | } 92 | 93 | boolean isReplaceMode() { 94 | return replaceMode; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.zip; 20 | 21 | import junit.framework.TestCase; 22 | 23 | /** 24 | * JUnit 3 testcases for org.apache.commons.compress.archivers.zip.ZipLong. 25 | * 26 | */ 27 | public class ZipLongTest extends TestCase { 28 | 29 | public ZipLongTest(String name) { 30 | super(name); 31 | } 32 | 33 | /** 34 | * Test conversion to bytes. 35 | */ 36 | public void testToBytes() { 37 | ZipLong zl = new ZipLong(0x12345678); 38 | byte[] result = zl.getBytes(); 39 | assertEquals("length getBytes", 4, result.length); 40 | assertEquals("first byte getBytes", 0x78, result[0]); 41 | assertEquals("second byte getBytes", 0x56, result[1]); 42 | assertEquals("third byte getBytes", 0x34, result[2]); 43 | assertEquals("fourth byte getBytes", 0x12, result[3]); 44 | } 45 | 46 | /** 47 | * Test conversion from bytes. 48 | */ 49 | public void testFromBytes() { 50 | byte[] val = new byte[] {0x78, 0x56, 0x34, 0x12}; 51 | ZipLong zl = new ZipLong(val); 52 | assertEquals("value from bytes", 0x12345678, zl.getValue()); 53 | } 54 | 55 | /** 56 | * Test the contract of the equals method. 57 | */ 58 | public void testEquals() { 59 | ZipLong zl = new ZipLong(0x12345678); 60 | ZipLong zl2 = new ZipLong(0x12345678); 61 | ZipLong zl3 = new ZipLong(0x87654321); 62 | 63 | assertTrue("reflexive", zl.equals(zl)); 64 | 65 | assertTrue("works", zl.equals(zl2)); 66 | assertTrue("works, part two", !zl.equals(zl3)); 67 | 68 | assertTrue("symmetric", zl2.equals(zl)); 69 | 70 | assertTrue("null handling", !zl.equals(null)); 71 | assertTrue("non ZipLong handling", !zl.equals(new Integer(0x1234))); 72 | } 73 | 74 | /** 75 | * Test sign handling. 76 | */ 77 | public void testSign() { 78 | ZipLong zl = new ZipLong(new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF}); 79 | assertEquals(0x00000000FFFFFFFFl, zl.getValue()); 80 | } 81 | 82 | public void testClone() { 83 | ZipLong s1 = new ZipLong(42); 84 | ZipLong s2 = (ZipLong) s1.clone(); 85 | assertNotSame(s1, s2); 86 | assertEquals(s1, s2); 87 | assertEquals(s1.getValue(), s2.getValue()); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.ar; 20 | 21 | import java.io.ByteArrayOutputStream; 22 | import java.io.File; 23 | import java.io.FileOutputStream; 24 | import java.io.IOException; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | import org.apache.commons.compress.AbstractTestCase; 29 | 30 | public class ArArchiveOutputStreamTest extends AbstractTestCase { 31 | 32 | public void testLongFileNamesCauseExceptionByDefault() { 33 | ArArchiveOutputStream os = null; 34 | try { 35 | os = new ArArchiveOutputStream(new ByteArrayOutputStream()); 36 | ArArchiveEntry ae = new ArArchiveEntry("this_is_a_long_name.txt", 37 | 0); 38 | os.putArchiveEntry(ae); 39 | fail("Expected an exception"); 40 | } catch (IOException ex) { 41 | assertTrue(ex.getMessage().startsWith("filename too long")); 42 | } finally { 43 | closeQuietly(os); 44 | } 45 | } 46 | 47 | public void testLongFileNamesWorkUsingBSDDialect() throws Exception { 48 | FileOutputStream fos = null; 49 | ArArchiveOutputStream os = null; 50 | File[] df = createTempDirAndFile(); 51 | try { 52 | fos = new FileOutputStream(df[1]); 53 | os = new ArArchiveOutputStream(fos); 54 | os.setLongFileMode(ArArchiveOutputStream.LONGFILE_BSD); 55 | ArArchiveEntry ae = new ArArchiveEntry("this_is_a_long_name.txt", 56 | 14); 57 | os.putArchiveEntry(ae); 58 | os.write(new byte[] { 59 | 'H', 'e', 'l', 'l', 'o', ',', ' ', 60 | 'w', 'o', 'r', 'l', 'd', '!', '\n' 61 | }); 62 | os.closeArchiveEntry(); 63 | os.close(); 64 | os = null; 65 | fos = null; 66 | 67 | List expected = new ArrayList(); 68 | expected.add("this_is_a_long_name.txt"); 69 | checkArchiveContent(df[1], expected); 70 | } finally { 71 | if (os != null) { 72 | os.close(); 73 | } 74 | if (fos != null) { 75 | fos.close(); 76 | } 77 | rmdir(df[0]); 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.zip; 20 | 21 | import java.util.Calendar; 22 | import java.util.Date; 23 | 24 | import junit.framework.TestCase; 25 | 26 | public class ZipUtilTest extends TestCase { 27 | 28 | private Date time; 29 | private ZipLong zl; 30 | 31 | /** 32 | * Constructor 33 | */ 34 | public ZipUtilTest(String name) { 35 | super(name); 36 | } 37 | 38 | @Override 39 | protected void setUp() throws Exception { 40 | time = new Date(); 41 | Calendar cal = Calendar.getInstance(); 42 | cal.setTime(time); 43 | int year = cal.get(Calendar.YEAR); 44 | int month = cal.get(Calendar.MONTH) + 1; 45 | long value = ((year - 1980) << 25) 46 | | (month << 21) 47 | | (cal.get(Calendar.DAY_OF_MONTH) << 16) 48 | | (cal.get(Calendar.HOUR_OF_DAY) << 11) 49 | | (cal.get(Calendar.MINUTE) << 5) 50 | | (cal.get(Calendar.SECOND) >> 1); 51 | 52 | byte[] result = new byte[4]; 53 | result[0] = (byte) ((value & 0xFF)); 54 | result[1] = (byte) ((value & 0xFF00) >> 8); 55 | result[2] = (byte) ((value & 0xFF0000) >> 16); 56 | result[3] = (byte) ((value & 0xFF000000L) >> 24); 57 | zl = new ZipLong(result); 58 | } 59 | 60 | @Override 61 | protected void tearDown() throws Exception { 62 | super.tearDown(); 63 | } 64 | 65 | public void testZipLong() throws Exception { 66 | ZipLong test = ZipUtil.toDosTime(time); 67 | assertEquals(test.getValue(), zl.getValue()); 68 | } 69 | 70 | public void testAdjustToLong() { 71 | assertEquals(Integer.MAX_VALUE, 72 | ZipUtil.adjustToLong(Integer.MAX_VALUE)); 73 | assertEquals(((long) Integer.MAX_VALUE) + 1, 74 | ZipUtil.adjustToLong(Integer.MAX_VALUE + 1)); 75 | assertEquals(2 * ((long) Integer.MAX_VALUE), 76 | ZipUtil.adjustToLong(2 * Integer.MAX_VALUE)); 77 | } 78 | 79 | public void testMinTime(){ 80 | byte[] b1 = ZipUtil.toDosTime(0); 81 | byte b10 = b1[0]; // Save the first byte 82 | b1[0]++; // change it 83 | byte[] b2 = ZipUtil.toDosTime(0); // get the same time 84 | assertEquals(b10,b2[0]); // first byte should still be the same 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/ExceptionMessageTest.java: -------------------------------------------------------------------------------- 1 | package org.apache.commons.compress.archivers; 2 | 3 | import junit.framework.Assert; 4 | import junit.framework.TestCase; 5 | 6 | /* 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | public class ExceptionMessageTest extends TestCase { 25 | 26 | private static final String ARCHIVER_NULL_MESSAGE = "Archivername must not be null."; 27 | 28 | private static final String INPUTSTREAM_NULL_MESSAGE = "InputStream must not be null."; 29 | 30 | private static final String OUTPUTSTREAM_NULL_MESSAGE = "OutputStream must not be null."; 31 | 32 | 33 | public void testMessageWhenArchiverNameIsNull_1(){ 34 | try{ 35 | new ArchiveStreamFactory().createArchiveInputStream(null, System.in); 36 | fail("Should raise an IllegalArgumentException."); 37 | }catch (IllegalArgumentException e) { 38 | Assert.assertEquals(ARCHIVER_NULL_MESSAGE, e.getMessage()); 39 | } catch (ArchiveException e) { 40 | fail("ArchiveException not expected"); 41 | } 42 | } 43 | 44 | public void testMessageWhenInputStreamIsNull(){ 45 | try{ 46 | new ArchiveStreamFactory().createArchiveInputStream("zip", null); 47 | fail("Should raise an IllegalArgumentException."); 48 | }catch (IllegalArgumentException e) { 49 | Assert.assertEquals(INPUTSTREAM_NULL_MESSAGE, e.getMessage()); 50 | } catch (ArchiveException e) { 51 | fail("ArchiveException not expected"); 52 | } 53 | } 54 | 55 | public void testMessageWhenArchiverNameIsNull_2(){ 56 | try{ 57 | new ArchiveStreamFactory().createArchiveOutputStream(null, System.out); 58 | fail("Should raise an IllegalArgumentException."); 59 | } catch (IllegalArgumentException e) { 60 | Assert.assertEquals(ARCHIVER_NULL_MESSAGE, e.getMessage()); 61 | } catch (ArchiveException e){ 62 | fail("ArchiveException not expected"); 63 | } 64 | } 65 | 66 | public void testMessageWhenOutputStreamIsNull(){ 67 | try{ 68 | new ArchiveStreamFactory().createArchiveOutputStream("zip", null); 69 | fail("Should raise an IllegalArgumentException."); 70 | } catch (IllegalArgumentException e) { 71 | Assert.assertEquals(OUTPUTSTREAM_NULL_MESSAGE, e.getMessage()); 72 | } catch (ArchiveException e) { 73 | fail("ArchiveException not expected"); 74 | } 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/zip/ZipExtraField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.archivers.zip; 20 | 21 | import java.util.zip.ZipException; 22 | 23 | /** 24 | * General format of extra field data. 25 | * 26 | *

Extra fields usually appear twice per file, once in the local 27 | * file data and once in the central directory. Usually they are the 28 | * same, but they don't have to be. {@link 29 | * java.util.zip.ZipOutputStream java.util.zip.ZipOutputStream} will 30 | * only use the local file data in both places.

31 | * 32 | */ 33 | public interface ZipExtraField { 34 | /** 35 | * The Header-ID. 36 | * 37 | * @return The HeaderId value 38 | */ 39 | ZipShort getHeaderId(); 40 | 41 | /** 42 | * Length of the extra field in the local file data - without 43 | * Header-ID or length specifier. 44 | * @return the length of the field in the local file data 45 | */ 46 | ZipShort getLocalFileDataLength(); 47 | 48 | /** 49 | * Length of the extra field in the central directory - without 50 | * Header-ID or length specifier. 51 | * @return the length of the field in the central directory 52 | */ 53 | ZipShort getCentralDirectoryLength(); 54 | 55 | /** 56 | * The actual data to put into local file data - without Header-ID 57 | * or length specifier. 58 | * @return the data 59 | */ 60 | byte[] getLocalFileDataData(); 61 | 62 | /** 63 | * The actual data to put into central directory - without Header-ID or 64 | * length specifier. 65 | * @return the data 66 | */ 67 | byte[] getCentralDirectoryData(); 68 | 69 | /** 70 | * Populate data from this array as if it was in local file data. 71 | * 72 | * @param buffer the buffer to read data from 73 | * @param offset offset into buffer to read data 74 | * @param length the length of data 75 | * @exception ZipException on error 76 | */ 77 | void parseFromLocalFileData(byte[] buffer, int offset, int length) 78 | throws ZipException; 79 | 80 | /** 81 | * Populate data from this array as if it was in central directory data. 82 | * 83 | * @param buffer the buffer to read data from 84 | * @param offset offset into buffer to read data 85 | * @param length the length of data 86 | * @exception ZipException on error 87 | */ 88 | void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) 89 | throws ZipException; 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/changes/ChangeSetResults.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.compress.changes; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | /** 25 | * Stores the results of an performed ChangeSet operation. 26 | */ 27 | public class ChangeSetResults { 28 | private final List addedFromChangeSet = new ArrayList(); 29 | private final List addedFromStream = new ArrayList(); 30 | private final List deleted = new ArrayList(); 31 | 32 | /** 33 | * Adds the filename of a recently deleted file to the result list. 34 | * @param fileName the file which has been deleted 35 | */ 36 | void deleted(String fileName) { 37 | deleted.add(fileName); 38 | } 39 | 40 | /** 41 | * Adds the name of a file to the result list which has been 42 | * copied from the source stream to the target stream. 43 | * @param fileName the file name which has been added from the original stream 44 | */ 45 | void addedFromStream(String fileName) { 46 | addedFromStream.add(fileName); 47 | } 48 | 49 | /** 50 | * Adds the name of a file to the result list which has been 51 | * copied from the changeset to the target stream 52 | * @param fileName the name of the file 53 | */ 54 | void addedFromChangeSet(String fileName) { 55 | addedFromChangeSet.add(fileName); 56 | } 57 | 58 | /** 59 | * Returns a list of filenames which has been added from the changeset 60 | * @return the list of filenames 61 | */ 62 | public List getAddedFromChangeSet() { 63 | return addedFromChangeSet; 64 | } 65 | 66 | /** 67 | * Returns a list of filenames which has been added from the original stream 68 | * @return the list of filenames 69 | */ 70 | public List getAddedFromStream() { 71 | return addedFromStream; 72 | } 73 | 74 | /** 75 | * Returns a list of filenames which has been deleted 76 | * @return the list of filenames 77 | */ 78 | public List getDeleted() { 79 | return deleted; 80 | } 81 | 82 | /** 83 | * Checks if an filename already has been added to the result list 84 | * @param filename the filename to check 85 | * @return true, if this filename already has been added 86 | */ 87 | boolean hasBeenAdded(String filename) { 88 | if(addedFromChangeSet.contains(filename) || addedFromStream.contains(filename)) { 89 | return true; 90 | } 91 | return false; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/compress/archivers/zip/FallbackZipEncoding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.compress.archivers.zip; 21 | 22 | import java.io.IOException; 23 | import java.nio.ByteBuffer; 24 | 25 | /** 26 | * A fallback ZipEncoding, which uses a java.io means to encode names. 27 | * 28 | *

This implementation is not suitable for encodings other than 29 | * utf-8, because java.io encodes unmappable character as question 30 | * marks leading to unreadable ZIP entries on some operating 31 | * systems.

32 | * 33 | *

Furthermore this implementation is unable to tell whether a 34 | * given name can be safely encoded or not.

35 | * 36 | *

This implementation acts as a last resort implementation, when 37 | * neither {@link Simple8BitZipEnoding} nor {@link NioZipEncoding} is 38 | * available.

39 | * 40 | *

The methods of this class are reentrant.

41 | * @Immutable 42 | */ 43 | class FallbackZipEncoding implements ZipEncoding { 44 | private final String charset; 45 | 46 | /** 47 | * Construct a fallback zip encoding, which uses the platform's 48 | * default charset. 49 | */ 50 | public FallbackZipEncoding() { 51 | this.charset = null; 52 | } 53 | 54 | /** 55 | * Construct a fallback zip encoding, which uses the given charset. 56 | * 57 | * @param charset The name of the charset or {@code null} for 58 | * the platform's default character set. 59 | */ 60 | public FallbackZipEncoding(String charset) { 61 | this.charset = charset; 62 | } 63 | 64 | /** 65 | * @see 66 | * org.apache.commons.compress.archivers.zip.ZipEncoding#canEncode(java.lang.String) 67 | */ 68 | public boolean canEncode(String name) { 69 | return true; 70 | } 71 | 72 | /** 73 | * @see 74 | * org.apache.commons.compress.archivers.zip.ZipEncoding#encode(java.lang.String) 75 | */ 76 | public ByteBuffer encode(String name) throws IOException { 77 | if (this.charset == null) { // i.e. use default charset, see no-args constructor 78 | return ByteBuffer.wrap(name.getBytes()); 79 | } else { 80 | return ByteBuffer.wrap(name.getBytes(this.charset)); 81 | } 82 | } 83 | 84 | /** 85 | * @see 86 | * org.apache.commons.compress.archivers.zip.ZipEncoding#decode(byte[]) 87 | */ 88 | public String decode(byte[] data) throws IOException { 89 | if (this.charset == null) { // i.e. use default charset, see no-args constructor 90 | return new String(data); 91 | } else { 92 | return new String(data,this.charset); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package org.apache.commons.compress.archivers.zip; 20 | 21 | import java.io.File; 22 | import java.io.FileInputStream; 23 | import java.io.IOException; 24 | import java.net.URI; 25 | import java.net.URISyntaxException; 26 | import java.net.URL; 27 | 28 | import junit.framework.TestCase; 29 | 30 | public class EncryptedArchiveTest extends TestCase { 31 | 32 | public void testReadPasswordEncryptedEntryViaZipFile() 33 | throws IOException, URISyntaxException { 34 | URL zip = getClass().getResource("/password-encrypted.zip"); 35 | File file = new File(new URI(zip.toString())); 36 | ZipFile zf = null; 37 | try { 38 | zf = new ZipFile(file); 39 | ZipArchiveEntry zae = zf.getEntry("LICENSE.txt"); 40 | assertTrue(zae.getGeneralPurposeBit().usesEncryption()); 41 | assertFalse(zae.getGeneralPurposeBit().usesStrongEncryption()); 42 | assertFalse(zf.canReadEntryData(zae)); 43 | try { 44 | zf.getInputStream(zae); 45 | fail("expected an exception"); 46 | } catch (UnsupportedZipFeatureException ex) { 47 | assertSame(UnsupportedZipFeatureException.Feature.ENCRYPTION, 48 | ex.getFeature()); 49 | } 50 | } finally { 51 | ZipFile.closeQuietly(zf); 52 | } 53 | } 54 | 55 | public void testReadPasswordEncryptedEntryViaStream() 56 | throws IOException, URISyntaxException { 57 | URL zip = getClass().getResource("/password-encrypted.zip"); 58 | File file = new File(new URI(zip.toString())); 59 | ZipArchiveInputStream zin = null; 60 | try { 61 | zin = new ZipArchiveInputStream(new FileInputStream(file)); 62 | ZipArchiveEntry zae = zin.getNextZipEntry(); 63 | assertEquals("LICENSE.txt", zae.getName()); 64 | assertTrue(zae.getGeneralPurposeBit().usesEncryption()); 65 | assertFalse(zae.getGeneralPurposeBit().usesStrongEncryption()); 66 | assertFalse(zin.canReadEntryData(zae)); 67 | try { 68 | byte[] buf = new byte[1024]; 69 | zin.read(buf, 0, buf.length); 70 | fail("expected an exception"); 71 | } catch (UnsupportedZipFeatureException ex) { 72 | assertSame(UnsupportedZipFeatureException.Feature.ENCRYPTION, 73 | ex.getFeature()); 74 | } 75 | } finally { 76 | if (zin != null) { 77 | zin.close(); 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /doap_compress.rdf: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | Apache Commons Compress 21 | 22 | Java 23 | 24 | 25 | 26 | 27 | 28 | Commons Compress 29 | Commons Compress: working with zip, ar, jar, bz2, cpio, tar, gz, dump, pack200 and xz files. 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | commons-compress 39 | 2012-05-23 40 | 1.4.1 41 | 42 | 43 | 44 | 45 | commons-compress 46 | 2012-04-11 47 | 1.4 48 | 49 | 50 | 51 | 52 | commons-compress 53 | 2011-11-01 54 | 1.3 55 | 56 | 57 | 58 | 59 | commons-compress 60 | 2011-07-31 61 | 1.2 62 | 63 | 64 | 65 | 66 | commons-compress 67 | 2010-08-13 68 | 1.1 69 | 70 | 71 | 72 | 73 | commons-compress 74 | 2009-05-21 75 | 1.0 76 | 77 | 78 | 79 | 80 | 81 | --------------------------------------------------------------------------------