aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethod.java
blob: 3c446cc2c1ee53c8e33652d451df16858d2a3cec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package org.apache.commons.compress.archivers.sevenz;

import java.util.Arrays;

/**
 * The (partially) supported compression/encryption methods used in 7z archives.
 *
 * <p>All methods with a _FILTER suffix are used as preprocessors with
 * the goal of creating a better compression ratio with the compressor
 * that comes next in the chain of methods.  7z will in general only
 * allow them to be used together with a "real" compression method but
 * Commons Compress doesn't enforce this.</p>
 *
 * <p>The BCJ_ filters work on executable files for the given platform
 * and convert relative addresses to absolute addresses in CALL
 * instructions.  This means they are only useful when applied to
 * executables of the chosen platform.</p>
 */
public enum SevenZMethod {
    /** no compression at all */
    COPY(new byte[] { (byte)0x00 }),
    /** LZMA - only supported when reading */
    LZMA(new byte[] { (byte)0x03, (byte)0x01, (byte)0x01 }),
    /** LZMA2 */
    LZMA2(new byte[] { (byte)0x21 }),
    /** Deflate */
    DEFLATE(new byte[] { (byte)0x04, (byte)0x01, (byte)0x08 }),
    /**
     * Deflate64
     * @since 1.16
     */
    DEFLATE64(new byte[] { (byte)0x04, (byte)0x01, (byte)0x09 }),
    /** BZIP2 */
    BZIP2(new byte[] { (byte)0x04, (byte)0x02, (byte)0x02 }),
    /**
     * AES encryption with a key length of 256 bit using SHA256 for
     * hashes - only supported when reading
     */
    AES256SHA256(new byte[] { (byte)0x06, (byte)0xf1, (byte)0x07, (byte)0x01 }),
    /**
     * BCJ x86 platform version 1.
     * @since 1.8
     */
    BCJ_X86_FILTER(new byte[] { 0x03, 0x03, 0x01, 0x03 }),
    /**
     * BCJ PowerPC platform.
     * @since 1.8
     */
    BCJ_PPC_FILTER(new byte[] { 0x03, 0x03, 0x02, 0x05 }),
    /**
     * BCJ I64 platform.
     * @since 1.8
     */
    BCJ_IA64_FILTER(new byte[] { 0x03, 0x03, 0x04, 0x01 }),
    /**
     * BCJ ARM platform.
     * @since 1.8
     */
    BCJ_ARM_FILTER(new byte[] { 0x03, 0x03, 0x05, 0x01 }),
    /**
     * BCJ ARM Thumb platform.
     * @since 1.8
     */
    BCJ_ARM_THUMB_FILTER(new byte[] { 0x03, 0x03, 0x07, 0x01 }),
    /**
     * BCJ Sparc platform.
     * @since 1.8
     */
    BCJ_SPARC_FILTER(new byte[] { 0x03, 0x03, 0x08, 0x05 }),
    /**
     * Delta filter.
     * @since 1.8
     */
    DELTA_FILTER(new byte[] { 0x03 });

    private final byte[] id;

    SevenZMethod(final byte[] id) {
        this.id = id;
    }

    byte[] getId() {
        final byte[] copy = new byte[id.length];
        System.arraycopy(id, 0, copy, 0, id.length);
        return copy;
    }

    static SevenZMethod byId(final byte[] id) {
        for (final SevenZMethod m : SevenZMethod.class.getEnumConstants()) {
            if (Arrays.equals(m.id, id)) {
                return m;
            }
        }
        return null;
    }
}