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     */
018    
019    package org.apache.commons.compress.archivers.zip;
020    
021    import java.util.zip.ZipException;
022    
023    /**
024     * Exception thrown when attempting to read or write data for a zip
025     * entry that uses ZIP features not supported by this library.
026     * @since Commons Compress 1.1
027     */
028    public class UnsupportedZipFeatureException extends ZipException {
029    
030        private final Feature reason;
031        private final ZipArchiveEntry entry;
032        private static final long serialVersionUID = 4430521921766595597L;
033    
034        /**
035         * Creates an exception.
036         * @param reason the feature that is not supported
037         * @param entry the entry using the feature
038         */
039        public UnsupportedZipFeatureException(Feature reason,
040                                              ZipArchiveEntry entry) {
041            super("unsupported feature " + reason +  " used in entry "
042                  + entry.getName());
043            this.reason = reason;
044            this.entry = entry;
045        }
046    
047        /**
048         * The unsupported feature that has been used.
049         */
050        public Feature getFeature() {
051            return reason;
052        }
053    
054        /**
055         * The entry using the unsupported feature.
056         */
057        public ZipArchiveEntry getEntry() {
058            return entry;
059        }
060    
061        /**
062         * ZIP Features that may or may not be supported.
063         * @since Commons Compress 1.1
064         */
065        public static class Feature {
066            /**
067             * The entry is encrypted.
068             */
069            public static final Feature ENCRYPTION = new Feature("encryption");
070            /**
071             * The entry used an unsupported compression method.
072             */
073            public static final Feature METHOD = new Feature("compression method");
074            /**
075             * The entry uses a data descriptor.
076             */
077            public static final Feature DATA_DESCRIPTOR = new Feature("data descriptor");
078    
079            private final String name;
080    
081            private Feature(String name) {
082                this.name = name;
083            }
084    
085            @Override
086            public String toString() {
087                return name;
088            }
089        }
090    }