View Javadoc
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  package org.apache.commons.compress.archivers.sevenz;
18  
19  import java.util.Arrays;
20  
21  /**
22   * The (partially) supported compression/encryption methods used in 7z archives.
23   * <p>
24   * All methods with a {@code _FILTER} suffix are used as preprocessors with the goal of creating a better compression ratio with the compressor that comes next
25   * 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.
26   * </p>
27   * <p>
28   * The {@code BCJ_} filters work on executable files for the given platform and convert relative addresses to absolute addresses in CALL instructions. This
29   * means they are only useful when applied to executables of the chosen platform.
30   * </p>
31   */
32  public enum SevenZMethod {
33  
34      /** No compression at all. */
35      COPY(new byte[] { (byte) 0x00 }),
36  
37      /** LZMA - only supported when reading. */
38      LZMA(new byte[] { (byte) 0x03, (byte) 0x01, (byte) 0x01 }),
39  
40      /** LZMA2. */
41      LZMA2(new byte[] { (byte) 0x21 }),
42  
43      /** Deflate. */
44      DEFLATE(new byte[] { (byte) 0x04, (byte) 0x01, (byte) 0x08 }),
45  
46      /**
47       * Deflate64.
48       *
49       * @since 1.16
50       */
51      DEFLATE64(new byte[] { (byte) 0x04, (byte) 0x01, (byte) 0x09 }),
52  
53      /** BZIP2. */
54      BZIP2(new byte[] { (byte) 0x04, (byte) 0x02, (byte) 0x02 }),
55  
56      /**
57       * AES encryption with a key length of 256 bit using SHA256 for hashes - only supported when reading.
58       */
59      AES256SHA256(new byte[] { (byte) 0x06, (byte) 0xf1, (byte) 0x07, (byte) 0x01 }),
60  
61      /**
62       * BCJ x86 platform version 1.
63       *
64       * @since 1.8
65       */
66      BCJ_X86_FILTER(new byte[] { 0x03, 0x03, 0x01, 0x03 }),
67  
68      /**
69       * BCJ PowerPC platform.
70       *
71       * @since 1.8
72       */
73      BCJ_PPC_FILTER(new byte[] { 0x03, 0x03, 0x02, 0x05 }),
74  
75      /**
76       * BCJ I64 platform.
77       *
78       * @since 1.8
79       */
80      BCJ_IA64_FILTER(new byte[] { 0x03, 0x03, 0x04, 0x01 }),
81  
82      /**
83       * BCJ ARM platform.
84       *
85       * @since 1.8
86       */
87      BCJ_ARM_FILTER(new byte[] { 0x03, 0x03, 0x05, 0x01 }),
88  
89      /**
90       * BCJ ARM Thumb platform.
91       *
92       * @since 1.8
93       */
94      BCJ_ARM_THUMB_FILTER(new byte[] { 0x03, 0x03, 0x07, 0x01 }),
95  
96      /**
97       * BCJ Sparc platform.
98       *
99       * @since 1.8
100      */
101     BCJ_SPARC_FILTER(new byte[] { 0x03, 0x03, 0x08, 0x05 }),
102 
103     /**
104      * Delta filter.
105      *
106      * @since 1.8
107      */
108     DELTA_FILTER(new byte[] { 0x03 });
109 
110     static SevenZMethod byId(final byte[] id) {
111         for (final SevenZMethod method : SevenZMethod.class.getEnumConstants()) {
112             if (Arrays.equals(method.id, id)) {
113                 return method;
114             }
115         }
116         return null;
117     }
118 
119     private final byte[] id;
120 
121     SevenZMethod(final byte[] id) {
122         this.id = id;
123     }
124 
125     byte[] getId() {
126         return Arrays.copyOf(id, id.length);
127     }
128 }