121 this.zfIndex = zfIndex; |
121 this.zfIndex = zfIndex; |
122 this.entry = entry; |
122 this.entry = entry; |
123 this.zipName = zipFileName; |
123 this.zipName = zipFileName; |
124 } |
124 } |
125 |
125 |
|
126 @Override |
|
127 public URI toUri() { |
|
128 return createJarUri(zipName, getPrefixedEntryName()); |
|
129 } |
|
130 |
|
131 @Override |
|
132 public String getName() { |
|
133 return zipName + "(" + getPrefixedEntryName() + ")"; |
|
134 } |
|
135 |
|
136 @Override |
|
137 public String getShortName() { |
|
138 return zipName.getName() + "(" + entry.getName() + ")"; |
|
139 } |
|
140 |
|
141 @Override |
|
142 public JavaFileObject.Kind getKind() { |
|
143 return getKind(entry.getName()); |
|
144 } |
|
145 |
|
146 @Override |
126 public InputStream openInputStream() throws IOException { |
147 public InputStream openInputStream() throws IOException { |
127 |
|
128 if (inputStream == null) { |
148 if (inputStream == null) { |
129 inputStream = new ByteArrayInputStream(read()); |
149 assert entry != null; // see constructor |
|
150 inputStream = new ByteArrayInputStream(zfIndex.read(entry)); |
130 } |
151 } |
131 return inputStream; |
152 return inputStream; |
132 } |
153 } |
133 |
154 |
134 @Override |
155 @Override |
135 protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) { |
|
136 return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors); |
|
137 } |
|
138 |
|
139 public OutputStream openOutputStream() throws IOException { |
156 public OutputStream openOutputStream() throws IOException { |
140 throw new UnsupportedOperationException(); |
157 throw new UnsupportedOperationException(); |
141 } |
158 } |
142 |
159 |
143 public Writer openWriter() throws IOException { |
160 @Override |
144 throw new UnsupportedOperationException(); |
|
145 } |
|
146 |
|
147 /** @deprecated see bug 6410637 */ |
|
148 @Deprecated |
|
149 public String getName() { |
|
150 return name; |
|
151 } |
|
152 |
|
153 public boolean isNameCompatible(String cn, JavaFileObject.Kind k) { |
|
154 cn.getClass(); // null check |
|
155 if (k == Kind.OTHER && getKind() != k) |
|
156 return false; |
|
157 return name.equals(cn + k.extension); |
|
158 } |
|
159 |
|
160 /** @deprecated see bug 6410637 */ |
|
161 @Deprecated |
|
162 @Override |
|
163 public String getPath() { |
|
164 return zipName + "(" + entry.getName() + ")"; |
|
165 } |
|
166 |
|
167 public long getLastModified() { |
|
168 return entry.getLastModified(); |
|
169 } |
|
170 |
|
171 public boolean delete() { |
|
172 throw new UnsupportedOperationException(); |
|
173 } |
|
174 |
|
175 @Override |
|
176 public boolean equals(Object other) { |
|
177 if (!(other instanceof ZipFileIndexFileObject)) |
|
178 return false; |
|
179 ZipFileIndexFileObject o = (ZipFileIndexFileObject) other; |
|
180 return entry.equals(o.entry); |
|
181 } |
|
182 |
|
183 @Override |
|
184 public int hashCode() { |
|
185 return zipName.hashCode() + (name.hashCode() << 10); |
|
186 } |
|
187 |
|
188 public String getZipName() { |
|
189 return zipName.getPath(); |
|
190 } |
|
191 |
|
192 public String getZipEntryName() { |
|
193 return entry.getName(); |
|
194 } |
|
195 |
|
196 public URI toUri() { |
|
197 if (zfIndex.symbolFilePrefix != null) |
|
198 return createJarUri(zipName, zfIndex.symbolFilePrefix.path + entry.getName()); |
|
199 else |
|
200 return createJarUri(zipName, entry.getName()); |
|
201 } |
|
202 |
|
203 private byte[] read() throws IOException { |
|
204 assert entry != null; // see constructor |
|
205 return zfIndex.read(entry); |
|
206 } |
|
207 |
|
208 public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException { |
161 public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException { |
209 CharBuffer cb = fileManager.getCachedContent(this); |
162 CharBuffer cb = fileManager.getCachedContent(this); |
210 if (cb == null) { |
163 if (cb == null) { |
211 InputStream in = new ByteArrayInputStream(zfIndex.read(entry)); |
164 InputStream in = new ByteArrayInputStream(zfIndex.read(entry)); |
212 try { |
165 try { |
226 } |
179 } |
227 return cb; |
180 return cb; |
228 } |
181 } |
229 |
182 |
230 @Override |
183 @Override |
|
184 public Writer openWriter() throws IOException { |
|
185 throw new UnsupportedOperationException(); |
|
186 } |
|
187 |
|
188 @Override |
|
189 public long getLastModified() { |
|
190 return entry.getLastModified(); |
|
191 } |
|
192 |
|
193 @Override |
|
194 public boolean delete() { |
|
195 throw new UnsupportedOperationException(); |
|
196 } |
|
197 |
|
198 @Override |
|
199 protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) { |
|
200 return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors); |
|
201 } |
|
202 |
|
203 @Override |
231 protected String inferBinaryName(Iterable<? extends File> path) { |
204 protected String inferBinaryName(Iterable<? extends File> path) { |
232 String entryName = getZipEntryName(); |
205 String entryName = entry.getName(); |
233 if (zfIndex.symbolFilePrefix != null) { |
206 if (zfIndex.symbolFilePrefix != null) { |
234 String prefix = zfIndex.symbolFilePrefix.path; |
207 String prefix = zfIndex.symbolFilePrefix.path; |
235 if (entryName.startsWith(prefix)) |
208 if (entryName.startsWith(prefix)) |
236 entryName = entryName.substring(prefix.length()); |
209 entryName = entryName.substring(prefix.length()); |
237 } |
210 } |
238 return removeExtension(entryName).replace('/', '.'); |
211 return removeExtension(entryName).replace('/', '.'); |
239 } |
212 } |
|
213 |
|
214 @Override |
|
215 public boolean isNameCompatible(String cn, JavaFileObject.Kind k) { |
|
216 cn.getClass(); // null check |
|
217 if (k == Kind.OTHER && getKind() != k) |
|
218 return false; |
|
219 return name.equals(cn + k.extension); |
|
220 } |
|
221 |
|
222 @Override |
|
223 public boolean equals(Object other) { |
|
224 if (!(other instanceof ZipFileIndexFileObject)) |
|
225 return false; |
|
226 ZipFileIndexFileObject o = (ZipFileIndexFileObject) other; |
|
227 return entry.equals(o.entry); |
|
228 } |
|
229 |
|
230 @Override |
|
231 public int hashCode() { |
|
232 return zipName.hashCode() + (name.hashCode() << 10); |
|
233 } |
|
234 |
|
235 private String getPrefixedEntryName() { |
|
236 if (zfIndex.symbolFilePrefix != null) |
|
237 return zfIndex.symbolFilePrefix.path + entry.getName(); |
|
238 else |
|
239 return entry.getName(); |
|
240 } |
240 } |
241 } |
241 |
242 |
242 } |
243 } |