Contains utilities used internally by the compress library.
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/site/resources/download_compress.cgi:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # Licensed to the Apache Software Foundation (ASF) under one or more
4 | # contributor license agreements. See the NOTICE file distributed with
5 | # this work for additional information regarding copyright ownership.
6 | # The ASF licenses this file to You under the Apache License, Version 2.0
7 | # (the "License"); you may not use this file except in compliance with
8 | # 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, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 |
18 | # Just call the standard mirrors.cgi script. It will use download.html
19 | # as the input template.
20 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $*
21 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/parallel/package.html:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
Provides common API classes for parallel compression features.
Provides stream classes for decompressing
22 | streams using the "compress" algorithm used to write .Z files.
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/archivers/sevenz/StartHeader.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.sevenz;
19 |
20 | class StartHeader {
21 | long nextHeaderOffset;
22 | long nextHeaderSize;
23 | long nextHeaderCrc;
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/archivers/sevenz/Coder.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.sevenz;
19 |
20 | class Coder {
21 | byte[] decompressionMethodId;
22 | long numInStreams;
23 | long numOutStreams;
24 | byte[] properties = null;
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/archivers/sevenz/BindPair.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.sevenz;
19 |
20 | class BindPair {
21 | long inIndex;
22 | long outIndex;
23 |
24 | @Override
25 | public String toString() {
26 | return "BindPair binding input " + inIndex + " to output " + outIndex;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/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/sevenz/SubStreamsInfo.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.sevenz;
19 |
20 | import java.util.BitSet;
21 |
22 | /// Properties for non-empty files.
23 | class SubStreamsInfo {
24 | /// Unpacked size of each unpacked stream.
25 | long[] unpackSizes;
26 | /// Whether CRC is present for each unpacked stream.
27 | BitSet hasCrc;
28 | /// CRCs of unpacked streams, if present.
29 | long[] crcs;
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/parallel/ScatterGatherBackingStoreSupplier.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.parallel;
20 |
21 | import java.io.IOException;
22 |
23 | /**
24 | * Supplies {@link ScatterGatherBackingStore} instances.
25 | *
26 | * @since 1.10
27 | */
28 | public interface ScatterGatherBackingStoreSupplier {
29 | /**
30 | * Create a ScatterGatherBackingStore.
31 | *
32 | * @return a ScatterGatherBackingStore, not null
33 | */
34 | ScatterGatherBackingStore get() throws IOException;
35 | }
36 |
--------------------------------------------------------------------------------
/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.
Provides stream classes for compressing and decompressing
22 | streams using the XZ algorithm.
23 |
24 |
The classes in this package are wrappers around {@link
25 | org.tukaani.xz.XZInputStream org.tukaani.xz.XZInputStream} and
26 | {@link org.tukaani.xz.XZOutputStream
27 | org.tukaani.xz.XZOutputStream} provided by the public
28 | domain XZ for Java
29 | library.
30 |
31 |
32 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/compressors/lzma/package.html:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
Provides a stream class decompressing streams using the
22 | "stand-alone" LZMA algorithm.
23 |
24 |
The class in this package is a wrapper around {@link
25 | org.tukaani.xz.LZMAInputStream org.tukaani.xz.LZMAInputStream}
26 | and provided by the public
27 | domain XZ for Java
28 | library.
29 |
30 |
In general you should prefer the more modern and robust XZ
31 | format over stand-alone LZMA compression.
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryPredicate.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 | * A predicate to test if a #ZipArchiveEntry matches a criteria.
23 | * Some day this can extend java.util.function.Predicate
24 | *
25 | * @since 1.10
26 | */
27 | public interface ZipArchiveEntryPredicate {
28 | /**
29 | * Indicate if the given entry should be included in the operation
30 | * @param zipArchiveEntry the entry to test
31 | * @return true if the entry should be included
32 | */
33 | boolean test(ZipArchiveEntry zipArchiveEntry);
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/parallel/InputStreamSupplier.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.parallel;
21 |
22 | import java.io.InputStream;
23 |
24 | /**
25 | * Supplies input streams.
26 | *
27 | * Implementations are required to support thread-handover. While an instance will
28 | * not be accessed concurrently by multiple threads, it will be called by
29 | * a different thread than it was created on.
30 | *
31 | * @since 1.10
32 | */
33 | public interface InputStreamSupplier {
34 |
35 | /**
36 | * Supply an input stream for a resource.
37 | * @return the input stream. Should never null, but may be an empty stream.
38 | */
39 | InputStream get();
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/resources/archives/SunOS_odc.cpio:
--------------------------------------------------------------------------------
1 | 07070700000000000110064400505600000100000117777711163465216000002000000000331 abcdefghijklmnopqrstuvwxyz
2 | 070707000000000002100644005056000001000001177777111635162140000030000000003312 abcdefghijklmnopqrstuvwxyz
3 | 0707070000000000031006440050560000010000011777771116351622100000400000000033123 abcdefghijklmnopqrstuvwxyz
4 | 07070700000000000410064400505600000100000117777711163516233000005000000000331234 abcdefghijklmnopqrstuvwxyz
5 | 070707000000000005100644005056000001000001177777111635162350000060000000003312345 abcdefghijklmnopqrstuvwxyz
6 | 0707070000000000061006440050560000010000011777771116351641100000700000000033123450 abcdefghijklmnopqrstuvwxyz
7 | 0707070000000000071006440050560000010000011777771116351676400000700000000032123456 bcdefghijklmnopqrstuvwxyz
8 | 0707070000000000101006440050560000010000011777771116351703400000700000000031123457 cdefghijklmnopqrstuvwxyz
9 | 0707070000000000111006440050560000010000011777771116351704600000700000000030123458 defghijklmnopqrstuvwxyz
10 | 0707070000000000121006440050560000010000011777771116351705700000700000000027123459 efghijklmnopqrstuvwxyz
11 | 0707070000000000000000000000000000000000010000000000000000000001300000000000TRAILER!!!
--------------------------------------------------------------------------------
/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 | initCause(cause);
39 | }
40 |
41 | public DumpArchiveException(String msg, Throwable cause) {
42 | super(msg);
43 | initCause(cause);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/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/test/java/org/apache/commons/compress/compressors/xz/XZCompressorInputStreamTest.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.xz;
20 |
21 | import org.junit.Assert;
22 | import org.junit.Test;
23 |
24 | public class XZCompressorInputStreamTest {
25 | @Test
26 | public void redundantTestOfAlmostDeprecatedMatchesMethod() {
27 | byte[] data = {
28 | (byte) 0xFD, '7', 'z', 'X', 'Z', '\0'
29 | };
30 | Assert.assertFalse(XZCompressorInputStream.matches(data, 5));
31 | Assert.assertTrue(XZCompressorInputStream.matches(data, 6));
32 | Assert.assertTrue(XZCompressorInputStream.matches(data, 7));
33 | data[5] = '0';
34 | Assert.assertFalse(XZCompressorInputStream.matches(data, 6));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/PasswordRequiredException.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;
19 |
20 | import java.io.IOException;
21 |
22 | /**
23 | * Exception thrown when trying to read an encrypted entry or file without
24 | * configuring a password.
25 | * @since 1.10
26 | */
27 | public class PasswordRequiredException extends IOException {
28 |
29 | private static final long serialVersionUID = 1391070005491684483L;
30 |
31 | /**
32 | * Create a new exception.
33 | *
34 | * @param name name of the archive containing encrypted streams or
35 | * the encrypted file.
36 | */
37 | public PasswordRequiredException(String name) {
38 | super("Cannot read encrypted content from " + name + " without a password.");
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorOutputStreamTest.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.deflate;
20 |
21 | import org.junit.Assert;
22 | import org.junit.Test;
23 |
24 | import java.io.ByteArrayOutputStream;
25 | import java.io.IOException;
26 |
27 | public class DeflateCompressorOutputStreamTest {
28 |
29 | @Test
30 | public void canReadASingleByteFlushAndFinish() throws IOException {
31 | ByteArrayOutputStream bos = new ByteArrayOutputStream();
32 | DeflateCompressorOutputStream cos = new DeflateCompressorOutputStream(bos);
33 | cos.write(99);
34 | cos.flush();
35 | cos.finish();
36 | Assert.assertTrue(bos.toByteArray().length > 0);
37 | cos.close();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/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/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.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.sevenz;
19 |
20 | import org.junit.Test;
21 |
22 | public class SevenZArchiveEntryTest {
23 |
24 | @Test(expected=UnsupportedOperationException.class)
25 | public void shouldThrowIfNoLastModifiedDateIsSet() {
26 | new SevenZArchiveEntry().getLastModifiedDate();
27 | }
28 |
29 | @Test(expected=UnsupportedOperationException.class)
30 | public void shouldThrowIfNoCreationDateIsSet() {
31 | new SevenZArchiveEntry().getCreationDate();
32 | }
33 |
34 | @Test(expected=UnsupportedOperationException.class)
35 | public void shouldThrowIfNoAccessDateIsSet() {
36 | new SevenZArchiveEntry().getAccessDate();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/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 | @Override
38 | InputStream getInputView() throws IOException {
39 | return new ByteArrayInputStream(((ByteArrayOutputStream) out)
40 | .toByteArray());
41 | }
42 | }
--------------------------------------------------------------------------------
/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 | LICENSE.txt
28 | NOTICE.txt
29 | README.txt
30 | RELEASE-NOTES.txt
31 | pom.xml
32 | findbugs-exclude-filter.xml
33 | pmd-ruleset.xml
34 |
35 |
36 |
37 | src
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/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 | public Date getLastModifiedDate() {
48 | return new Date();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/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.
Provides stream classes for decompressing streams using the
22 | Snappy
23 | algorithm.
24 |
25 |
The raw Snappy format which only contains the compressed data
26 | is supported by the SnappyCompressorInputStream
27 | class while the so called "framing format" is implemented
28 | by FramedSnappyCompressorInputStream. Note there
29 | have been different versions of the fraing format specification,
30 | the implementation in Commons Compress is based on the
31 | specification "Last revised: 2013-10-25".
32 |
33 |
Only the "framing format" can be auto-detected this means you
34 | have to speficy the format explicitly if you want to read a
35 | "raw" Snappy stream
36 | via CompressorStreamFactory.
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateParametersTest.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.deflate;
20 |
21 | import org.junit.Assert;
22 | import org.junit.Test;
23 |
24 | public class DeflateParametersTest {
25 |
26 | @Test
27 | public void shouldBeAbleToSetCompressionLevel() {
28 | DeflateParameters p = new DeflateParameters();
29 | p.setCompressionLevel(5);
30 | Assert.assertEquals(5, p.getCompressionLevel());
31 | }
32 |
33 | @Test(expected = IllegalArgumentException.class)
34 | public void shouldNotBeAbleToSetCompressionLevelToANegativeValue() {
35 | DeflateParameters p = new DeflateParameters();
36 | p.setCompressionLevel(-2);
37 | }
38 |
39 | @Test(expected = IllegalArgumentException.class)
40 | public void shouldNotBeAbleToSetCompressionLevelToADoubleDigitValue() {
41 | DeflateParameters p = new DeflateParameters();
42 | p.setCompressionLevel(12);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/archivers/sevenz/StreamMap.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.sevenz;
19 |
20 | /// Map between folders, files and streams.
21 | class StreamMap {
22 | /// The first Archive.packStream index of each folder.
23 | int[] folderFirstPackStreamIndex;
24 | /// Offset to beginning of this pack stream's data, relative to the beginning of the first pack stream.
25 | long[] packStreamOffsets;
26 | /// Index of first file for each folder.
27 | int[] folderFirstFileIndex;
28 | /// Index of folder for each file.
29 | int[] fileFolderIndex;
30 |
31 | @Override
32 | public String toString() {
33 | return "StreamMap with indices of " + folderFirstPackStreamIndex.length
34 | + " folders, offsets of " + packStreamOffsets.length + " packed streams,"
35 | + " first files of " + folderFirstFileIndex.length + " folders and"
36 | + " folder indices for " + fileFolderIndex.length + " files";
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/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 static org.apache.commons.compress.AbstractTestCase.getFile;
22 | import static org.junit.Assert.*;
23 | import org.junit.Test;
24 |
25 | import java.io.File;
26 | import java.io.FileInputStream;
27 |
28 |
29 | public class SparseFilesTest {
30 |
31 | @Test
32 | public void testOldGNU() throws Throwable {
33 | File file = getFile("oldgnu_sparse.tar");
34 | TarArchiveInputStream tin = null;
35 | try {
36 | tin = new TarArchiveInputStream(new FileInputStream(file));
37 | TarArchiveEntry ae = tin.getNextTarEntry();
38 | assertEquals("sparsefile", ae.getName());
39 | assertTrue(ae.isGNUSparse());
40 | assertFalse(tin.canReadEntryData(ae));
41 | } finally {
42 | if (tin != null) {
43 | tin.close();
44 | }
45 | }
46 | }
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/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/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/StreamingNotSupportedException.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 | * Exception thrown by ArchiveStreamFactory if a format is requested/detected that doesn't support streaming.
23 | *
24 | * @since 1.8
25 | */
26 | public class StreamingNotSupportedException extends ArchiveException {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 | private final String format;
31 |
32 | /**
33 | * Creates a new StreamingNotSupportedException.
34 | *
35 | * @param format the format that has been requested/detected.
36 | */
37 | public StreamingNotSupportedException(String format) {
38 | super("The " + format + " doesn't support streaming.");
39 | this.format = format;
40 | }
41 |
42 | /**
43 | * Returns the format that has been requested/detected.
44 | *
45 | * @return the format that has been requested/detected.
46 | */
47 | public String getFormat() {
48 | return format;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/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 | @Override
43 | InputStream getInputView() throws IOException {
44 | out.close();
45 | return new FileInputStream(f) {
46 | @Override
47 | public void close() throws IOException {
48 | super.close();
49 | f.delete();
50 | }
51 | };
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | Apache Commons Compress
2 | =======================
3 |
4 | Commons Compress is a Java library for working with various
5 | compression and archiving formats.
6 |
7 | For full documentation see http://commons.apache.org/proper/commons-compress/
8 |
9 | ## Apache Commons Compress was derived from various sources, including:
10 |
11 | Original BZip2 classes contributed by Keiron Liddle
12 | , Aftex Software to the Apache Ant project.
13 | They are based on a port of Julian Seward's libbzip2.
14 |
15 | Original Tar classes from contributors of the Apache Ant project.
16 |
17 | Original Zip classes from contributors of the Apache Ant project.
18 |
19 | Original CPIO classes contributed by Markus Kuss and the jRPM project
20 | (jrpm.sourceforge.net).
21 |
22 | This distribution includes cryptographic software. The country in
23 | which you currently reside may have restrictions on the import,
24 | possession, use, and/or re-export to another country, of encryption
25 | software. BEFORE using any encryption software, please check your
26 | country's laws, regulations and policies concerning the import,
27 | possession, or use, and re-export of encryption software, to see if
28 | this is permitted. See for more
29 | information.
30 |
31 | The U.S. Government Department of Commerce, Bureau of Industry and
32 | Security (BIS), has classified this software as Export Commodity
33 | Control Number (ECCN) 5D002.C.1, which includes information security
34 | software using or performing cryptographic functions with asymmetric
35 | algorithms. The form and manner of this Apache Software Foundation
36 | distribution makes it eligible for export under the License Exception
37 | ENC Technology Software Unrestricted (TSU) exception (see the BIS
38 | Export Administration Regulations, Section 740.13) for both object
39 | code and source code.
40 |
41 | The following provides more details on the included cryptographic
42 | software:
43 | * the 7zip package can read AES encrypted archives
44 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/utils/CRC32VerifyingInputStream.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.io.InputStream;
21 | import java.util.zip.CRC32;
22 |
23 | /**
24 | * A stream that verifies the CRC of the data read once the stream is
25 | * exhausted.
26 | * @NotThreadSafe
27 | * @since 1.6
28 | */
29 | public class CRC32VerifyingInputStream extends ChecksumVerifyingInputStream {
30 |
31 | /**
32 | * @param in the stream to wrap
33 | * @param size the of the stream's content
34 | * @param expectedCrc32 the expected checksum
35 | */
36 | public CRC32VerifyingInputStream(final InputStream in, final long size, final int expectedCrc32) {
37 | this(in, size, expectedCrc32 & 0xFFFFffffl);
38 | }
39 |
40 | /**
41 | * @since 1.7
42 | * @param in the stream to wrap
43 | * @param size the of the stream's content
44 | * @param expectedCrc32 the expected checksum
45 | */
46 | public CRC32VerifyingInputStream(final InputStream in, final long size, final long expectedCrc32) {
47 | super(new CRC32(), in, size, expectedCrc32);
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/compress/archivers/zip/BinaryTreeTest.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 static org.junit.Assert.*;
23 |
24 | import java.io.ByteArrayInputStream;
25 | import java.io.IOException;
26 | import java.io.InputStream;
27 |
28 | import org.junit.Test;
29 |
30 | public class BinaryTreeTest {
31 |
32 | @Test
33 | public void testDecode() throws IOException {
34 | InputStream in = new ByteArrayInputStream(new byte[] { 0x02, 0x42, 0x01, 0x13 });
35 |
36 | BinaryTree tree = BinaryTree.decode(in, 8);
37 |
38 | assertNotNull(tree);
39 |
40 | BitStream stream = new BitStream(new ByteArrayInputStream(new byte[] { (byte) 0x8D, (byte) 0xC5, (byte) 0x11, 0x00 }));
41 | assertEquals(0, tree.read(stream));
42 | assertEquals(1, tree.read(stream));
43 | assertEquals(2, tree.read(stream));
44 | assertEquals(3, tree.read(stream));
45 | assertEquals(4, tree.read(stream));
46 | assertEquals(5, tree.read(stream));
47 | assertEquals(6, tree.read(stream));
48 | assertEquals(7, tree.read(stream));
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/resources/archives/FreeBSD_crc.cpio:
--------------------------------------------------------------------------------
1 | 070702061d1a63000081b4000006b9000006b90000000149cea04d0000001b00000000000000bb00000000000000000000000200000b291 abcdefghijklmnopqrstuvwxyz
2 | 070702061d1a61000081b4000006b9000006b90000000149cea04d0000001b00000000000000bb00000000000000000000000300000b2912 abcdefghijklmnopqrstuvwxyz
3 | 070702061d1a60000081b4000006b9000006b90000000149cea04d0000001b00000000000000bb00000000000000000000000400000b29123 abcdefghijklmnopqrstuvwxyz
4 | 07070201c08024000081b4000006b9000006b90000000149cea04e0000001b00000000000000bb00000000000000000000000500000b291234 abcdefghijklmnopqrstuvwxyz
5 | 07070201c08023000081b4000006b9000006b90000000149cea04e0000001b00000000000000bb00000000000000000000000600000b2912345 abcdefghijklmnopqrstuvwxyz
6 | 070702061d1704000081a4000006b9000006b90000000149cea04e0000001b00000000000000bb00000000000000000000000700000b29123450 abcdefghijklmnopqrstuvwxyz
7 | 07070201c08022000081b4000006b9000006b90000000149cea04e0000001a00000000000000bb00000000000000000000000700000ac8123456 bcdefghijklmnopqrstuvwxyz
8 | 070702061d177b000081a4000006b9000006b90000000149cea04e0000001900000000000000bb00000000000000000000000700000a66123457 cdefghijklmnopqrstuvwxyz
9 | 070702061d177f000081a4000006b9000006b90000000149cea04e0000001800000000000000bb00000000000000000000000700000a03123458 defghijklmnopqrstuvwxyz
10 | 070702061d1783000081a4000006b9000006b90000000149cea04e0000001700000000000000bb0000000000000000000000070000099f123459 efghijklmnopqrstuvwxyz
11 | 07070200000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000b00000000TRAILER!!!
--------------------------------------------------------------------------------
/src/test/resources/archives/SunOS_-c.cpio:
--------------------------------------------------------------------------------
1 | 07070100289305000081a400000a2e000000010000000149ce6a8e0000001b000000b500010005ffffffffffffffff00000002000000001 abcdefghijklmnopqrstuvwxyz
2 | 07070100289306000081a400000a2e000000010000000149ce9c8c0000001b000000b500010005ffffffffffffffff000000030000000012 abcdefghijklmnopqrstuvwxyz
3 | 0707010058e278000081a400000a2e000000010000000149ce9c910000001b000000b500010005ffffffffffffffff0000000400000000123 abcdefghijklmnopqrstuvwxyz
4 | 0707010058f486000081a400000a2e000000010000000149ce9c9b0000001b000000b500010005ffffffffffffffff00000005000000001234 abcdefghijklmnopqrstuvwxyz
5 | 0707010058f5d4000081a400000a2e000000010000000149ce9c9d0000001b000000b500010005ffffffffffffffff000000060000000012345 abcdefghijklmnopqrstuvwxyz
6 | 070701004beba0000081a400000a2e000000010000000149ce9d090000001b000000b500010005ffffffffffffffff0000000700000000123450 abcdefghijklmnopqrstuvwxyz
7 | 0707010058f62d000081a400000a2e000000010000000149ce9df40000001a000000b500010005ffffffffffffffff0000000700000000123456 bcdefghijklmnopqrstuvwxyz
8 | 070701004beb9a000081a400000a2e000000010000000149ce9e1c00000019000000b500010005ffffffffffffffff0000000700000000123457 cdefghijklmnopqrstuvwxyz
9 | 070701004beb9d000081a400000a2e000000010000000149ce9e2600000018000000b500010005ffffffffffffffff0000000700000000123458 defghijklmnopqrstuvwxyz
10 | 070701004beb9e000081a400000a2e000000010000000149ce9e2f00000017000000b500010005ffffffffffffffff0000000700000000123459 efghijklmnopqrstuvwxyz
11 | 07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000b00000000TRAILER!!!
--------------------------------------------------------------------------------
/src/test/resources/archives/SunOS_crc.cpio:
--------------------------------------------------------------------------------
1 | 07070200289305000081a400000a2e000000010000000149ce6a8e0000001b000000b500010005ffffffffffffffff0000000200000b291 abcdefghijklmnopqrstuvwxyz
2 | 07070200289306000081a400000a2e000000010000000149ce9c8c0000001b000000b500010005ffffffffffffffff0000000300000b2912 abcdefghijklmnopqrstuvwxyz
3 | 0707020058e278000081a400000a2e000000010000000149ce9c910000001b000000b500010005ffffffffffffffff0000000400000b29123 abcdefghijklmnopqrstuvwxyz
4 | 0707020058f486000081a400000a2e000000010000000149ce9c9b0000001b000000b500010005ffffffffffffffff0000000500000b291234 abcdefghijklmnopqrstuvwxyz
5 | 0707020058f5d4000081a400000a2e000000010000000149ce9c9d0000001b000000b500010005ffffffffffffffff0000000600000b2912345 abcdefghijklmnopqrstuvwxyz
6 | 070702004beba0000081a400000a2e000000010000000149ce9d090000001b000000b500010005ffffffffffffffff0000000700000b29123450 abcdefghijklmnopqrstuvwxyz
7 | 0707020058f62d000081a400000a2e000000010000000149ce9df40000001a000000b500010005ffffffffffffffff0000000700000ac8123456 bcdefghijklmnopqrstuvwxyz
8 | 070702004beb9a000081a400000a2e000000010000000149ce9e1c00000019000000b500010005ffffffffffffffff0000000700000a66123457 cdefghijklmnopqrstuvwxyz
9 | 070702004beb9d000081a400000a2e000000010000000149ce9e2600000018000000b500010005ffffffffffffffff0000000700000a03123458 defghijklmnopqrstuvwxyz
10 | 070702004beb9e000081a400000a2e000000010000000149ce9e2f00000017000000b500010005ffffffffffffffff000000070000099f123459 efghijklmnopqrstuvwxyz
11 | 07070200000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000b00000000TRAILER!!!
--------------------------------------------------------------------------------
/src/test/resources/archives/FreeBSD_newc.cpio:
--------------------------------------------------------------------------------
1 | 070701061d1a63000081b4000006b9000006b90000000149cea04d0000001b00000000000000bb000000000000000000000002000000001 abcdefghijklmnopqrstuvwxyz
2 | 070701061d1a61000081b4000006b9000006b90000000149cea04d0000001b00000000000000bb0000000000000000000000030000000012 abcdefghijklmnopqrstuvwxyz
3 | 070701061d1a60000081b4000006b9000006b90000000149cea04d0000001b00000000000000bb00000000000000000000000400000000123 abcdefghijklmnopqrstuvwxyz
4 | 07070101c08024000081b4000006b9000006b90000000149cea04e0000001b00000000000000bb000000000000000000000005000000001234 abcdefghijklmnopqrstuvwxyz
5 | 07070101c08023000081b4000006b9000006b90000000149cea04e0000001b00000000000000bb0000000000000000000000060000000012345 abcdefghijklmnopqrstuvwxyz
6 | 070701061d1704000081a4000006b9000006b90000000149cea04e0000001b00000000000000bb00000000000000000000000700000000123450 abcdefghijklmnopqrstuvwxyz
7 | 07070101c08022000081b4000006b9000006b90000000149cea04e0000001a00000000000000bb00000000000000000000000700000000123456 bcdefghijklmnopqrstuvwxyz
8 | 070701061d177b000081a4000006b9000006b90000000149cea04e0000001900000000000000bb00000000000000000000000700000000123457 cdefghijklmnopqrstuvwxyz
9 | 070701061d177f000081a4000006b9000006b90000000149cea04e0000001800000000000000bb00000000000000000000000700000000123458 defghijklmnopqrstuvwxyz
10 | 070701061d1783000081a4000006b9000006b90000000149cea04e0000001700000000000000bb00000000000000000000000700000000123459 efghijklmnopqrstuvwxyz
11 | 07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000b00000000TRAILER!!!
--------------------------------------------------------------------------------
/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 | /**
29 | * Gets the name of the entry in this archive. May refer to a file or directory or other item.
30 | *
31 | * @return The name of this entry in the archive.
32 | */
33 | String getName();
34 |
35 | /**
36 | * Gets the uncompressed size of this entry. May be -1 (SIZE_UNKNOWN) if the size is unknown
37 | *
38 | * @return the uncompressed size of this entry.
39 | */
40 | long getSize();
41 |
42 | /** Special value indicating that the size is unknown */
43 | long SIZE_UNKNOWN = -1;
44 |
45 | /**
46 | * Returns true if this entry refers to a directory.
47 | *
48 | * @return true if this entry refers to a directory.
49 | */
50 | boolean isDirectory();
51 |
52 | /**
53 | * Gets the last modified date of this entry.
54 | *
55 | * @return the last modified date of this entry.
56 | * @since 1.1
57 | */
58 | Date getLastModifiedDate();
59 | }
60 |
--------------------------------------------------------------------------------
/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/main/java/org/apache/commons/compress/archivers/zip/ScatterStatistics.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 | * Provides information about a scatter compression run.
23 | *
24 | * @since 1.10
25 | */
26 | public class ScatterStatistics {
27 | private final long compressionElapsed;
28 | private final long mergingElapsed;
29 |
30 | ScatterStatistics(long compressionElapsed, long mergingElapsed) {
31 | this.compressionElapsed = compressionElapsed;
32 | this.mergingElapsed = mergingElapsed;
33 | }
34 |
35 | /**
36 | * The number of milliseconds elapsed in the parallel compression phase
37 | * @return The number of milliseconds elapsed
38 | */
39 | public long getCompressionElapsed() {
40 | return compressionElapsed;
41 | }
42 |
43 | /**
44 | * The number of milliseconds elapsed in merging the results of the parallel compression, the IO phase
45 | * @return The number of milliseconds elapsed
46 | */
47 | public long getMergingElapsed() {
48 | return mergingElapsed;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "compressionElapsed=" + compressionElapsed + "ms, mergingElapsed=" + mergingElapsed + "ms";
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/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 static org.junit.Assert.*;
22 |
23 | import java.io.IOException;
24 |
25 | import org.junit.Test;
26 |
27 | import org.apache.commons.compress.archivers.ArchiveEntry;
28 |
29 | public final class MemoryArchiveTestCase {
30 |
31 | @Test
32 | public void testReading() throws IOException {
33 |
34 | final MemoryArchiveInputStream is = new MemoryArchiveInputStream(new String[][] {
35 | { "test1", "content1" },
36 | { "test2", "content2" },
37 | });
38 |
39 | final ArchiveEntry entry1 = is.getNextEntry();
40 | assertNotNull(entry1);
41 | assertEquals("test1", entry1.getName());
42 | final String content1 = is.readString();
43 | assertEquals("content1", content1);
44 |
45 | final ArchiveEntry entry2 = is.getNextEntry();
46 | assertNotNull(entry2);
47 | assertEquals("test2", entry2.getName());
48 | final String content2 = is.readString();
49 | assertEquals("content2", content2);
50 |
51 | final ArchiveEntry entry3 = is.getNextEntry();
52 | assertNull(entry3);
53 |
54 | is.close();
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/archivers/zip/BitStream.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.io.InputStream;
24 | import org.apache.commons.compress.utils.BitInputStream;
25 | import java.nio.ByteOrder;
26 |
27 | /**
28 | * Iterates over the bits of an InputStream. For each byte the bits
29 | * are read from the right to the left.
30 | *
31 | * @since 1.7
32 | */
33 | class BitStream extends BitInputStream {
34 |
35 | BitStream(InputStream in) {
36 | super(in, ByteOrder.LITTLE_ENDIAN);
37 | }
38 |
39 | /**
40 | * Returns the next bit.
41 | *
42 | * @return The next bit (0 or 1) or -1 if the end of the stream has been reached
43 | */
44 | int nextBit() throws IOException {
45 | return (int) readBits(1);
46 | }
47 |
48 | /**
49 | * Returns the integer value formed by the n next bits (up to 8 bits).
50 | *
51 | * @param n the number of bits read (up to 8)
52 | * @return The value formed by the n bits, or -1 if the end of the stream has been reached
53 | */
54 | long nextBits(final int n) throws IOException {
55 | return readBits(n);
56 | }
57 |
58 | int nextByte() throws IOException {
59 | return (int) readBits(8);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/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/test/java/org/apache/commons/compress/archivers/zip/ScatterSample.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 | import org.apache.commons.compress.parallel.InputStreamSupplier;
21 |
22 | import java.io.File;
23 | import java.io.IOException;
24 | import java.util.concurrent.ExecutionException;
25 |
26 | public class ScatterSample {
27 |
28 | ParallelScatterZipCreator scatterZipCreator = new ParallelScatterZipCreator();
29 | ScatterZipOutputStream dirs = ScatterZipOutputStream.fileBased(File.createTempFile("scatter-dirs", "tmp"));
30 |
31 | public ScatterSample() throws IOException {
32 | }
33 |
34 | public void addEntry(ZipArchiveEntry zipArchiveEntry, InputStreamSupplier streamSupplier) throws IOException {
35 | if (zipArchiveEntry.isDirectory() && !zipArchiveEntry.isUnixSymlink())
36 | dirs.addArchiveEntry(ZipArchiveEntryRequest.createZipArchiveEntryRequest(zipArchiveEntry, streamSupplier));
37 | else
38 | scatterZipCreator.addArchiveEntry( zipArchiveEntry, streamSupplier);
39 | }
40 |
41 | public void writeTo(ZipArchiveOutputStream zipArchiveOutputStream)
42 | throws IOException, ExecutionException, InterruptedException {
43 | dirs.writeTo(zipArchiveOutputStream);
44 | dirs.close();
45 | scatterZipCreator.writeTo(zipArchiveOutputStream);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/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/site/site.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
23 | Commons Compress
24 | /images/compress-logo-white.png
25 | /index.html
26 |
27 |
28 |
29 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/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 | *
41 | */
42 |
43 | public class TarArchiveSparseEntry implements TarConstants {
44 | /** If an extension sparse header follows. */
45 | private final 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/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/sevenz/NID.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.sevenz;
19 |
20 | final class NID {
21 | public static final int kEnd = 0x00;
22 | public static final int kHeader = 0x01;
23 | public static final int kArchiveProperties = 0x02;
24 | public static final int kAdditionalStreamsInfo = 0x03;
25 | public static final int kMainStreamsInfo = 0x04;
26 | public static final int kFilesInfo = 0x05;
27 | public static final int kPackInfo = 0x06;
28 | public static final int kUnpackInfo = 0x07;
29 | public static final int kSubStreamsInfo = 0x08;
30 | public static final int kSize = 0x09;
31 | public static final int kCRC = 0x0A;
32 | public static final int kFolder = 0x0B;
33 | public static final int kCodersUnpackSize = 0x0C;
34 | public static final int kNumUnpackStream = 0x0D;
35 | public static final int kEmptyStream = 0x0E;
36 | public static final int kEmptyFile = 0x0F;
37 | public static final int kAnti = 0x10;
38 | public static final int kName = 0x11;
39 | public static final int kCTime = 0x12;
40 | public static final int kATime = 0x13;
41 | public static final int kMTime = 0x14;
42 | public static final int kWinAttributes = 0x15;
43 | public static final int kComment = 0x16;
44 | public static final int kEncodedHeader = 0x17;
45 | public static final int kStartPos = 0x18;
46 | public static final int kDummy = 0x19;
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/parallel/FileBasedScatterGatherBackingStore.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.parallel;
19 |
20 | import java.io.File;
21 | import java.io.FileNotFoundException;
22 | import java.io.FileInputStream;
23 | import java.io.FileOutputStream;
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 |
27 | /**
28 | * ScatterGatherBackingStore that is backed by a file.
29 | *
30 | * @since 1.10
31 | */
32 | public class FileBasedScatterGatherBackingStore implements ScatterGatherBackingStore {
33 | private final File target;
34 | private final FileOutputStream os;
35 | private boolean closed;
36 |
37 | public FileBasedScatterGatherBackingStore(File target) throws FileNotFoundException {
38 | this.target = target;
39 | os = new FileOutputStream(target);
40 | }
41 |
42 | public InputStream getInputStream() throws IOException {
43 | return new FileInputStream(target);
44 | }
45 |
46 | @SuppressWarnings("ResultOfMethodCallIgnored")
47 | public void closeForWriting() throws IOException {
48 | if (!closed) {
49 | os.close();
50 | closed = true;
51 | }
52 | }
53 |
54 | public void writeOut(byte[] data, int offset, int length) throws IOException {
55 | os.write(data, offset, length);
56 | }
57 |
58 | public void close() throws IOException {
59 | closeForWriting();
60 | target.delete();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/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 static org.junit.Assert.*;
22 |
23 | import java.io.File;
24 | import java.io.FileInputStream;
25 |
26 | import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
27 | import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
28 | import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
29 | import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
30 | import org.junit.Test;
31 |
32 |
33 | public class ChainingTestCase extends AbstractTestCase {
34 |
35 | @Test
36 | public void testTarGzip() throws Exception {
37 | File file = getFile("bla.tgz");
38 | final TarArchiveInputStream is = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(file)));
39 | final TarArchiveEntry entry = (TarArchiveEntry)is.getNextEntry();
40 | assertNotNull(entry);
41 | assertEquals("test1.xml", entry.getName());
42 | is.close();
43 | }
44 |
45 | @Test
46 | public void testTarBzip2() throws Exception {
47 | File file = getFile("bla.tar.bz2");
48 | final TarArchiveInputStream is = new TarArchiveInputStream(new BZip2CompressorInputStream(new FileInputStream(file)));
49 | final TarArchiveEntry entry = (TarArchiveEntry)is.getNextEntry();
50 | assertNotNull(entry);
51 | assertEquals("test1.xml", entry.getName());
52 | is.close();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/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 final int ino;
26 | private final int parentIno;
27 | private final int type;
28 | private final 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", ino, name);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/archivers/sevenz/BoundedRandomAccessFileInputStream.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.sevenz;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.io.RandomAccessFile;
23 |
24 | class BoundedRandomAccessFileInputStream extends InputStream {
25 | private final RandomAccessFile file;
26 | private long bytesRemaining;
27 |
28 | public BoundedRandomAccessFileInputStream(final RandomAccessFile file,
29 | final long size) {
30 | this.file = file;
31 | this.bytesRemaining = size;
32 | }
33 |
34 | @Override
35 | public int read() throws IOException {
36 | if (bytesRemaining > 0) {
37 | --bytesRemaining;
38 | return file.read();
39 | } else {
40 | return -1;
41 | }
42 | }
43 |
44 | @Override
45 | public int read(byte[] b, int off, int len) throws IOException {
46 | if (bytesRemaining == 0) {
47 | return -1;
48 | }
49 | int bytesToRead = len;
50 | if (bytesToRead > bytesRemaining) {
51 | bytesToRead = (int) bytesRemaining;
52 | }
53 | final int bytesRead = file.read(b, off, bytesToRead);
54 | if (bytesRead >= 0) {
55 | bytesRemaining -= bytesRead;
56 | }
57 | return bytesRead;
58 | }
59 |
60 | @Override
61 | public void close() {
62 | // the nested RandomAccessFile is controlled externally
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/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/main/java/org/apache/commons/compress/archivers/sevenz/Archive.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.sevenz;
19 |
20 | import java.util.BitSet;
21 |
22 | class Archive {
23 | /// Offset from beginning of file + SIGNATURE_HEADER_SIZE to packed streams.
24 | long packPos;
25 | /// Size of each packed stream.
26 | long[] packSizes;
27 | /// Whether each particular packed streams has a CRC.
28 | BitSet packCrcsDefined;
29 | /// CRCs for each packed stream, valid only if that packed stream has one.
30 | long[] packCrcs;
31 | /// Properties of solid compression blocks.
32 | Folder[] folders;
33 | /// Temporary properties for non-empty files (subsumed into the files array later).
34 | SubStreamsInfo subStreamsInfo;
35 | /// The files and directories in the archive.
36 | SevenZArchiveEntry[] files;
37 | /// Mapping between folders, files and streams.
38 | StreamMap streamMap;
39 |
40 | @Override
41 | public String toString() {
42 | return "Archive with packed streams starting at offset " + packPos
43 | + ", " + lengthOf(packSizes) + " pack sizes, " + lengthOf(packCrcs)
44 | + " CRCs, " + lengthOf(folders) + " folders, " + lengthOf(files)
45 | + " files and " + streamMap;
46 | }
47 |
48 | private static String lengthOf(long[] a) {
49 | return a == null ? "(null)" : String.valueOf(a.length);
50 | }
51 |
52 | private static String lengthOf(Object[] a) {
53 | return a == null ? "(null)" : String.valueOf(a.length);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/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/parallel/ScatterGatherBackingStore.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.parallel;
19 |
20 | import java.io.Closeable;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 |
24 | /**
25 | *
Store intermediate payload in a scatter-gather scenario.
26 | * Multiple threads write their payload to a backing store, which can
27 | * subsequently be reversed to an {@link InputStream} to be used as input in the
28 | * gather phase.
29 | *
30 | *
It is the responsibility of the allocator of an instance of this class
31 | * to close this. Closing it should clear off any allocated structures
32 | * and preferably delete files.
33 | *
34 | * @since 1.10
35 | */
36 | public interface ScatterGatherBackingStore extends Closeable {
37 |
38 | /**
39 | * An input stream that contains the scattered payload
40 | *
41 | * @return An InputStream, should be closed by the caller of this method.
42 | * @throws IOException when something fails
43 | */
44 | InputStream getInputStream() throws IOException;
45 |
46 | /**
47 | * Writes a piece of payload.
48 | *
49 | * @param data the data to write
50 | * @param offset offset inside data to start writing from
51 | * @param length the amount of data to write
52 | * @throws IOException when something fails
53 | */
54 | void writeOut(byte[] data, int offset, int length) throws IOException;
55 |
56 | /**
57 | * Closes this backing store for further writing.
58 | */
59 | void closeForWriting() throws IOException;
60 | }
61 |
--------------------------------------------------------------------------------
/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 org.junit.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/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 static org.junit.Assert.*;
22 |
23 | import java.io.BufferedInputStream;
24 | import java.io.FileInputStream;
25 |
26 | import org.apache.commons.compress.AbstractTestCase;
27 | import org.apache.commons.compress.archivers.ArchiveEntry;
28 | import org.apache.commons.compress.utils.ArchiveUtils;
29 | import org.junit.Test;
30 |
31 | public class ArArchiveInputStreamTest extends AbstractTestCase {
32 |
33 | @Test
34 | public void testReadLongNamesGNU() throws Exception {
35 | checkLongNameEntry("longfile_gnu.ar");
36 | }
37 |
38 | @Test
39 | public void testReadLongNamesBSD() throws Exception {
40 | checkLongNameEntry("longfile_bsd.ar");
41 | }
42 |
43 | private void checkLongNameEntry(String archive) throws Exception {
44 | FileInputStream fis = new FileInputStream(getFile(archive));
45 | ArArchiveInputStream s = null;
46 | try {
47 | s = new ArArchiveInputStream(new BufferedInputStream(fis));
48 | ArchiveEntry e = s.getNextEntry();
49 | assertEquals("this_is_a_long_file_name.txt", e.getName());
50 | assertEquals(14, e.getSize());
51 | byte[] hello = new byte[14];
52 | s.read(hello);
53 | assertEquals("Hello, world!\n", ArchiveUtils.toAsciiString(hello));
54 | assertNull(s.getNextEntry());
55 | } finally {
56 | if (s != null) {
57 | s.close();
58 | }
59 | fis.close();
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZMethodConfigurationTest.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.sevenz;
19 |
20 | import org.junit.Assert;
21 | import org.junit.Test;
22 | import org.tukaani.xz.LZMA2Options;
23 |
24 | public class SevenZMethodConfigurationTest {
25 |
26 | @Test
27 | public void shouldAllowNullOptions() {
28 | Assert.assertNull(new SevenZMethodConfiguration(SevenZMethod.LZMA2, null)
29 | .getOptions());
30 | }
31 |
32 | @Test
33 | public void shouldAllowLZMA2OptionsForLZMA2() {
34 | Assert.assertNotNull(new SevenZMethodConfiguration(SevenZMethod.LZMA2,
35 | new LZMA2Options())
36 | .getOptions());
37 | }
38 |
39 | @Test
40 | public void shouldAllowNumberForLZMA2() {
41 | Assert.assertNotNull(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 42)
42 | .getOptions());
43 | }
44 |
45 | @Test
46 | public void shouldAllowNumberForBzip2() {
47 | Assert.assertNotNull(new SevenZMethodConfiguration(SevenZMethod.BZIP2, 42)
48 | .getOptions());
49 | }
50 |
51 | @Test
52 | public void shouldAllowNumberForDeflate() {
53 | Assert.assertNotNull(new SevenZMethodConfiguration(SevenZMethod.DEFLATE, 42)
54 | .getOptions());
55 | }
56 |
57 | @Test(expected = IllegalArgumentException.class)
58 | public void shouldNotAllowStringOptionsForLZMA2() {
59 | new SevenZMethodConfiguration(SevenZMethod.LZMA2, "");
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/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/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 | /**
45 | * Create and instance that wraps the output stream using the provided encoding.
46 | *
47 | * @param out the output stream to wrap
48 | * @param encoding the encoding to use. Use null for the platform default.
49 | * @since 1.10
50 | */
51 | public JarArchiveOutputStream(final OutputStream out, final String encoding) {
52 | super(out);
53 | setEncoding(encoding);
54 | }
55 |
56 | // @throws ClassCastException if entry is not an instance of ZipArchiveEntry
57 | @Override
58 | public void putArchiveEntry(ArchiveEntry ze) throws IOException {
59 | if (!jarMarkerAdded) {
60 | ((ZipArchiveEntry)ze).addAsFirstExtraField(JarMarker.getInstance());
61 | jarMarkerAdded = true;
62 | }
63 | super.putArchiveEntry(ze);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/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/main/java/org/apache/commons/compress/archivers/sevenz/DeltaDecoder.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.sevenz;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.io.OutputStream;
23 | import org.tukaani.xz.DeltaOptions;
24 | import org.tukaani.xz.FinishableWrapperOutputStream;
25 | import org.tukaani.xz.UnsupportedOptionsException;
26 |
27 | class DeltaDecoder extends CoderBase {
28 | DeltaDecoder() {
29 | super(Number.class);
30 | }
31 |
32 | @Override
33 | InputStream decode(final String archiveName, final InputStream in, long uncompressedLength,
34 | final Coder coder, byte[] password) throws IOException {
35 | return new DeltaOptions(getOptionsFromCoder(coder)).getInputStream(in);
36 | }
37 |
38 | @Override
39 | OutputStream encode(final OutputStream out, final Object options) throws IOException {
40 | int distance = numberOptionOrDefault(options, 1);
41 | try {
42 | return new DeltaOptions(distance).getOutputStream(new FinishableWrapperOutputStream(out));
43 | } catch (UnsupportedOptionsException ex) {
44 | throw new IOException(ex.getMessage());
45 | }
46 | }
47 |
48 | @Override
49 | byte[] getOptionsAsProperties(Object options) {
50 | return new byte[] {
51 | (byte) (numberOptionOrDefault(options, 1) - 1)
52 | };
53 | }
54 |
55 | @Override
56 | Object getOptionsFromCoder(Coder coder, InputStream in) {
57 | return getOptionsFromCoder(coder);
58 | }
59 |
60 | private int getOptionsFromCoder(Coder coder) {
61 | if (coder.properties == null || coder.properties.length == 0) {
62 | return 1;
63 | }
64 | return (0xff & coder.properties[0]) + 1;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.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.io.IOException;
21 | import java.io.InputStream;
22 |
23 | /**
24 | * A stream that limits reading from a wrapped stream to a given number of bytes.
25 | * @NotThreadSafe
26 | * @since 1.6
27 | */
28 | public class BoundedInputStream extends InputStream {
29 | private final InputStream in;
30 | private long bytesRemaining;
31 |
32 | /**
33 | * Creates the stream that will at most read the given amount of
34 | * bytes from the given stream.
35 | * @param in the stream to read from
36 | * @param size the maximum amount of bytes to read
37 | */
38 | public BoundedInputStream(final InputStream in, final long size) {
39 | this.in = in;
40 | bytesRemaining = size;
41 | }
42 |
43 | @Override
44 | public int read() throws IOException {
45 | if (bytesRemaining > 0) {
46 | --bytesRemaining;
47 | return in.read();
48 | } else {
49 | return -1;
50 | }
51 | }
52 |
53 | @Override
54 | public int read(byte[] b, int off, int len) throws IOException {
55 | if (bytesRemaining == 0) {
56 | return -1;
57 | }
58 | int bytesToRead = len;
59 | if (bytesToRead > bytesRemaining) {
60 | bytesToRead = (int) bytesRemaining;
61 | }
62 | final int bytesRead = in.read(b, off, bytesToRead);
63 | if (bytesRead >= 0) {
64 | bytesRemaining -= bytesRead;
65 | }
66 | return bytesRead;
67 | }
68 |
69 | @Override
70 | public void close() {
71 | // there isn't anything to close in this stream and the nested
72 | // stream is controlled externally
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/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 static org.junit.Assert.*;
22 |
23 | import java.io.FileInputStream;
24 |
25 | import org.apache.commons.compress.AbstractTestCase;
26 | import org.junit.Test;
27 |
28 | public class CpioArchiveInputStreamTest extends AbstractTestCase {
29 |
30 | @Test
31 | public void testCpioUnarchive() throws Exception {
32 | StringBuilder expected = new StringBuilder();
33 | expected.append("./test1.xml\n");
34 | expected.append("./test2.xml\n");
35 | expected.append("\n");
36 |
37 |
38 | CpioArchiveInputStream in = new CpioArchiveInputStream(new FileInputStream(getFile("bla.cpio")));
39 | CpioArchiveEntry entry;
40 |
41 | StringBuilder result = new StringBuilder();
42 | while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) {
43 | result.append(entry.getName());
44 | int tmp;
45 | while ((tmp = in.read()) != -1) {
46 | result.append((char) tmp);
47 | }
48 | }
49 | in.close();
50 | assertEquals(result.toString(), expected.toString());
51 | }
52 |
53 | @Test
54 | public void testCpioUnarchiveCreatedByRedlineRpm() throws Exception {
55 | CpioArchiveInputStream in =
56 | new CpioArchiveInputStream(new FileInputStream(getFile("redline.cpio")));
57 | CpioArchiveEntry entry= null;
58 |
59 | int count = 0;
60 | while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) {
61 | count++;
62 | assertNotNull(entry);
63 | }
64 | in.close();
65 |
66 | assertEquals(count, 1);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/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 | * @see PKWARE
28 | * APPNOTE.TXT, section 4.6.9
29 | *
30 | * @NotThreadSafe super-class is not thread-safe
31 | */
32 | public class UnicodePathExtraField extends AbstractUnicodeExtraField {
33 |
34 | public static final ZipShort UPATH_ID = new ZipShort(0x7075);
35 |
36 | public UnicodePathExtraField () {
37 | }
38 |
39 | /**
40 | * Assemble as unicode path extension from the name given as
41 | * text as well as the encoded bytes actually written to the archive.
42 | *
43 | * @param text The file name
44 | * @param bytes the bytes actually written to the archive
45 | * @param off The offset of the encoded filename in bytes.
46 | * @param len The length of the encoded filename or comment in
47 | * bytes.
48 | */
49 | public UnicodePathExtraField(String text, byte[] bytes, int off, int len) {
50 | super(text, bytes, off, len);
51 | }
52 |
53 | /**
54 | * Assemble as unicode path extension from the name given as
55 | * text as well as the encoded bytes actually written to the archive.
56 | *
57 | * @param name The file name
58 | * @param bytes the bytes actually written to the archive
59 | */
60 | public UnicodePathExtraField(String name, byte[] bytes) {
61 | super(name, bytes);
62 | }
63 |
64 | public ZipShort getHeaderId() {
65 | return UPATH_ID;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/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 | * Decrements the counter of already read bytes.
52 | *
53 | * @param pushedBack the number of bytes pushed back.
54 | * @since 1.7
55 | */
56 | protected void pushedBackBytes(long pushedBack) {
57 | bytesRead -= pushedBack;
58 | }
59 |
60 | /**
61 | * Returns the current number of bytes read from this stream.
62 | * @return the number of read bytes
63 | * @deprecated this method may yield wrong results for large
64 | * archives, use #getBytesRead instead
65 | */
66 | @Deprecated
67 | public int getCount() {
68 | return (int) bytesRead;
69 | }
70 |
71 | /**
72 | * Returns the current number of bytes read from this stream.
73 | * @return the number of read bytes
74 | *
75 | * @since 1.1
76 | */
77 | public long getBytesRead() {
78 | return bytesRead;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/compress/compressors/deflate/DeflateParameters.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.deflate;
21 |
22 | import java.util.zip.Deflater;
23 |
24 | /**
25 | * Parameters for the Deflate compressor.
26 | * @since 1.9
27 | */
28 | public class DeflateParameters {
29 |
30 | private boolean zlibHeader = true;
31 | private int compressionLevel = Deflater.DEFAULT_COMPRESSION;
32 |
33 | /**
34 | * Whether or not the zlib header shall be written (when
35 | * compressing) or expected (when decompressing).
36 | */
37 | public boolean withZlibHeader() {
38 | return zlibHeader;
39 | }
40 |
41 | /**
42 | * Sets the zlib header presence parameter.
43 | *
44 | *
This affects whether or not the zlib header will be written
45 | * (when compressing) or expected (when decompressing).
46 | *
47 | * @param zlibHeader
48 | */
49 | public void setWithZlibHeader(boolean zlibHeader) {
50 | this.zlibHeader = zlibHeader;
51 | }
52 |
53 | /**
54 | * The compression level.
55 | * @see #setCompressionLevel
56 | */
57 | public int getCompressionLevel() {
58 | return compressionLevel;
59 | }
60 |
61 | /**
62 | * Sets the compression level.
63 | *
64 | * @param compressionLevel the compression level (between 0 and 9)
65 | * @see Deflater#NO_COMPRESSION
66 | * @see Deflater#BEST_SPEED
67 | * @see Deflater#DEFAULT_COMPRESSION
68 | * @see Deflater#BEST_COMPRESSION
69 | */
70 | public void setCompressionLevel(int compressionLevel) {
71 | if (compressionLevel < -1 || compressionLevel > 9) {
72 | throw new IllegalArgumentException("Invalid Deflate compression level: " + compressionLevel);
73 | }
74 | this.compressionLevel = compressionLevel;
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/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 | * @see PKWARE
28 | * APPNOTE.TXT, section 4.6.8
29 | *
30 | * @NotThreadSafe super-class is not thread-safe
31 | */
32 | public class UnicodeCommentExtraField extends AbstractUnicodeExtraField {
33 |
34 | public static final ZipShort UCOM_ID = new ZipShort(0x6375);
35 |
36 | public UnicodeCommentExtraField () {
37 | }
38 |
39 | /**
40 | * Assemble as unicode comment extension from the name given as
41 | * text as well as the encoded bytes actually written to the archive.
42 | *
43 | * @param text The file name
44 | * @param bytes the bytes actually written to the archive
45 | * @param off The offset of the encoded comment in bytes.
46 | * @param len The length of the encoded comment or comment in
47 | * bytes.
48 | */
49 | public UnicodeCommentExtraField(String text, byte[] bytes, int off,
50 | int len) {
51 | super(text, bytes, off, len);
52 | }
53 |
54 | /**
55 | * Assemble as unicode comment extension from the comment given as
56 | * text as well as the bytes actually written to the archive.
57 | *
58 | * @param comment The file comment
59 | * @param bytes the bytes actually written to the archive
60 | */
61 | public UnicodeCommentExtraField(String comment, byte[] bytes) {
62 | super(comment, bytes);
63 | }
64 |
65 | public ZipShort getHeaderId() {
66 | return UCOM_ID;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/compress/archivers/zip/StreamCompressorTest.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 | import org.junit.Test;
21 |
22 | import java.io.ByteArrayInputStream;
23 | import java.io.ByteArrayOutputStream;
24 | import java.util.zip.ZipEntry;
25 |
26 | import static org.junit.Assert.assertArrayEquals;
27 | import static org.junit.Assert.assertEquals;
28 |
29 | public class StreamCompressorTest {
30 |
31 | @Test
32 | public void storedEntries() throws Exception {
33 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
34 | StreamCompressor sc = StreamCompressor.create( baos);
35 | sc.deflate(new ByteArrayInputStream("A".getBytes()), ZipEntry.STORED);
36 | sc.deflate(new ByteArrayInputStream("BAD".getBytes()), ZipEntry.STORED);
37 | assertEquals(3, sc.getBytesRead());
38 | assertEquals(3, sc.getBytesWrittenForLastEntry());
39 | assertEquals(344750961, sc.getCrc32());
40 | sc.deflate(new ByteArrayInputStream("CAFE".getBytes()), ZipEntry.STORED);
41 | assertEquals("ABADCAFE", baos.toString());
42 | }
43 |
44 | @Test
45 | public void deflatedEntries() throws Exception {
46 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
47 | StreamCompressor sc = StreamCompressor.create( baos);
48 | sc.deflate(new ByteArrayInputStream("AAAAAABBBBBB".getBytes()), ZipEntry.DEFLATED);
49 | assertEquals(12, sc.getBytesRead());
50 | assertEquals(8, sc.getBytesWrittenForLastEntry());
51 | assertEquals(3299542, sc.getCrc32());
52 |
53 | final byte[] actuals = baos.toByteArray();
54 | byte[] expected = new byte[]{115,116,4,1,39,48,0,0};
55 | // Note that this test really asserts stuff about the java Deflater, which might be a little bit brittle
56 | assertArrayEquals(expected, actuals);
57 | }
58 | }
--------------------------------------------------------------------------------