Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 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.zip; |
| 19 | |
Stefan Bodewig | 59dfc7c | 2012-11-10 17:27:14 +0000 | [diff] [blame] | 20 | import java.util.Collections; |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 21 | import java.util.HashMap; |
| 22 | import java.util.Map; |
| 23 | import java.util.zip.ZipEntry; |
| 24 | |
| 25 | /** |
| 26 | * List of known compression methods |
| 27 | * |
| 28 | * Many of these methods are currently not supported by commons compress |
| 29 | * |
| 30 | * @since 1.5 |
| 31 | */ |
| 32 | public enum ZipMethod { |
| 33 | |
| 34 | /** |
| 35 | * Compression method 0 for uncompressed entries. |
| 36 | * |
| 37 | * @see ZipEntry#STORED |
| 38 | */ |
| 39 | STORED(ZipEntry.STORED), |
| 40 | |
| 41 | /** |
| 42 | * UnShrinking. |
| 43 | * dynamic Lempel-Ziv-Welch-Algorithm |
| 44 | * |
Gary D. Gregory | a0ac844 | 2012-10-25 19:33:26 +0000 | [diff] [blame] | 45 | * @see <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">Explanation of fields: compression |
| 46 | * method: (2 bytes)</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 47 | */ |
| 48 | UNSHRINKING(1), |
| 49 | |
| 50 | /** |
| 51 | * Reduced with compression factor 1. |
| 52 | * |
Gary D. Gregory | a0ac844 | 2012-10-25 19:33:26 +0000 | [diff] [blame] | 53 | * @see <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">Explanation of fields: compression |
| 54 | * method: (2 bytes)</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 55 | */ |
| 56 | EXPANDING_LEVEL_1(2), |
| 57 | |
| 58 | /** |
| 59 | * Reduced with compression factor 2. |
| 60 | * |
Gary D. Gregory | a0ac844 | 2012-10-25 19:33:26 +0000 | [diff] [blame] | 61 | * @see <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">Explanation of fields: compression |
| 62 | * method: (2 bytes)</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 63 | */ |
| 64 | EXPANDING_LEVEL_2(3), |
| 65 | |
| 66 | /** |
| 67 | * Reduced with compression factor 3. |
| 68 | * |
Gary D. Gregory | a0ac844 | 2012-10-25 19:33:26 +0000 | [diff] [blame] | 69 | * @see <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">Explanation of fields: compression |
| 70 | * method: (2 bytes)</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 71 | */ |
| 72 | EXPANDING_LEVEL_3(4), |
| 73 | |
| 74 | /** |
| 75 | * Reduced with compression factor 4. |
| 76 | * |
Gary D. Gregory | a0ac844 | 2012-10-25 19:33:26 +0000 | [diff] [blame] | 77 | * @see <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">Explanation of fields: compression |
| 78 | * method: (2 bytes)</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 79 | */ |
| 80 | EXPANDING_LEVEL_4(5), |
| 81 | |
| 82 | /** |
| 83 | * Imploding. |
| 84 | * |
Gary D. Gregory | a0ac844 | 2012-10-25 19:33:26 +0000 | [diff] [blame] | 85 | * @see <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">Explanation of fields: compression |
| 86 | * method: (2 bytes)</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 87 | */ |
| 88 | IMPLODING(6), |
| 89 | |
| 90 | /** |
| 91 | * Tokenization. |
| 92 | * |
Gary D. Gregory | a0ac844 | 2012-10-25 19:33:26 +0000 | [diff] [blame] | 93 | * @see <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">Explanation of fields: compression |
| 94 | * method: (2 bytes)</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 95 | */ |
| 96 | TOKENIZATION(7), |
| 97 | |
| 98 | /** |
| 99 | * Compression method 8 for compressed (deflated) entries. |
| 100 | * |
| 101 | * @see ZipEntry#DEFLATED |
| 102 | */ |
| 103 | DEFLATED(ZipEntry.DEFLATED), |
| 104 | |
| 105 | /** |
| 106 | * Compression Method 9 for enhanced deflate. |
| 107 | * |
Stefan Bodewig | 45e51c2 | 2013-12-22 07:03:43 +0000 | [diff] [blame^] | 108 | * @see <a href="http://www.winzip.com/wz54.htm">http://www.winzip.com/wz54.htm</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 109 | */ |
| 110 | ENHANCED_DEFLATED(9), |
| 111 | |
| 112 | /** |
| 113 | * PKWARE Data Compression Library Imploding. |
| 114 | * |
Stefan Bodewig | 45e51c2 | 2013-12-22 07:03:43 +0000 | [diff] [blame^] | 115 | * @see <a href="http://www.winzip.com/wz54.htm">http://www.winzip.com/wz54.htm</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 116 | */ |
| 117 | PKWARE_IMPLODING(10), |
| 118 | |
| 119 | /** |
| 120 | * Compression Method 12 for bzip2. |
| 121 | * |
Stefan Bodewig | 45e51c2 | 2013-12-22 07:03:43 +0000 | [diff] [blame^] | 122 | * @see <a href="http://www.winzip.com/wz54.htm">http://www.winzip.com/wz54.htm</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 123 | */ |
| 124 | BZIP2(12), |
| 125 | |
| 126 | /** |
| 127 | * Compression Method 14 for LZMA. |
| 128 | * |
Stefan Bodewig | 45e51c2 | 2013-12-22 07:03:43 +0000 | [diff] [blame^] | 129 | * @see <a href="http://www.7-zip.org/sdk.html">http://www.7-zip.org/sdk.html</a> |
| 130 | * @see <a href="http://www.winzip.com/wz54.htm">http://www.winzip.com/wz54.htm</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 131 | */ |
| 132 | LZMA(14), |
| 133 | |
| 134 | |
| 135 | /** |
| 136 | * Compression Method 96 for Jpeg compression. |
| 137 | * |
Stefan Bodewig | 45e51c2 | 2013-12-22 07:03:43 +0000 | [diff] [blame^] | 138 | * @see <a href="http://www.winzip.com/wz54.htm">http://www.winzip.com/wz54.htm</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 139 | */ |
| 140 | JPEG(96), |
| 141 | |
| 142 | /** |
| 143 | * Compression Method 97 for WavPack. |
| 144 | * |
Stefan Bodewig | 45e51c2 | 2013-12-22 07:03:43 +0000 | [diff] [blame^] | 145 | * @see <a href="http://www.winzip.com/wz54.htm">http://www.winzip.com/wz54.htm</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 146 | */ |
| 147 | WAVPACK(97), |
| 148 | |
| 149 | /** |
| 150 | * Compression Method 98 for PPMd. |
| 151 | * |
Stefan Bodewig | 45e51c2 | 2013-12-22 07:03:43 +0000 | [diff] [blame^] | 152 | * @see <a href="http://www.winzip.com/wz54.htm">http://www.winzip.com/wz54.htm</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 153 | */ |
| 154 | PPMD(98), |
| 155 | |
| 156 | |
| 157 | /** |
| 158 | * Compression Method 99 for AES encryption. |
| 159 | * |
Stefan Bodewig | 45e51c2 | 2013-12-22 07:03:43 +0000 | [diff] [blame^] | 160 | * @see <a href="http://www.winzip.com/wz54.htm">http://www.winzip.com/wz54.htm</a> |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 161 | */ |
| 162 | AES_ENCRYPTED(99), |
| 163 | |
| 164 | /** |
| 165 | * Unknown compression method. |
| 166 | */ |
| 167 | UNKNOWN(-1); |
| 168 | |
| 169 | private final int code; |
| 170 | |
Stefan Bodewig | 59dfc7c | 2012-11-10 17:27:14 +0000 | [diff] [blame] | 171 | private static final Map<Integer, ZipMethod> codeToEnum; |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 172 | |
| 173 | static { |
Stefan Bodewig | 59dfc7c | 2012-11-10 17:27:14 +0000 | [diff] [blame] | 174 | Map<Integer, ZipMethod> cte = new HashMap<Integer, ZipMethod>(); |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 175 | for (ZipMethod method : values()) { |
Stefan Bodewig | 59dfc7c | 2012-11-10 17:27:14 +0000 | [diff] [blame] | 176 | cte.put(Integer.valueOf(method.getCode()), method); |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 177 | } |
Stefan Bodewig | 59dfc7c | 2012-11-10 17:27:14 +0000 | [diff] [blame] | 178 | codeToEnum = Collections.unmodifiableMap(cte); |
Stefan Bodewig | c96b2e2 | 2012-07-08 18:55:06 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /** |
| 182 | * private constructor for enum style class. |
| 183 | */ |
| 184 | ZipMethod(int code) { |
| 185 | this.code = code; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * the code of the compression method. |
| 190 | * |
| 191 | * @see ZipArchiveEntry#getMethod() |
| 192 | * |
| 193 | * @return an integer code for the method |
| 194 | */ |
| 195 | public int getCode() { |
| 196 | return code; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | /** |
| 201 | * returns the {@link ZipMethod} for the given code or null if the |
| 202 | * method is not known. |
| 203 | */ |
| 204 | public static ZipMethod getMethodByCode(int code) { |
| 205 | return codeToEnum.get(Integer.valueOf(code)); |
| 206 | } |
| 207 | } |