langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipArchive.java
changeset 26266 2d24bda701dc
parent 25874 83c19f00452c
child 27225 8369cde9152a
equal deleted inserted replaced
26265:46aacfffd3b5 26266:2d24bda701dc
    44 import javax.tools.JavaFileObject;
    44 import javax.tools.JavaFileObject;
    45 
    45 
    46 import com.sun.tools.javac.file.JavacFileManager.Archive;
    46 import com.sun.tools.javac.file.JavacFileManager.Archive;
    47 import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
    47 import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
    48 import com.sun.tools.javac.file.RelativePath.RelativeFile;
    48 import com.sun.tools.javac.file.RelativePath.RelativeFile;
       
    49 import com.sun.tools.javac.util.DefinedBy;
       
    50 import com.sun.tools.javac.util.DefinedBy.Api;
    49 import com.sun.tools.javac.util.List;
    51 import com.sun.tools.javac.util.List;
    50 import java.lang.ref.Reference;
    52 import java.lang.ref.Reference;
    51 import java.lang.ref.SoftReference;
    53 import java.lang.ref.SoftReference;
    52 
    54 
    53 /**
    55 /**
   169             this.zarch = zarch;
   171             this.zarch = zarch;
   170             this.name = name;
   172             this.name = name;
   171             this.entry = entry;
   173             this.entry = entry;
   172         }
   174         }
   173 
   175 
       
   176         @DefinedBy(Api.COMPILER)
   174         public URI toUri() {
   177         public URI toUri() {
   175             File zipFile = new File(zarch.zfile.getName());
   178             File zipFile = new File(zarch.zfile.getName());
   176             return createJarUri(zipFile, entry.getName());
   179             return createJarUri(zipFile, entry.getName());
   177         }
   180         }
   178 
   181 
   179         @Override
   182         @Override @DefinedBy(Api.COMPILER)
   180         public String getName() {
   183         public String getName() {
   181             return zarch.zfile.getName() + "(" + entry.getName() + ")";
   184             return zarch.zfile.getName() + "(" + entry.getName() + ")";
   182         }
   185         }
   183 
   186 
   184         @Override
   187         @Override
   185         public String getShortName() {
   188         public String getShortName() {
   186             return new File(zarch.zfile.getName()).getName() + "(" + entry + ")";
   189             return new File(zarch.zfile.getName()).getName() + "(" + entry + ")";
   187         }
   190         }
   188 
   191 
   189         @Override
   192         @Override @DefinedBy(Api.COMPILER)
   190         public JavaFileObject.Kind getKind() {
   193         public JavaFileObject.Kind getKind() {
   191             return getKind(entry.getName());
   194             return getKind(entry.getName());
   192         }
   195         }
   193 
   196 
   194         @Override
   197         @Override @DefinedBy(Api.COMPILER)
   195         public InputStream openInputStream() throws IOException {
   198         public InputStream openInputStream() throws IOException {
   196             return zarch.zfile.getInputStream(entry);
   199             return zarch.zfile.getInputStream(entry);
   197         }
   200         }
   198 
   201 
   199         @Override
   202         @Override @DefinedBy(Api.COMPILER)
   200         public OutputStream openOutputStream() throws IOException {
   203         public OutputStream openOutputStream() throws IOException {
   201             throw new UnsupportedOperationException();
   204             throw new UnsupportedOperationException();
   202         }
   205         }
   203 
   206 
   204         @Override
   207         @Override @DefinedBy(Api.COMPILER)
   205         public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
   208         public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
   206             CharBuffer cb = fileManager.getCachedContent(this);
   209             CharBuffer cb = fileManager.getCachedContent(this);
   207             if (cb == null) {
   210             if (cb == null) {
   208                 try (InputStream in = zarch.zfile.getInputStream(entry)) {
   211                 try (InputStream in = zarch.zfile.getInputStream(entry)) {
   209                     ByteBuffer bb = fileManager.makeByteBuffer(in);
   212                     ByteBuffer bb = fileManager.makeByteBuffer(in);
   220                 }
   223                 }
   221             }
   224             }
   222             return cb;
   225             return cb;
   223         }
   226         }
   224 
   227 
   225         @Override
   228         @Override @DefinedBy(Api.COMPILER)
   226         public Writer openWriter() throws IOException {
   229         public Writer openWriter() throws IOException {
   227             throw new UnsupportedOperationException();
   230             throw new UnsupportedOperationException();
   228         }
   231         }
   229 
   232 
   230         @Override
   233         @Override @DefinedBy(Api.COMPILER)
   231         public long getLastModified() {
   234         public long getLastModified() {
   232             return entry.getTime();
   235             return entry.getTime();
   233         }
   236         }
   234 
   237 
   235         @Override
   238         @Override @DefinedBy(Api.COMPILER)
   236         public boolean delete() {
   239         public boolean delete() {
   237             throw new UnsupportedOperationException();
   240             throw new UnsupportedOperationException();
   238         }
   241         }
   239 
   242 
   240         @Override
   243         @Override
   246         protected String inferBinaryName(Iterable<? extends File> path) {
   249         protected String inferBinaryName(Iterable<? extends File> path) {
   247             String entryName = entry.getName();
   250             String entryName = entry.getName();
   248             return removeExtension(entryName).replace('/', '.');
   251             return removeExtension(entryName).replace('/', '.');
   249         }
   252         }
   250 
   253 
   251         @Override
   254         @Override @DefinedBy(Api.COMPILER)
   252         public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
   255         public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
   253             cn.getClass();
   256             cn.getClass();
   254             // null check
   257             // null check
   255             if (k == Kind.OTHER && getKind() != k) {
   258             if (k == Kind.OTHER && getKind() != k) {
   256                 return false;
   259                 return false;