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