author | mchung |
Fri, 20 Jun 2014 13:36:10 -0700 | |
changeset 25303 | 5f9e68207588 |
parent 22163 | 3651128c74eb |
permissions | -rw-r--r-- |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
1 |
/* |
5520 | 2 |
* Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved. |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
4 |
* |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
10 |
* |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
16 |
* |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
20 |
* |
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
24 |
*/ |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
25 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.file; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
27 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
28 |
import java.io.File; |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
29 |
import java.io.IOException; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
30 |
import java.io.InputStream; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
31 |
import java.io.OutputStream; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
32 |
import java.io.Writer; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
33 |
import java.net.URI; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
34 |
import java.nio.ByteBuffer; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
35 |
import java.nio.CharBuffer; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
36 |
import java.nio.charset.CharsetDecoder; |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
37 |
import java.util.Enumeration; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
38 |
import java.util.HashMap; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
39 |
import java.util.Map; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
40 |
import java.util.Set; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
41 |
import java.util.zip.ZipEntry; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
42 |
import java.util.zip.ZipFile; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
43 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
44 |
import javax.tools.JavaFileObject; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
45 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
46 |
import com.sun.tools.javac.file.JavacFileManager.Archive; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
47 |
import com.sun.tools.javac.file.RelativePath.RelativeDirectory; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
48 |
import com.sun.tools.javac.file.RelativePath.RelativeFile; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
49 |
import com.sun.tools.javac.util.List; |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
50 |
import java.lang.ref.Reference; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
51 |
import java.lang.ref.SoftReference; |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
52 |
|
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1205
diff
changeset
|
53 |
/** |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
54 |
* <p><b>This is NOT part of any supported API. |
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1205
diff
changeset
|
55 |
* If you write code that depends on this, you do so at your own risk. |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1205
diff
changeset
|
56 |
* This code and its internal interfaces are subject to change or |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1205
diff
changeset
|
57 |
* deletion without notice.</b> |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1205
diff
changeset
|
58 |
*/ |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
59 |
public class ZipArchive implements Archive { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
60 |
|
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
61 |
public ZipArchive(JavacFileManager fm, ZipFile zfile) throws IOException { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
62 |
this(fm, zfile, true); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
63 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
64 |
|
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
65 |
protected ZipArchive(JavacFileManager fm, ZipFile zfile, boolean initMap) throws IOException { |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
66 |
this.fileManager = fm; |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
67 |
this.zfile = zfile; |
22163 | 68 |
this.map = new HashMap<>(); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
69 |
if (initMap) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
70 |
initMap(); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
71 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
72 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
73 |
protected void initMap() throws IOException { |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
74 |
for (Enumeration<? extends ZipEntry> e = zfile.entries(); e.hasMoreElements(); ) { |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
75 |
ZipEntry entry; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
76 |
try { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
77 |
entry = e.nextElement(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
78 |
} catch (InternalError ex) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
79 |
IOException io = new IOException(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
80 |
io.initCause(ex); // convenience constructors added in Mustang :-( |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
81 |
throw io; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
82 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
83 |
addZipEntry(entry); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
84 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
85 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
86 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
87 |
void addZipEntry(ZipEntry entry) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
88 |
String name = entry.getName(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
89 |
int i = name.lastIndexOf('/'); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
90 |
RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1)); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
91 |
String basename = name.substring(i+1); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
92 |
if (basename.length() == 0) |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
93 |
return; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
94 |
List<String> list = map.get(dirname); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
95 |
if (list == null) |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
96 |
list = List.nil(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
97 |
list = list.prepend(basename); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
98 |
map.put(dirname, list); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
99 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
100 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
101 |
public boolean contains(RelativePath name) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
102 |
RelativeDirectory dirname = name.dirname(); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
103 |
String basename = name.basename(); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
104 |
if (basename.length() == 0) |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
105 |
return false; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
106 |
List<String> list = map.get(dirname); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
107 |
return (list != null && list.contains(basename)); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
108 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
109 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
110 |
public List<String> getFiles(RelativeDirectory subdirectory) { |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
111 |
return map.get(subdirectory); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
112 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
113 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
114 |
public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) { |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
115 |
ZipEntry ze = new RelativeFile(subdirectory, file).getZipEntry(zfile); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
116 |
return new ZipFileObject(this, file, ze); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
117 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
118 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
119 |
public Set<RelativeDirectory> getSubdirectories() { |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
120 |
return map.keySet(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
121 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
122 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
123 |
public void close() throws IOException { |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
124 |
zfile.close(); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
125 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
126 |
|
3782 | 127 |
@Override |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
128 |
public String toString() { |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
129 |
return "ZipArchive[" + zfile.getName() + "]"; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
130 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
131 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
132 |
private File getAbsoluteFile() { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
133 |
File absFile = (absFileRef == null ? null : absFileRef.get()); |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
134 |
if (absFile == null) { |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
135 |
absFile = new File(zfile.getName()).getAbsoluteFile(); |
22163 | 136 |
absFileRef = new SoftReference<>(absFile); |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
137 |
} |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
138 |
return absFile; |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
139 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
140 |
|
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
141 |
/** |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
142 |
* The file manager that created this archive. |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
143 |
*/ |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
144 |
protected JavacFileManager fileManager; |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
145 |
/** |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
146 |
* The index for the contents of this archive. |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
147 |
*/ |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
148 |
protected final Map<RelativeDirectory,List<String>> map; |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
149 |
/** |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
150 |
* The zip file for the archive. |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
151 |
*/ |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
152 |
protected final ZipFile zfile; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
153 |
/** |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
154 |
* A reference to the absolute filename for the zip file for the archive. |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
155 |
*/ |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
156 |
protected Reference<File> absFileRef; |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
157 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
158 |
/** |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
159 |
* A subclass of JavaFileObject representing zip entries. |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
160 |
*/ |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
161 |
public static class ZipFileObject extends BaseFileObject { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
162 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
163 |
private String name; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
164 |
ZipArchive zarch; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
165 |
ZipEntry entry; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
166 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
167 |
protected ZipFileObject(ZipArchive zarch, String name, ZipEntry entry) { |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
168 |
super(zarch.fileManager); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
169 |
this.zarch = zarch; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
170 |
this.name = name; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
171 |
this.entry = entry; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
172 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
173 |
|
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
174 |
public URI toUri() { |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
175 |
File zipFile = new File(zarch.zfile.getName()); |
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
176 |
return createJarUri(zipFile, entry.getName()); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
177 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
178 |
|
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
179 |
@Override |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
180 |
public String getName() { |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
181 |
return zarch.zfile.getName() + "(" + entry.getName() + ")"; |
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
182 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
183 |
|
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
184 |
@Override |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
185 |
public String getShortName() { |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
186 |
return new File(zarch.zfile.getName()).getName() + "(" + entry + ")"; |
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
187 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
188 |
|
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
189 |
@Override |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
190 |
public JavaFileObject.Kind getKind() { |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
191 |
return getKind(entry.getName()); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
192 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
193 |
|
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
194 |
@Override |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
195 |
public InputStream openInputStream() throws IOException { |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
196 |
return zarch.zfile.getInputStream(entry); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
197 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
198 |
|
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
199 |
@Override |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
200 |
public OutputStream openOutputStream() throws IOException { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
201 |
throw new UnsupportedOperationException(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
202 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
203 |
|
3782 | 204 |
@Override |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
205 |
public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
206 |
CharBuffer cb = fileManager.getCachedContent(this); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
207 |
if (cb == null) { |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
5847
diff
changeset
|
208 |
try (InputStream in = zarch.zfile.getInputStream(entry)) { |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
209 |
ByteBuffer bb = fileManager.makeByteBuffer(in); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
210 |
JavaFileObject prev = fileManager.log.useSource(this); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
211 |
try { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
212 |
cb = fileManager.decode(bb, ignoreEncodingErrors); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
213 |
} finally { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
214 |
fileManager.log.useSource(prev); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
215 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
216 |
fileManager.recycleByteBuffer(bb); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
217 |
if (!ignoreEncodingErrors) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
218 |
fileManager.cache(this, cb); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
219 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
220 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
221 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
222 |
return cb; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
223 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
224 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
225 |
@Override |
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
226 |
public Writer openWriter() throws IOException { |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
227 |
throw new UnsupportedOperationException(); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
228 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
229 |
|
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
230 |
@Override |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
231 |
public long getLastModified() { |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
232 |
return entry.getTime(); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
233 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
234 |
|
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
235 |
@Override |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
236 |
public boolean delete() { |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
237 |
throw new UnsupportedOperationException(); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
238 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
239 |
|
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
240 |
@Override |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
241 |
protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) { |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
242 |
return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
243 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
244 |
|
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
245 |
@Override |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
246 |
protected String inferBinaryName(Iterable<? extends File> path) { |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
247 |
String entryName = entry.getName(); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
248 |
return removeExtension(entryName).replace('/', '.'); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
249 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
250 |
|
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
251 |
@Override |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
252 |
public boolean isNameCompatible(String cn, JavaFileObject.Kind k) { |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
253 |
cn.getClass(); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
254 |
// null check |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
255 |
if (k == Kind.OTHER && getKind() != k) { |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
256 |
return false; |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
257 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
258 |
return name.equals(cn + k.extension); |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
259 |
} |
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
260 |
|
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
261 |
/** |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
262 |
* Check if two file objects are equal. |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
263 |
* Two ZipFileObjects are equal if the absolute paths of the underlying |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
264 |
* zip files are equal and if the paths within those zip files are equal. |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
265 |
*/ |
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
266 |
@Override |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
267 |
public boolean equals(Object other) { |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
268 |
if (this == other) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
269 |
return true; |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
270 |
|
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
271 |
if (!(other instanceof ZipFileObject)) |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
272 |
return false; |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
273 |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
274 |
ZipFileObject o = (ZipFileObject) other; |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
275 |
return zarch.getAbsoluteFile().equals(o.zarch.getAbsoluteFile()) |
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
276 |
&& name.equals(o.name); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
277 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
278 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
279 |
@Override |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
280 |
public int hashCode() { |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
281 |
return zarch.getAbsoluteFile().hashCode() + name.hashCode(); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
282 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
283 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
284 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
285 |
} |