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 */
017package org.apache.commons.compress.archivers.sevenz;
018
019import java.util.Arrays;
020
021/**
022 * The (partially) supported compression/encryption methods used in 7z archives.
023 *
024 * <p>All methods with a _FILTER suffix are used as preprocessors with
025 * the goal of creating a better compression ratio with the compressor
026 * that comes next in the chain of methods.  7z will in general only
027 * allow them to be used together with a "real" compression method but
028 * Commons Compress doesn't enforce this.</p>
029 *
030 * <p>The BCJ_ filters work on executable files for the given platform
031 * and convert relative addresses to absolute addresses in CALL
032 * instructions.  This means they are only useful when applied to
033 * executables of the chosen platform.</p>
034 */
035public enum SevenZMethod {
036    /** no compression at all */
037    COPY(new byte[] { (byte)0x00 }),
038    /** LZMA - only supported when reading */
039    LZMA(new byte[] { (byte)0x03, (byte)0x01, (byte)0x01 }),
040    /** LZMA2 */
041    LZMA2(new byte[] { (byte)0x21 }),
042    /** Deflate */
043    DEFLATE(new byte[] { (byte)0x04, (byte)0x01, (byte)0x08 }),
044    /**
045     * Deflate64
046     * @since 1.16
047     */
048    DEFLATE64(new byte[] { (byte)0x04, (byte)0x01, (byte)0x09 }),
049    /** BZIP2 */
050    BZIP2(new byte[] { (byte)0x04, (byte)0x02, (byte)0x02 }),
051    /**
052     * AES encryption with a key length of 256 bit using SHA256 for
053     * hashes - only supported when reading
054     */
055    AES256SHA256(new byte[] { (byte)0x06, (byte)0xf1, (byte)0x07, (byte)0x01 }),
056    /**
057     * BCJ x86 platform version 1.
058     * @since 1.8
059     */
060    BCJ_X86_FILTER(new byte[] { 0x03, 0x03, 0x01, 0x03 }),
061    /**
062     * BCJ PowerPC platform.
063     * @since 1.8
064     */
065    BCJ_PPC_FILTER(new byte[] { 0x03, 0x03, 0x02, 0x05 }),
066    /**
067     * BCJ I64 platform.
068     * @since 1.8
069     */
070    BCJ_IA64_FILTER(new byte[] { 0x03, 0x03, 0x04, 0x01 }),
071    /**
072     * BCJ ARM platform.
073     * @since 1.8
074     */
075    BCJ_ARM_FILTER(new byte[] { 0x03, 0x03, 0x05, 0x01 }),
076    /**
077     * BCJ ARM Thumb platform.
078     * @since 1.8
079     */
080    BCJ_ARM_THUMB_FILTER(new byte[] { 0x03, 0x03, 0x07, 0x01 }),
081    /**
082     * BCJ Sparc platform.
083     * @since 1.8
084     */
085    BCJ_SPARC_FILTER(new byte[] { 0x03, 0x03, 0x08, 0x05 }),
086    /**
087     * Delta filter.
088     * @since 1.8
089     */
090    DELTA_FILTER(new byte[] { 0x03 });
091
092    static SevenZMethod byId(final byte[] id) {
093        for (final SevenZMethod m : SevenZMethod.class.getEnumConstants()) {
094            if (Arrays.equals(m.id, id)) {
095                return m;
096            }
097        }
098        return null;
099    }
100
101    private final byte[] id;
102
103    SevenZMethod(final byte[] id) {
104        this.id = id;
105    }
106
107    byte[] getId() {
108        return Arrays.copyOf(id, id.length);
109    }
110}