src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java

changeset 103
e571266ae14f
parent 57
aa67a5da66e3
child 333
7c2d6da61646
     1.1 --- a/src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java	Fri Aug 22 11:46:29 2008 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java	Tue Aug 26 14:52:59 2008 -0700
     1.3 @@ -29,11 +29,8 @@
     1.4  import java.util.Set;
     1.5  import javax.tools.JavaFileObject;
     1.6  
     1.7 -import com.sun.tools.javac.file.JavacFileManager.Archive;
     1.8 -import com.sun.tools.javac.util.List;
     1.9  import java.io.ByteArrayInputStream;
    1.10  import java.io.File;
    1.11 -import java.io.FileNotFoundException;
    1.12  import java.io.InputStream;
    1.13  import java.io.OutputStream;
    1.14  import java.io.Writer;
    1.15 @@ -42,6 +39,11 @@
    1.16  import java.nio.CharBuffer;
    1.17  import java.nio.charset.CharsetDecoder;
    1.18  
    1.19 +import com.sun.tools.javac.file.JavacFileManager.Archive;
    1.20 +import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
    1.21 +import com.sun.tools.javac.file.RelativePath.RelativeFile;
    1.22 +import com.sun.tools.javac.util.List;
    1.23 +
    1.24  public class ZipFileIndexArchive implements Archive {
    1.25  
    1.26      private final ZipFileIndex zfIndex;
    1.27 @@ -53,22 +55,22 @@
    1.28          this.zfIndex = zdir;
    1.29      }
    1.30  
    1.31 -    public boolean contains(String name) {
    1.32 +    public boolean contains(RelativePath name) {
    1.33          return zfIndex.contains(name);
    1.34      }
    1.35  
    1.36 -    public List<String> getFiles(String subdirectory) {
    1.37 -        return zfIndex.getFiles((subdirectory.endsWith("/") || subdirectory.endsWith("\\")) ? subdirectory.substring(0, subdirectory.length() - 1) : subdirectory);
    1.38 +    public List<String> getFiles(RelativeDirectory subdirectory) {
    1.39 +        return zfIndex.getFiles(subdirectory);
    1.40      }
    1.41  
    1.42 -    public JavaFileObject getFileObject(String subdirectory, String file) {
    1.43 -        String fullZipFileName = subdirectory + file;
    1.44 +    public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) {
    1.45 +        RelativeFile fullZipFileName = new RelativeFile(subdirectory, file);
    1.46          ZipFileIndex.Entry entry = zfIndex.getZipIndexEntry(fullZipFileName);
    1.47          JavaFileObject ret = new ZipFileIndexFileObject(fileManager, zfIndex, entry, zfIndex.getZipFile().getPath());
    1.48          return ret;
    1.49      }
    1.50  
    1.51 -    public Set<String> getSubdirectories() {
    1.52 +    public Set<RelativeDirectory> getSubdirectories() {
    1.53          return zfIndex.getAllDirectories();
    1.54      }
    1.55  
    1.56 @@ -76,6 +78,10 @@
    1.57          zfIndex.close();
    1.58      }
    1.59  
    1.60 +    public String toString() {
    1.61 +        return "ZipFileIndexArchive[" + zfIndex + "]";
    1.62 +    }
    1.63 +
    1.64      /**
    1.65       * A subclass of JavaFileObject representing zip entries using the com.sun.tools.javac.file.ZipFileIndex implementation.
    1.66       */
    1.67 @@ -181,18 +187,11 @@
    1.68          public URI toUri() {
    1.69              String zipName = new File(getZipName()).toURI().normalize().getPath();
    1.70              String entryName = getZipEntryName();
    1.71 -            if (File.separatorChar != '/') {
    1.72 -                entryName = entryName.replace(File.separatorChar, '/');
    1.73 -            }
    1.74              return URI.create("jar:" + zipName + "!" + entryName);
    1.75          }
    1.76  
    1.77          private byte[] read() throws IOException {
    1.78 -            if (entry == null) {
    1.79 -                entry = zfIndex.getZipIndexEntry(name);
    1.80 -                if (entry == null)
    1.81 -                  throw new FileNotFoundException();
    1.82 -            }
    1.83 +            assert entry != null; // see constructor
    1.84              return zfIndex.read(entry);
    1.85          }
    1.86  
    1.87 @@ -222,11 +221,11 @@
    1.88          protected String inferBinaryName(Iterable<? extends File> path) {
    1.89              String entryName = getZipEntryName();
    1.90              if (zfIndex.symbolFilePrefix != null) {
    1.91 -                String prefix = zfIndex.symbolFilePrefix;
    1.92 +                String prefix = zfIndex.symbolFilePrefix.path;
    1.93                  if (entryName.startsWith(prefix))
    1.94                      entryName = entryName.substring(prefix.length());
    1.95              }
    1.96 -            return removeExtension(entryName).replace(File.separatorChar, '.');
    1.97 +            return removeExtension(entryName).replace('/', '.');
    1.98          }
    1.99      }
   1.100  

mercurial