• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 package org.apache.commons.compress.archivers.zip;
20 
21 import java.util.zip.ZipException;
22 
23 /**
24  * Exception thrown when attempting to read or write data for a zip
25  * entry that uses ZIP features not supported by this library.
26  * @since 1.1
27  */
28 public class UnsupportedZipFeatureException extends ZipException {
29 
30     private final Feature reason;
31     private transient final ZipArchiveEntry entry;
32     private static final long serialVersionUID = 20161219L;
33 
34     /**
35      * Creates an exception.
36      * @param reason the feature that is not supported
37      * @param entry the entry using the feature
38      */
UnsupportedZipFeatureException(final Feature reason, final ZipArchiveEntry entry)39     public UnsupportedZipFeatureException(final Feature reason,
40                                           final ZipArchiveEntry entry) {
41         super("unsupported feature " + reason +  " used in entry "
42               + entry.getName());
43         this.reason = reason;
44         this.entry = entry;
45     }
46 
47     /**
48      * Creates an exception for archives that use an unsupported
49      * compression algorithm.
50      * @param method the method that is not supported
51      * @param entry the entry using the feature
52      * @since 1.5
53      */
UnsupportedZipFeatureException(final ZipMethod method, final ZipArchiveEntry entry)54     public UnsupportedZipFeatureException(final ZipMethod method,
55                                           final ZipArchiveEntry entry) {
56         super("unsupported feature method '" + method.name()
57               +  "' used in entry " + entry.getName());
58         this.reason = Feature.METHOD;
59         this.entry = entry;
60     }
61 
62     /**
63      * Creates an exception when the whole archive uses an unsupported
64      * feature.
65      *
66      * @param reason the feature that is not supported
67      * @since 1.5
68      */
UnsupportedZipFeatureException(final Feature reason)69     public UnsupportedZipFeatureException(final Feature reason) {
70         super("unsupported feature " + reason +  " used in archive.");
71         this.reason = reason;
72         this.entry = null;
73     }
74 
75     /**
76      * The unsupported feature that has been used.
77      * @return The unsupported feature that has been used.
78      */
getFeature()79     public Feature getFeature() {
80         return reason;
81     }
82 
83     /**
84      * The entry using the unsupported feature.
85      * @return The entry using the unsupported feature.
86      */
getEntry()87     public ZipArchiveEntry getEntry() {
88         return entry;
89     }
90 
91     /**
92      * ZIP Features that may or may not be supported.
93      * @since 1.1
94      */
95     public static class Feature implements java.io.Serializable {
96 
97         private static final long serialVersionUID = 4112582948775420359L;
98         /**
99          * The entry is encrypted.
100          */
101         public static final Feature ENCRYPTION = new Feature("encryption");
102         /**
103          * The entry used an unsupported compression method.
104          */
105         public static final Feature METHOD = new Feature("compression method");
106         /**
107          * The entry uses a data descriptor.
108          */
109         public static final Feature DATA_DESCRIPTOR = new Feature("data descriptor");
110         /**
111          * The archive uses splitting or spanning.
112          * @since 1.5
113          */
114         public static final Feature SPLITTING = new Feature("splitting");
115         /**
116          * The archive contains entries with unknown compressed size
117          * for a compression method that doesn't support detection of
118          * the end of the compressed stream.
119          * @since 1.16
120          */
121         public static final Feature UNKNOWN_COMPRESSED_SIZE = new Feature("unknown compressed size");
122 
123         private final String name;
124 
Feature(final String name)125         private Feature(final String name) {
126             this.name = name;
127         }
128 
129         @Override
toString()130         public String toString() {
131             return name;
132         }
133     }
134 }
135