41 |
41 |
42 import com.sun.tools.javac.file.JavacFileManager.Archive; |
42 import com.sun.tools.javac.file.JavacFileManager.Archive; |
43 import com.sun.tools.javac.file.RelativePath.RelativeDirectory; |
43 import com.sun.tools.javac.file.RelativePath.RelativeDirectory; |
44 import com.sun.tools.javac.file.RelativePath.RelativeFile; |
44 import com.sun.tools.javac.file.RelativePath.RelativeFile; |
45 import com.sun.tools.javac.util.Assert; |
45 import com.sun.tools.javac.util.Assert; |
|
46 import com.sun.tools.javac.util.DefinedBy; |
|
47 import com.sun.tools.javac.util.DefinedBy.Api; |
46 import com.sun.tools.javac.util.List; |
48 import com.sun.tools.javac.util.List; |
47 |
49 |
48 /** |
50 /** |
49 * <p><b>This is NOT part of any supported API. |
51 * <p><b>This is NOT part of any supported API. |
50 * If you write code that depends on this, you do so at your own risk. |
52 * If you write code that depends on this, you do so at your own risk. |
118 this.zfIndex = zfIndex; |
120 this.zfIndex = zfIndex; |
119 this.entry = entry; |
121 this.entry = entry; |
120 this.zipName = zipFileName; |
122 this.zipName = zipFileName; |
121 } |
123 } |
122 |
124 |
123 @Override |
125 @Override @DefinedBy(Api.COMPILER) |
124 public URI toUri() { |
126 public URI toUri() { |
125 return createJarUri(zipName, getPrefixedEntryName()); |
127 return createJarUri(zipName, getPrefixedEntryName()); |
126 } |
128 } |
127 |
129 |
128 @Override |
130 @Override @DefinedBy(Api.COMPILER) |
129 public String getName() { |
131 public String getName() { |
130 return zipName + "(" + getPrefixedEntryName() + ")"; |
132 return zipName + "(" + getPrefixedEntryName() + ")"; |
131 } |
133 } |
132 |
134 |
133 @Override |
135 @Override |
134 public String getShortName() { |
136 public String getShortName() { |
135 return zipName.getName() + "(" + entry.getName() + ")"; |
137 return zipName.getName() + "(" + entry.getName() + ")"; |
136 } |
138 } |
137 |
139 |
138 @Override |
140 @Override @DefinedBy(Api.COMPILER) |
139 public JavaFileObject.Kind getKind() { |
141 public JavaFileObject.Kind getKind() { |
140 return getKind(entry.getName()); |
142 return getKind(entry.getName()); |
141 } |
143 } |
142 |
144 |
143 @Override |
145 @Override @DefinedBy(Api.COMPILER) |
144 public InputStream openInputStream() throws IOException { |
146 public InputStream openInputStream() throws IOException { |
145 Assert.checkNonNull(entry); // see constructor |
147 Assert.checkNonNull(entry); // see constructor |
146 return new ByteArrayInputStream(zfIndex.read(entry)); |
148 return new ByteArrayInputStream(zfIndex.read(entry)); |
147 } |
149 } |
148 |
150 |
149 @Override |
151 @Override @DefinedBy(Api.COMPILER) |
150 public OutputStream openOutputStream() throws IOException { |
152 public OutputStream openOutputStream() throws IOException { |
151 throw new UnsupportedOperationException(); |
153 throw new UnsupportedOperationException(); |
152 } |
154 } |
153 |
155 |
154 @Override |
156 @Override @DefinedBy(Api.COMPILER) |
155 public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException { |
157 public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException { |
156 CharBuffer cb = fileManager.getCachedContent(this); |
158 CharBuffer cb = fileManager.getCachedContent(this); |
157 if (cb == null) { |
159 if (cb == null) { |
158 try (InputStream in = new ByteArrayInputStream(zfIndex.read(entry))) { |
160 try (InputStream in = new ByteArrayInputStream(zfIndex.read(entry))) { |
159 ByteBuffer bb = fileManager.makeByteBuffer(in); |
161 ByteBuffer bb = fileManager.makeByteBuffer(in); |
169 } |
171 } |
170 } |
172 } |
171 return cb; |
173 return cb; |
172 } |
174 } |
173 |
175 |
174 @Override |
176 @Override @DefinedBy(Api.COMPILER) |
175 public Writer openWriter() throws IOException { |
177 public Writer openWriter() throws IOException { |
176 throw new UnsupportedOperationException(); |
178 throw new UnsupportedOperationException(); |
177 } |
179 } |
178 |
180 |
179 @Override |
181 @Override @DefinedBy(Api.COMPILER) |
180 public long getLastModified() { |
182 public long getLastModified() { |
181 return entry.getLastModified(); |
183 return entry.getLastModified(); |
182 } |
184 } |
183 |
185 |
184 @Override |
186 @Override @DefinedBy(Api.COMPILER) |
185 public boolean delete() { |
187 public boolean delete() { |
186 throw new UnsupportedOperationException(); |
188 throw new UnsupportedOperationException(); |
187 } |
189 } |
188 |
190 |
189 @Override |
191 @Override |
200 entryName = entryName.substring(prefix.length()); |
202 entryName = entryName.substring(prefix.length()); |
201 } |
203 } |
202 return removeExtension(entryName).replace('/', '.'); |
204 return removeExtension(entryName).replace('/', '.'); |
203 } |
205 } |
204 |
206 |
205 @Override |
207 @Override @DefinedBy(Api.COMPILER) |
206 public boolean isNameCompatible(String cn, JavaFileObject.Kind k) { |
208 public boolean isNameCompatible(String cn, JavaFileObject.Kind k) { |
207 cn.getClass(); // null check |
209 cn.getClass(); // null check |
208 if (k == Kind.OTHER && getKind() != k) |
210 if (k == Kind.OTHER && getKind() != k) |
209 return false; |
211 return false; |
210 return name.equals(cn + k.extension); |
212 return name.equals(cn + k.extension); |