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    
033        /**
034         * Creates an exception.
035         * @param reason the feature that is not supported
036         * @param entry the entry using the feature
037         */
038        public UnsupportedZipFeatureException(Feature reason,
039                                              ZipArchiveEntry entry) {
040            super("unsupported feature " + reason +  " used in entry "
041                  + entry.getName());
042            this.reason = reason;
043            this.entry = entry;
044        }
045    
046        /**
047         * The unsupported feature that has been used.
048         */
049        public Feature getFeature() {
050            return reason;
051        }
052    
053        /**
054         * The entry using the unsupported feature.
055         */
056        public ZipArchiveEntry getEntry() {
057            return entry;
058        }
059    
060        /**
061         * ZIP Features that may or may not be supported.
062         * @since Commons Compress 1.1
063         */
064        public static class Feature {
065            /**
066             * The entry is encrypted.
067             */
068            public static final Feature ENCRYPTION = new Feature("encryption");
069            /**
070             * The entry used an unsupported compression method.
071             */
072            public static final Feature METHOD = new Feature("compression method");
073            /**
074             * The entry uses a data descriptor.
075             */
076            public static final Feature DATA_DESCRIPTOR = new Feature("data descriptor");
077            
078            private final String name;
079    
080            private Feature(String name) {
081                this.name = name;
082            }
083    
084            public String toString() {
085                return name;
086            }
087        }
088    }