001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 */ 018package org.apache.commons.compress.archivers.sevenz; 019 020import java.util.Arrays; 021 022/** 023 * The (partially) supported compression/encryption methods used in 7z archives. 024 * 025 * <p>All methods with a _FILTER suffix are used as preprocessors with 026 * the goal of creating a better compression ratio with the compressor 027 * that comes next in the chain of methods. 7z will in general only 028 * allow them to be used together with a "real" compression method but 029 * Commons Compress doesn't enforce this.</p> 030 * 031 * <p>The BCJ_ filters work on executable files for the given platform 032 * and convert relative addresses to absolute addresses in CALL 033 * instructions. This means they are only useful when applied to 034 * executables of the chosen platform.</p> 035 */ 036public enum SevenZMethod { 037 /** no compression at all */ 038 COPY(new byte[] { (byte)0x00 }), 039 /** LZMA - only supported when reading */ 040 LZMA(new byte[] { (byte)0x03, (byte)0x01, (byte)0x01 }), 041 /** LZMA2 */ 042 LZMA2(new byte[] { (byte)0x21 }), 043 /** Deflate */ 044 DEFLATE(new byte[] { (byte)0x04, (byte)0x01, (byte)0x08 }), 045 /** BZIP2 */ 046 BZIP2(new byte[] { (byte)0x04, (byte)0x02, (byte)0x02 }), 047 /** 048 * AES encryption with a key length of 256 bit using SHA256 for 049 * hashes - only supported when reading 050 */ 051 AES256SHA256(new byte[] { (byte)0x06, (byte)0xf1, (byte)0x07, (byte)0x01 }), 052 /** 053 * BCJ x86 platform version 1. 054 * @since 1.8 055 */ 056 BCJ_X86_FILTER(new byte[] { 0x03, 0x03, 0x01, 0x03 }), 057 /** 058 * BCJ PowerPC platform. 059 * @since 1.8 060 */ 061 BCJ_PPC_FILTER(new byte[] { 0x03, 0x03, 0x02, 0x05 }), 062 /** 063 * BCJ I64 platform. 064 * @since 1.8 065 */ 066 BCJ_IA64_FILTER(new byte[] { 0x03, 0x03, 0x04, 0x01 }), 067 /** 068 * BCJ ARM platform. 069 * @since 1.8 070 */ 071 BCJ_ARM_FILTER(new byte[] { 0x03, 0x03, 0x05, 0x01 }), 072 /** 073 * BCJ ARM Thumb platform. 074 * @since 1.8 075 */ 076 BCJ_ARM_THUMB_FILTER(new byte[] { 0x03, 0x03, 0x07, 0x01 }), 077 /** 078 * BCJ Sparc platform. 079 * @since 1.8 080 */ 081 BCJ_SPARC_FILTER(new byte[] { 0x03, 0x03, 0x08, 0x05 }), 082 /** 083 * Delta filter. 084 * @since 1.8 085 */ 086 DELTA_FILTER(new byte[] { 0x03 }); 087 088 private final byte[] id; 089 090 private SevenZMethod(final byte[] id) { 091 this.id = id; 092 } 093 094 byte[] getId() { 095 final byte[] copy = new byte[id.length]; 096 System.arraycopy(id, 0, copy, 0, id.length); 097 return copy; 098 } 099 100 static SevenZMethod byId(final byte[] id) { 101 for (final SevenZMethod m : SevenZMethod.class.getEnumConstants()) { 102 if (Arrays.equals(m.id, id)) { 103 return m; 104 } 105 } 106 return null; 107 } 108}