001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019 package org.apache.felix.framework.util;
020
021 import java.io.File;
022 import java.io.IOException;
023 import java.util.jar.JarEntry;
024 import java.util.jar.JarFile;
025 import java.util.zip.ZipEntry;
026
027 /**
028 * The purpose of this class is to fix an apparent bug in the JVM in versions
029 * 1.4.2 and lower where directory entries in ZIP/JAR files are not correctly
030 * identified.
031 **/
032 public class JarFileX extends JarFile
033 {
034 public JarFileX(File file) throws IOException
035 {
036 super(file);
037 }
038
039 public JarFileX(File file, boolean verify) throws IOException
040 {
041 super(file, verify);
042 }
043
044 public JarFileX(File file, boolean verify, int mode) throws IOException
045 {
046 super(file, verify, mode);
047 }
048
049 public JarFileX(String name) throws IOException
050 {
051 super(name);
052 }
053
054 public JarFileX(String name, boolean verify) throws IOException
055 {
056 super(name, verify);
057 }
058
059 public ZipEntry getEntry(String name)
060 {
061 ZipEntry entry = super.getEntry(name);
062 if ((entry != null) && (entry.getSize() == 0) && !entry.isDirectory())
063 {
064 ZipEntry dirEntry = super.getEntry(name + '/');
065 if (dirEntry != null)
066 {
067 entry = dirEntry;
068 }
069 }
070 return entry;
071 }
072
073 public JarEntry getJarEntry(String name)
074 {
075 JarEntry entry = super.getJarEntry(name);
076 if ((entry != null) && (entry.getSize() == 0) && !entry.isDirectory())
077 {
078 JarEntry dirEntry = super.getJarEntry(name + '/');
079 if (dirEntry != null)
080 {
081 entry = dirEntry;
082 }
083 }
084 return entry;
085 }
086 }