1.1 --- a/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Tue Jun 17 10:44:32 2008 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Wed Jun 18 07:23:25 2008 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -25,21 +25,16 @@ 1.11 1.12 package com.sun.tools.javac.file; 1.13 1.14 -import java.io.ByteArrayInputStream; 1.15 import java.io.ByteArrayOutputStream; 1.16 import java.io.File; 1.17 import java.io.FileInputStream; 1.18 import java.io.FileNotFoundException; 1.19 -import java.io.FileOutputStream; 1.20 import java.io.IOException; 1.21 import java.io.InputStream; 1.22 -import java.io.OutputStream; 1.23 import java.io.OutputStreamWriter; 1.24 -import java.io.Writer; 1.25 import java.lang.ref.SoftReference; 1.26 import java.net.MalformedURLException; 1.27 import java.net.URI; 1.28 -import java.net.URISyntaxException; 1.29 import java.net.URL; 1.30 import java.net.URLClassLoader; 1.31 import java.nio.ByteBuffer; 1.32 @@ -56,13 +51,11 @@ 1.33 import java.util.Collection; 1.34 import java.util.Collections; 1.35 import java.util.EnumSet; 1.36 -import java.util.Enumeration; 1.37 import java.util.HashMap; 1.38 import java.util.Iterator; 1.39 import java.util.Map; 1.40 import java.util.Set; 1.41 import java.util.concurrent.ConcurrentHashMap; 1.42 -import java.util.zip.ZipEntry; 1.43 import java.util.zip.ZipFile; 1.44 1.45 import javax.lang.model.SourceVersion; 1.46 @@ -96,15 +89,6 @@ 1.47 1.48 boolean useZipFileIndex; 1.49 1.50 - private static int symbolFilePrefixLength = 0; 1.51 - static { 1.52 - try { 1.53 - symbolFilePrefixLength = symbolFilePrefix.getBytes("UTF-8").length; 1.54 - } catch (java.io.UnsupportedEncodingException uee) { 1.55 - // Can't happen...UTF-8 is always supported. 1.56 - } 1.57 - } 1.58 - 1.59 private static boolean CHECK_ZIP_TIMESTAMP = false; 1.60 private static Map<File, Boolean> isDirectory = new ConcurrentHashMap<File, Boolean>(); 1.61 1.62 @@ -202,7 +186,7 @@ 1.63 } 1.64 1.65 public JavaFileObject getRegularFile(File file) { 1.66 - return new RegularFileObject(file); 1.67 + return new RegularFileObject(this, file); 1.68 } 1.69 1.70 public JavaFileObject getFileForOutput(String classname, 1.71 @@ -405,7 +389,7 @@ 1.72 } else { 1.73 if (isValidFile(fname, fileKinds)) { 1.74 JavaFileObject fe = 1.75 - new RegularFileObject(fname, new File(d, fname)); 1.76 + new RegularFileObject(this, fname, new File(d, fname)); 1.77 l.append(fe); 1.78 } 1.79 } 1.80 @@ -469,106 +453,13 @@ 1.81 Set<String> getSubdirectories(); 1.82 } 1.83 1.84 - public class ZipArchive implements Archive { 1.85 - protected final Map<String,List<String>> map; 1.86 - protected final ZipFile zdir; 1.87 - public ZipArchive(ZipFile zdir) throws IOException { 1.88 - this.zdir = zdir; 1.89 - this.map = new HashMap<String,List<String>>(); 1.90 - for (Enumeration<? extends ZipEntry> e = zdir.entries(); e.hasMoreElements(); ) { 1.91 - ZipEntry entry; 1.92 - try { 1.93 - entry = e.nextElement(); 1.94 - } catch (InternalError ex) { 1.95 - IOException io = new IOException(); 1.96 - io.initCause(ex); // convenience constructors added in Mustang :-( 1.97 - throw io; 1.98 - } 1.99 - addZipEntry(entry); 1.100 - } 1.101 - } 1.102 - 1.103 - void addZipEntry(ZipEntry entry) { 1.104 - String name = entry.getName(); 1.105 - int i = name.lastIndexOf('/'); 1.106 - String dirname = name.substring(0, i+1); 1.107 - String basename = name.substring(i+1); 1.108 - if (basename.length() == 0) 1.109 - return; 1.110 - List<String> list = map.get(dirname); 1.111 - if (list == null) 1.112 - list = List.nil(); 1.113 - list = list.prepend(basename); 1.114 - map.put(dirname, list); 1.115 - } 1.116 - 1.117 - public boolean contains(String name) { 1.118 - int i = name.lastIndexOf('/'); 1.119 - String dirname = name.substring(0, i+1); 1.120 - String basename = name.substring(i+1); 1.121 - if (basename.length() == 0) 1.122 - return false; 1.123 - List<String> list = map.get(dirname); 1.124 - return (list != null && list.contains(basename)); 1.125 - } 1.126 - 1.127 - public List<String> getFiles(String subdirectory) { 1.128 - return map.get(subdirectory); 1.129 - } 1.130 - 1.131 - public JavaFileObject getFileObject(String subdirectory, String file) { 1.132 - ZipEntry ze = zdir.getEntry(subdirectory + file); 1.133 - return new ZipFileObject(file, zdir, ze); 1.134 - } 1.135 - 1.136 - public Set<String> getSubdirectories() { 1.137 - return map.keySet(); 1.138 - } 1.139 - 1.140 - public void close() throws IOException { 1.141 - zdir.close(); 1.142 - } 1.143 - } 1.144 - 1.145 - public class SymbolArchive extends ZipArchive { 1.146 - final File origFile; 1.147 - public SymbolArchive(File orig, ZipFile zdir) throws IOException { 1.148 - super(zdir); 1.149 - this.origFile = orig; 1.150 - } 1.151 - 1.152 - @Override 1.153 - void addZipEntry(ZipEntry entry) { 1.154 - // called from super constructor, may not refer to origFile. 1.155 - String name = entry.getName(); 1.156 - if (!name.startsWith(symbolFilePrefix)) 1.157 - return; 1.158 - name = name.substring(symbolFilePrefix.length()); 1.159 - int i = name.lastIndexOf('/'); 1.160 - String dirname = name.substring(0, i+1); 1.161 - String basename = name.substring(i+1); 1.162 - if (basename.length() == 0) 1.163 - return; 1.164 - List<String> list = map.get(dirname); 1.165 - if (list == null) 1.166 - list = List.nil(); 1.167 - list = list.prepend(basename); 1.168 - map.put(dirname, list); 1.169 - } 1.170 - 1.171 - @Override 1.172 - public JavaFileObject getFileObject(String subdirectory, String file) { 1.173 - return super.getFileObject(symbolFilePrefix + subdirectory, file); 1.174 - } 1.175 - } 1.176 - 1.177 public class MissingArchive implements Archive { 1.178 final File zipFileName; 1.179 public MissingArchive(File name) { 1.180 zipFileName = name; 1.181 } 1.182 public boolean contains(String name) { 1.183 - return false; 1.184 + return false; 1.185 } 1.186 1.187 public void close() { 1.188 @@ -647,19 +538,23 @@ 1.189 1.190 if (origZipFileName == zipFileName) { 1.191 if (!useZipFileIndex) { 1.192 - archive = new ZipArchive(zdir); 1.193 + archive = new ZipArchive(this, zdir); 1.194 } else { 1.195 - archive = new ZipFileIndexArchive(this, ZipFileIndex.getZipFileIndex(zipFileName, 0, 1.196 + archive = new ZipFileIndexArchive(this, ZipFileIndex.getZipFileIndex(zipFileName, null, 1.197 usePreindexedCache, preindexCacheLocation, options.get("writezipindexfiles") != null)); 1.198 } 1.199 } 1.200 else { 1.201 if (!useZipFileIndex) { 1.202 - archive = new SymbolArchive(origZipFileName, zdir); 1.203 + archive = new SymbolArchive(this, origZipFileName, zdir, symbolFilePrefix); 1.204 } 1.205 else { 1.206 - archive = new ZipFileIndexArchive(this, ZipFileIndex.getZipFileIndex(zipFileName, symbolFilePrefixLength, 1.207 - usePreindexedCache, preindexCacheLocation, options.get("writezipindexfiles") != null)); 1.208 + archive = new ZipFileIndexArchive(this, 1.209 + ZipFileIndex.getZipFileIndex(zipFileName, 1.210 + symbolFilePrefix, 1.211 + usePreindexedCache, 1.212 + preindexCacheLocation, 1.213 + options.get("writezipindexfiles") != null)); 1.214 } 1.215 } 1.216 } catch (FileNotFoundException ex) { 1.217 @@ -695,7 +590,17 @@ 1.218 } 1.219 } 1.220 1.221 - private Map<JavaFileObject, SoftReference<CharBuffer>> contentCache = new HashMap<JavaFileObject, SoftReference<CharBuffer>>(); 1.222 + CharBuffer getCachedContent(JavaFileObject file) { 1.223 + SoftReference<CharBuffer> r = contentCache.get(file); 1.224 + return (r == null ? null : r.get()); 1.225 + } 1.226 + 1.227 + void cache(JavaFileObject file, CharBuffer cb) { 1.228 + contentCache.put(file, new SoftReference<CharBuffer>(cb)); 1.229 + } 1.230 + 1.231 + private final Map<JavaFileObject, SoftReference<CharBuffer>> contentCache 1.232 + = new HashMap<JavaFileObject, SoftReference<CharBuffer>>(); 1.233 1.234 private String defaultEncodingName; 1.235 private String getDefaultEncodingName() { 1.236 @@ -725,7 +630,7 @@ 1.237 /** 1.238 * Make a byte buffer from an input stream. 1.239 */ 1.240 - private ByteBuffer makeByteBuffer(InputStream in) 1.241 + ByteBuffer makeByteBuffer(InputStream in) 1.242 throws IOException { 1.243 int limit = in.available(); 1.244 if (mmappedIO && in instanceof FileInputStream) { 1.245 @@ -751,6 +656,10 @@ 1.246 return (ByteBuffer)result.flip(); 1.247 } 1.248 1.249 + void recycleByteBuffer(ByteBuffer bb) { 1.250 + byteBufferCache.put(bb); 1.251 + } 1.252 + 1.253 /** 1.254 * A single-element cache of direct byte buffers. 1.255 */ 1.256 @@ -769,9 +678,10 @@ 1.257 cached = x; 1.258 } 1.259 } 1.260 + 1.261 private final ByteBufferCache byteBufferCache; 1.262 1.263 - private CharsetDecoder getDecoder(String encodingName, boolean ignoreEncodingErrors) { 1.264 + CharsetDecoder getDecoder(String encodingName, boolean ignoreEncodingErrors) { 1.265 Charset charset = (this.charset == null) 1.266 ? Charset.forName(encodingName) 1.267 : this.charset; 1.268 @@ -791,7 +701,7 @@ 1.269 /** 1.270 * Decode a ByteBuffer into a CharBuffer. 1.271 */ 1.272 - private CharBuffer decode(ByteBuffer inbuf, boolean ignoreEncodingErrors) { 1.273 + CharBuffer decode(ByteBuffer inbuf, boolean ignoreEncodingErrors) { 1.274 String encodingName = getEncodingName(); 1.275 CharsetDecoder decoder; 1.276 try { 1.277 @@ -901,48 +811,14 @@ 1.278 // Need to match the path semantics of list(location, ...) 1.279 Iterable<? extends File> path = getLocation(location); 1.280 if (path == null) { 1.281 - //System.err.println("Path for " + location + " is null"); 1.282 return null; 1.283 } 1.284 - //System.err.println("Path for " + location + " is " + path); 1.285 1.286 - if (file instanceof RegularFileObject) { 1.287 - RegularFileObject r = (RegularFileObject) file; 1.288 - String rPath = r.getPath(); 1.289 - //System.err.println("RegularFileObject " + file + " " +r.getPath()); 1.290 - for (File dir: path) { 1.291 - //System.err.println("dir: " + dir); 1.292 - String dPath = dir.getPath(); 1.293 - if (!dPath.endsWith(File.separator)) 1.294 - dPath += File.separator; 1.295 - if (rPath.regionMatches(true, 0, dPath, 0, dPath.length()) 1.296 - && new File(rPath.substring(0, dPath.length())).equals(new File(dPath))) { 1.297 - String relativeName = rPath.substring(dPath.length()); 1.298 - return removeExtension(relativeName).replace(File.separatorChar, '.'); 1.299 - } 1.300 - } 1.301 - } else if (file instanceof ZipFileObject) { 1.302 - ZipFileObject z = (ZipFileObject) file; 1.303 - String entryName = z.getZipEntryName(); 1.304 - if (entryName.startsWith(symbolFilePrefix)) 1.305 - entryName = entryName.substring(symbolFilePrefix.length()); 1.306 - return removeExtension(entryName).replace('/', '.'); 1.307 - } else if (file instanceof ZipFileIndexFileObject) { 1.308 - ZipFileIndexFileObject z = (ZipFileIndexFileObject) file; 1.309 - String entryName = z.getZipEntryName(); 1.310 - if (entryName.startsWith(symbolFilePrefix)) 1.311 - entryName = entryName.substring(symbolFilePrefix.length()); 1.312 - return removeExtension(entryName).replace(File.separatorChar, '.'); 1.313 + if (file instanceof BaseFileObject) { 1.314 + return ((BaseFileObject) file).inferBinaryName(path); 1.315 } else 1.316 throw new IllegalArgumentException(file.getClass().getName()); 1.317 - // System.err.println("inferBinaryName failed for " + file); 1.318 - return null; 1.319 } 1.320 - // where 1.321 - private static String removeExtension(String fileName) { 1.322 - int lastDot = fileName.lastIndexOf("."); 1.323 - return (lastDot == -1 ? fileName : fileName.substring(0, lastDot)); 1.324 - } 1.325 1.326 public boolean isSameFile(FileObject a, FileObject b) { 1.327 nullCheck(a); 1.328 @@ -1029,7 +905,7 @@ 1.329 if (dir.isDirectory()) { 1.330 File f = new File(dir, name.replace('/', File.separatorChar)); 1.331 if (f.exists()) 1.332 - return new RegularFileObject(f); 1.333 + return new RegularFileObject(this, f); 1.334 } else { 1.335 Archive a = openArchive(dir); 1.336 if (a.contains(name)) { 1.337 @@ -1091,7 +967,7 @@ 1.338 if (sibling != null && sibling instanceof RegularFileObject) { 1.339 siblingDir = ((RegularFileObject)sibling).f.getParentFile(); 1.340 } 1.341 - return new RegularFileObject(new File(siblingDir, baseName(fileName))); 1.342 + return new RegularFileObject(this, new File(siblingDir, baseName(fileName))); 1.343 } 1.344 } else if (location == SOURCE_OUTPUT) { 1.345 dir = (getSourceOutDir() != null ? getSourceOutDir() : getClassOutDir()); 1.346 @@ -1105,7 +981,7 @@ 1.347 } 1.348 1.349 File file = (dir == null ? new File(fileName) : new File(dir, fileName)); 1.350 - return new RegularFileObject(file); 1.351 + return new RegularFileObject(this, file); 1.352 1.353 } 1.354 1.355 @@ -1118,7 +994,7 @@ 1.356 else 1.357 result = new ArrayList<RegularFileObject>(); 1.358 for (File f: files) 1.359 - result.add(new RegularFileObject(nullCheck(f))); 1.360 + result.add(new RegularFileObject(this, nullCheck(f))); 1.361 return result; 1.362 } 1.363 1.364 @@ -1268,452 +1144,4 @@ 1.365 t.getClass(); // null check 1.366 return it; 1.367 } 1.368 - 1.369 - /** 1.370 - * A subclass of JavaFileObject representing regular files. 1.371 - */ 1.372 - private class RegularFileObject extends BaseFileObject { 1.373 - /** Have the parent directories been created? 1.374 - */ 1.375 - private boolean hasParents=false; 1.376 - 1.377 - /** The file's name. 1.378 - */ 1.379 - private String name; 1.380 - 1.381 - /** The underlying file. 1.382 - */ 1.383 - final File f; 1.384 - 1.385 - public RegularFileObject(File f) { 1.386 - this(f.getName(), f); 1.387 - } 1.388 - 1.389 - public RegularFileObject(String name, File f) { 1.390 - if (f.isDirectory()) 1.391 - throw new IllegalArgumentException("directories not supported"); 1.392 - this.name = name; 1.393 - this.f = f; 1.394 - } 1.395 - 1.396 - public InputStream openInputStream() throws IOException { 1.397 - return new FileInputStream(f); 1.398 - } 1.399 - 1.400 - protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) { 1.401 - return JavacFileManager.this.getDecoder(getEncodingName(), ignoreEncodingErrors); 1.402 - } 1.403 - 1.404 - public OutputStream openOutputStream() throws IOException { 1.405 - ensureParentDirectoriesExist(); 1.406 - return new FileOutputStream(f); 1.407 - } 1.408 - 1.409 - public Writer openWriter() throws IOException { 1.410 - ensureParentDirectoriesExist(); 1.411 - return new OutputStreamWriter(new FileOutputStream(f), getEncodingName()); 1.412 - } 1.413 - 1.414 - private void ensureParentDirectoriesExist() throws IOException { 1.415 - if (!hasParents) { 1.416 - File parent = f.getParentFile(); 1.417 - if (parent != null && !parent.exists()) { 1.418 - if (!parent.mkdirs()) { 1.419 - // if the mkdirs failed, it may be because another process concurrently 1.420 - // created the directory, so check if the directory got created 1.421 - // anyway before throwing an exception 1.422 - if (!parent.exists() || !parent.isDirectory()) 1.423 - throw new IOException("could not create parent directories"); 1.424 - } 1.425 - } 1.426 - hasParents = true; 1.427 - } 1.428 - } 1.429 - 1.430 - /** @deprecated see bug 6410637 */ 1.431 - @Deprecated 1.432 - public String getName() { 1.433 - return name; 1.434 - } 1.435 - 1.436 - public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) { 1.437 - cn.getClass(); // null check 1.438 - if (kind == Kind.OTHER && getKind() != kind) 1.439 - return false; 1.440 - String n = cn + kind.extension; 1.441 - if (name.equals(n)) 1.442 - return true; 1.443 - if (name.equalsIgnoreCase(n)) { 1.444 - try { 1.445 - // allow for Windows 1.446 - return (f.getCanonicalFile().getName().equals(n)); 1.447 - } catch (IOException e) { 1.448 - } 1.449 - } 1.450 - return false; 1.451 - } 1.452 - 1.453 - /** @deprecated see bug 6410637 */ 1.454 - @Deprecated 1.455 - public String getPath() { 1.456 - return f.getPath(); 1.457 - } 1.458 - 1.459 - public long getLastModified() { 1.460 - return f.lastModified(); 1.461 - } 1.462 - 1.463 - public boolean delete() { 1.464 - return f.delete(); 1.465 - } 1.466 - 1.467 - public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException { 1.468 - SoftReference<CharBuffer> r = contentCache.get(this); 1.469 - CharBuffer cb = (r == null ? null : r.get()); 1.470 - if (cb == null) { 1.471 - InputStream in = new FileInputStream(f); 1.472 - try { 1.473 - ByteBuffer bb = makeByteBuffer(in); 1.474 - JavaFileObject prev = log.useSource(this); 1.475 - try { 1.476 - cb = decode(bb, ignoreEncodingErrors); 1.477 - } finally { 1.478 - log.useSource(prev); 1.479 - } 1.480 - byteBufferCache.put(bb); // save for next time 1.481 - if (!ignoreEncodingErrors) 1.482 - contentCache.put(this, new SoftReference<CharBuffer>(cb)); 1.483 - } finally { 1.484 - in.close(); 1.485 - } 1.486 - } 1.487 - return cb; 1.488 - } 1.489 - 1.490 - @Override 1.491 - public boolean equals(Object other) { 1.492 - if (!(other instanceof RegularFileObject)) 1.493 - return false; 1.494 - RegularFileObject o = (RegularFileObject) other; 1.495 - try { 1.496 - return f.equals(o.f) 1.497 - || f.getCanonicalFile().equals(o.f.getCanonicalFile()); 1.498 - } catch (IOException e) { 1.499 - return false; 1.500 - } 1.501 - } 1.502 - 1.503 - @Override 1.504 - public int hashCode() { 1.505 - return f.hashCode(); 1.506 - } 1.507 - 1.508 - public URI toUri() { 1.509 - try { 1.510 - // Do no use File.toURI to avoid file system access 1.511 - String path = f.getAbsolutePath().replace(File.separatorChar, '/'); 1.512 - return new URI("file://" + path).normalize(); 1.513 - } catch (URISyntaxException ex) { 1.514 - return f.toURI(); 1.515 - } 1.516 - } 1.517 - 1.518 - } 1.519 - 1.520 - /** 1.521 - * A subclass of JavaFileObject representing zip entries. 1.522 - */ 1.523 - public class ZipFileObject extends BaseFileObject { 1.524 - 1.525 - /** The entry's name. 1.526 - */ 1.527 - private String name; 1.528 - 1.529 - /** The zipfile containing the entry. 1.530 - */ 1.531 - ZipFile zdir; 1.532 - 1.533 - /** The underlying zip entry object. 1.534 - */ 1.535 - ZipEntry entry; 1.536 - 1.537 - public ZipFileObject(String name, ZipFile zdir, ZipEntry entry) { 1.538 - this.name = name; 1.539 - this.zdir = zdir; 1.540 - this.entry = entry; 1.541 - } 1.542 - 1.543 - public InputStream openInputStream() throws IOException { 1.544 - return zdir.getInputStream(entry); 1.545 - } 1.546 - 1.547 - public OutputStream openOutputStream() throws IOException { 1.548 - throw new UnsupportedOperationException(); 1.549 - } 1.550 - 1.551 - protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) { 1.552 - return JavacFileManager.this.getDecoder(getEncodingName(), ignoreEncodingErrors); 1.553 - } 1.554 - 1.555 - public Writer openWriter() throws IOException { 1.556 - throw new UnsupportedOperationException(); 1.557 - } 1.558 - 1.559 - /** @deprecated see bug 6410637 */ 1.560 - @Deprecated 1.561 - public String getName() { 1.562 - return name; 1.563 - } 1.564 - 1.565 - public boolean isNameCompatible(String cn, JavaFileObject.Kind k) { 1.566 - cn.getClass(); // null check 1.567 - if (k == Kind.OTHER && getKind() != k) 1.568 - return false; 1.569 - return name.equals(cn + k.extension); 1.570 - } 1.571 - 1.572 - /** @deprecated see bug 6410637 */ 1.573 - @Deprecated 1.574 - public String getPath() { 1.575 - return zdir.getName() + "(" + entry + ")"; 1.576 - } 1.577 - 1.578 - public long getLastModified() { 1.579 - return entry.getTime(); 1.580 - } 1.581 - 1.582 - public boolean delete() { 1.583 - throw new UnsupportedOperationException(); 1.584 - } 1.585 - 1.586 - public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException { 1.587 - SoftReference<CharBuffer> r = contentCache.get(this); 1.588 - CharBuffer cb = (r == null ? null : r.get()); 1.589 - if (cb == null) { 1.590 - InputStream in = zdir.getInputStream(entry); 1.591 - try { 1.592 - ByteBuffer bb = makeByteBuffer(in); 1.593 - JavaFileObject prev = log.useSource(this); 1.594 - try { 1.595 - cb = decode(bb, ignoreEncodingErrors); 1.596 - } finally { 1.597 - log.useSource(prev); 1.598 - } 1.599 - byteBufferCache.put(bb); // save for next time 1.600 - if (!ignoreEncodingErrors) 1.601 - contentCache.put(this, new SoftReference<CharBuffer>(cb)); 1.602 - } finally { 1.603 - in.close(); 1.604 - } 1.605 - } 1.606 - return cb; 1.607 - } 1.608 - 1.609 - @Override 1.610 - public boolean equals(Object other) { 1.611 - if (!(other instanceof ZipFileObject)) 1.612 - return false; 1.613 - ZipFileObject o = (ZipFileObject) other; 1.614 - return zdir.equals(o.zdir) || name.equals(o.name); 1.615 - } 1.616 - 1.617 - @Override 1.618 - public int hashCode() { 1.619 - return zdir.hashCode() + name.hashCode(); 1.620 - } 1.621 - 1.622 - public String getZipName() { 1.623 - return zdir.getName(); 1.624 - } 1.625 - 1.626 - public String getZipEntryName() { 1.627 - return entry.getName(); 1.628 - } 1.629 - 1.630 - public URI toUri() { 1.631 - String zipName = new File(getZipName()).toURI().normalize().getPath(); 1.632 - String entryName = getZipEntryName(); 1.633 - return URI.create("jar:" + zipName + "!" + entryName); 1.634 - } 1.635 - 1.636 - } 1.637 - 1.638 - /** 1.639 - * A subclass of JavaFileObject representing zip entries using the com.sun.tools.javac.zip.ZipFileIndex implementation. 1.640 - */ 1.641 - public class ZipFileIndexFileObject extends BaseFileObject { 1.642 - 1.643 - /** The entry's name. 1.644 - */ 1.645 - private String name; 1.646 - 1.647 - /** The zipfile containing the entry. 1.648 - */ 1.649 - ZipFileIndex zfIndex; 1.650 - 1.651 - /** The underlying zip entry object. 1.652 - */ 1.653 - ZipFileIndexEntry entry; 1.654 - 1.655 - /** The InputStream for this zip entry (file.) 1.656 - */ 1.657 - InputStream inputStream = null; 1.658 - 1.659 - /** The name of the zip file where this entry resides. 1.660 - */ 1.661 - String zipName; 1.662 - 1.663 - JavacFileManager defFileManager = null; 1.664 - 1.665 - public ZipFileIndexFileObject(JavacFileManager fileManager, ZipFileIndex zfIndex, ZipFileIndexEntry entry, String zipFileName) { 1.666 - super(); 1.667 - this.name = entry.getFileName(); 1.668 - this.zfIndex = zfIndex; 1.669 - this.entry = entry; 1.670 - this.zipName = zipFileName; 1.671 - defFileManager = fileManager; 1.672 - } 1.673 - 1.674 - public InputStream openInputStream() throws IOException { 1.675 - 1.676 - if (inputStream == null) { 1.677 - inputStream = new ByteArrayInputStream(read()); 1.678 - } 1.679 - return inputStream; 1.680 - } 1.681 - 1.682 - protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) { 1.683 - return JavacFileManager.this.getDecoder(getEncodingName(), ignoreEncodingErrors); 1.684 - } 1.685 - 1.686 - public OutputStream openOutputStream() throws IOException { 1.687 - throw new UnsupportedOperationException(); 1.688 - } 1.689 - 1.690 - public Writer openWriter() throws IOException { 1.691 - throw new UnsupportedOperationException(); 1.692 - } 1.693 - 1.694 - /** @deprecated see bug 6410637 */ 1.695 - @Deprecated 1.696 - public String getName() { 1.697 - return name; 1.698 - } 1.699 - 1.700 - public boolean isNameCompatible(String cn, JavaFileObject.Kind k) { 1.701 - cn.getClass(); // null check 1.702 - if (k == Kind.OTHER && getKind() != k) 1.703 - return false; 1.704 - return name.equals(cn + k.extension); 1.705 - } 1.706 - 1.707 - /** @deprecated see bug 6410637 */ 1.708 - @Deprecated 1.709 - public String getPath() { 1.710 - return zipName + "(" + entry.getName() + ")"; 1.711 - } 1.712 - 1.713 - public long getLastModified() { 1.714 - return entry.getLastModified(); 1.715 - } 1.716 - 1.717 - public boolean delete() { 1.718 - throw new UnsupportedOperationException(); 1.719 - } 1.720 - 1.721 - @Override 1.722 - public boolean equals(Object other) { 1.723 - if (!(other instanceof ZipFileIndexFileObject)) 1.724 - return false; 1.725 - ZipFileIndexFileObject o = (ZipFileIndexFileObject) other; 1.726 - return entry.equals(o.entry); 1.727 - } 1.728 - 1.729 - @Override 1.730 - public int hashCode() { 1.731 - return zipName.hashCode() + (name.hashCode() << 10); 1.732 - } 1.733 - 1.734 - public String getZipName() { 1.735 - return zipName; 1.736 - } 1.737 - 1.738 - public String getZipEntryName() { 1.739 - return entry.getName(); 1.740 - } 1.741 - 1.742 - public URI toUri() { 1.743 - String zipName = new File(getZipName()).toURI().normalize().getPath(); 1.744 - String entryName = getZipEntryName(); 1.745 - if (File.separatorChar != '/') { 1.746 - entryName = entryName.replace(File.separatorChar, '/'); 1.747 - } 1.748 - return URI.create("jar:" + zipName + "!" + entryName); 1.749 - } 1.750 - 1.751 - private byte[] read() throws IOException { 1.752 - if (entry == null) { 1.753 - entry = zfIndex.getZipIndexEntry(name); 1.754 - if (entry == null) 1.755 - throw new FileNotFoundException(); 1.756 - } 1.757 - return zfIndex.read(entry); 1.758 - } 1.759 - 1.760 - public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException { 1.761 - SoftReference<CharBuffer> r = defFileManager.contentCache.get(this); 1.762 - CharBuffer cb = (r == null ? null : r.get()); 1.763 - if (cb == null) { 1.764 - InputStream in = new ByteArrayInputStream(zfIndex.read(entry)); 1.765 - try { 1.766 - ByteBuffer bb = makeByteBuffer(in); 1.767 - JavaFileObject prev = log.useSource(this); 1.768 - try { 1.769 - cb = decode(bb, ignoreEncodingErrors); 1.770 - } finally { 1.771 - log.useSource(prev); 1.772 - } 1.773 - byteBufferCache.put(bb); // save for next time 1.774 - if (!ignoreEncodingErrors) 1.775 - defFileManager.contentCache.put(this, new SoftReference<CharBuffer>(cb)); 1.776 - } finally { 1.777 - in.close(); 1.778 - } 1.779 - } 1.780 - return cb; 1.781 - } 1.782 - } 1.783 - 1.784 - public class ZipFileIndexArchive implements Archive { 1.785 - private final ZipFileIndex zfIndex; 1.786 - private JavacFileManager fileManager; 1.787 - 1.788 - public ZipFileIndexArchive(JavacFileManager fileManager, ZipFileIndex zdir) throws IOException { 1.789 - this.fileManager = fileManager; 1.790 - this.zfIndex = zdir; 1.791 - } 1.792 - 1.793 - public boolean contains(String name) { 1.794 - return zfIndex.contains(name); 1.795 - } 1.796 - 1.797 - public com.sun.tools.javac.util.List<String> getFiles(String subdirectory) { 1.798 - return zfIndex.getFiles(((subdirectory.endsWith("/") || subdirectory.endsWith("\\"))? subdirectory.substring(0, subdirectory.length() - 1) : subdirectory)); 1.799 - } 1.800 - 1.801 - public JavaFileObject getFileObject(String subdirectory, String file) { 1.802 - String fullZipFileName = subdirectory + file; 1.803 - ZipFileIndexEntry entry = zfIndex.getZipIndexEntry(fullZipFileName); 1.804 - JavaFileObject ret = new ZipFileIndexFileObject(fileManager, zfIndex, entry, zfIndex.getZipFile().getPath()); 1.805 - return ret; 1.806 - } 1.807 - 1.808 - public Set<String> getSubdirectories() { 1.809 - return zfIndex.getAllDirectories(); 1.810 - } 1.811 - 1.812 - public void close() throws IOException { 1.813 - zfIndex.close(); 1.814 - } 1.815 - } 1.816 }