1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tools.build.apkzlib.zip;
18 
19 import javax.annotation.Nullable;
20 
21 /**
22  * Enumeration with all known compression methods.
23  */
24 public enum CompressionMethod {
25     /**
26      * STORE method: data is stored without any compression.
27      */
28     STORE(0),
29 
30     /**
31      * DEFLATE method: data is stored compressed using the DEFLATE algorithm.
32      */
33     DEFLATE(8);
34 
35     /**
36      * Code, within the zip file, that identifies this compression method.
37      */
38     int methodCode;
39 
40     /**
41      * Creates a new compression method.
42      *
43      * @param methodCode the code used in the zip file that identifies the compression method
44      */
CompressionMethod(int methodCode)45     CompressionMethod(int methodCode) {
46         this.methodCode = methodCode;
47     }
48 
49     /**
50      * Obtains the compression method that corresponds to the provided code.
51      *
52      * @param code the code
53      * @return the method or {@code null} if no method has the provided code
54      */
55     @Nullable
fromCode(long code)56     static CompressionMethod fromCode(long code) {
57         for (CompressionMethod method : values()) {
58             if (method.methodCode == code) {
59                 return method;
60             }
61         }
62 
63         return null;
64     }
65 }
66