author | erikj |
Wed, 07 Mar 2018 13:26:15 -0800 | |
changeset 49357 | aaedb8343784 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
27565 | 1 |
/* |
44034
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
2 |
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. |
27565 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
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. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.internal.jimage; |
|
27 |
||
36511 | 28 |
import java.nio.ByteBuffer; |
38582
8618f4ccb220
8156209: Add argument checks to BasicImageReader calls
jlaskey
parents:
36511
diff
changeset
|
29 |
import java.util.Objects; |
36511 | 30 |
|
31 |
/** |
|
32 |
* @implNote This class needs to maintain JDK 8 source compatibility. |
|
33 |
* |
|
34 |
* It is used internally in the JDK to implement jimage/jrtfs access, |
|
35 |
* but also compiled and delivered as part of the jrtfs.jar to support access |
|
36 |
* to the jimage file provided by the shipped JDK by tools running on JDK 8. |
|
37 |
*/ |
|
38 |
public class ImageLocation { |
|
39 |
public static final int ATTRIBUTE_END = 0; |
|
40 |
public static final int ATTRIBUTE_MODULE = 1; |
|
41 |
public static final int ATTRIBUTE_PARENT = 2; |
|
42 |
public static final int ATTRIBUTE_BASE = 3; |
|
43 |
public static final int ATTRIBUTE_EXTENSION = 4; |
|
44 |
public static final int ATTRIBUTE_OFFSET = 5; |
|
45 |
public static final int ATTRIBUTE_COMPRESSED = 6; |
|
46 |
public static final int ATTRIBUTE_UNCOMPRESSED = 7; |
|
47 |
public static final int ATTRIBUTE_COUNT = 8; |
|
48 |
||
49 |
protected final long[] attributes; |
|
50 |
||
51 |
protected final ImageStrings strings; |
|
52 |
||
53 |
public ImageLocation(long[] attributes, ImageStrings strings) { |
|
38582
8618f4ccb220
8156209: Add argument checks to BasicImageReader calls
jlaskey
parents:
36511
diff
changeset
|
54 |
this.attributes = Objects.requireNonNull(attributes); |
8618f4ccb220
8156209: Add argument checks to BasicImageReader calls
jlaskey
parents:
36511
diff
changeset
|
55 |
this.strings = Objects.requireNonNull(strings); |
36511 | 56 |
} |
57 |
||
58 |
ImageStrings getStrings() { |
|
59 |
return strings; |
|
60 |
} |
|
61 |
||
62 |
static long[] decompress(ByteBuffer bytes) { |
|
38582
8618f4ccb220
8156209: Add argument checks to BasicImageReader calls
jlaskey
parents:
36511
diff
changeset
|
63 |
Objects.requireNonNull(bytes); |
36511 | 64 |
long[] attributes = new long[ATTRIBUTE_COUNT]; |
65 |
||
66 |
if (bytes != null) { |
|
67 |
while (bytes.hasRemaining()) { |
|
68 |
int data = bytes.get() & 0xFF; |
|
44034
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
69 |
int kind = data >>> 3; |
36511 | 70 |
|
71 |
if (kind == ATTRIBUTE_END) { |
|
72 |
break; |
|
73 |
} |
|
74 |
||
75 |
if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) { |
|
41121
91734a3ed04b
8151832: Improve exception messages in exception thrown by new JDK 9 code
coffeys
parents:
38582
diff
changeset
|
76 |
throw new InternalError( |
91734a3ed04b
8151832: Improve exception messages in exception thrown by new JDK 9 code
coffeys
parents:
38582
diff
changeset
|
77 |
"Invalid jimage attribute kind: " + kind); |
36511 | 78 |
} |
79 |
||
44034
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
80 |
int length = (data & 0x7) + 1; |
36511 | 81 |
long value = 0; |
82 |
||
83 |
for (int j = 0; j < length; j++) { |
|
84 |
value <<= 8; |
|
85 |
||
86 |
if (!bytes.hasRemaining()) { |
|
41121
91734a3ed04b
8151832: Improve exception messages in exception thrown by new JDK 9 code
coffeys
parents:
38582
diff
changeset
|
87 |
throw new InternalError("Missing jimage attribute data"); |
36511 | 88 |
} |
89 |
||
90 |
value |= bytes.get() & 0xFF; |
|
91 |
} |
|
92 |
||
93 |
attributes[kind] = value; |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
return attributes; |
|
98 |
} |
|
99 |
||
100 |
public static byte[] compress(long[] attributes) { |
|
38582
8618f4ccb220
8156209: Add argument checks to BasicImageReader calls
jlaskey
parents:
36511
diff
changeset
|
101 |
Objects.requireNonNull(attributes); |
36511 | 102 |
ImageStream stream = new ImageStream(16); |
103 |
||
104 |
for (int kind = ATTRIBUTE_END + 1; kind < ATTRIBUTE_COUNT; kind++) { |
|
105 |
long value = attributes[kind]; |
|
106 |
||
107 |
if (value != 0) { |
|
108 |
int n = (63 - Long.numberOfLeadingZeros(value)) >> 3; |
|
109 |
stream.put((kind << 3) | n); |
|
110 |
||
111 |
for (int i = n; i >= 0; i--) { |
|
112 |
stream.put((int)(value >> (i << 3))); |
|
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
||
117 |
stream.put(ATTRIBUTE_END << 3); |
|
118 |
||
119 |
return stream.toArray(); |
|
120 |
} |
|
121 |
||
122 |
public boolean verify(String name) { |
|
44034
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
123 |
return verify(name, attributes, strings); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
124 |
} |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
125 |
|
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
126 |
/** |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
127 |
* A simpler verification would be {@code name.equals(getFullName())}, but |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
128 |
* by not creating the full name and enabling early returns we allocate |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
129 |
* fewer objects. Could possibly be made allocation free by extending |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
130 |
* ImageStrings to test if strings at an offset match the name region. |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
131 |
*/ |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
132 |
static boolean verify(String name, long[] attributes, ImageStrings strings) { |
38582
8618f4ccb220
8156209: Add argument checks to BasicImageReader calls
jlaskey
parents:
36511
diff
changeset
|
133 |
Objects.requireNonNull(name); |
44034
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
134 |
final int length = name.length(); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
135 |
int index = 0; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
136 |
int moduleOffset = (int)attributes[ATTRIBUTE_MODULE]; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
137 |
if (moduleOffset != 0) { |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
138 |
String module = strings.get(moduleOffset); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
139 |
final int moduleLen = module.length(); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
140 |
index = moduleLen + 1; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
141 |
if (length <= index |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
142 |
|| name.charAt(0) != '/' |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
143 |
|| !name.regionMatches(1, module, 0, moduleLen) |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
144 |
|| name.charAt(index++) != '/') { |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
145 |
return false; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
146 |
} |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
147 |
} |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
148 |
|
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
149 |
return verifyName(name, index, length, attributes, strings); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
150 |
} |
38582
8618f4ccb220
8156209: Add argument checks to BasicImageReader calls
jlaskey
parents:
36511
diff
changeset
|
151 |
|
44034
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
152 |
static boolean verify(String module, String name, long[] attributes, |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
153 |
ImageStrings strings) { |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
154 |
Objects.requireNonNull(module); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
155 |
Objects.requireNonNull(name); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
156 |
int moduleOffset = (int)attributes[ATTRIBUTE_MODULE]; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
157 |
if (moduleOffset != 0) { |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
158 |
if (!module.equals(strings.get(moduleOffset))) { |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
159 |
return false; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
160 |
} |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
161 |
} |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
162 |
|
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
163 |
return verifyName(name, 0, name.length(), attributes, strings); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
164 |
} |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
165 |
|
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
166 |
private static boolean verifyName(String name, int index, int length, |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
167 |
long[] attributes, ImageStrings strings) { |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
168 |
|
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
169 |
int parentOffset = (int) attributes[ATTRIBUTE_PARENT]; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
170 |
if (parentOffset != 0) { |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
171 |
String parent = strings.get(parentOffset); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
172 |
final int parentLen = parent.length(); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
173 |
if (!name.regionMatches(index, parent, 0, parentLen)) { |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
174 |
return false; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
175 |
} |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
176 |
index += parentLen; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
177 |
if (length <= index || name.charAt(index++) != '/') { |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
178 |
return false; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
179 |
} |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
180 |
} |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
181 |
String base = strings.get((int) attributes[ATTRIBUTE_BASE]); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
182 |
final int baseLen = base.length(); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
183 |
if (!name.regionMatches(index, base, 0, baseLen)) { |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
184 |
return false; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
185 |
} |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
186 |
index += baseLen; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
187 |
int extOffset = (int) attributes[ATTRIBUTE_EXTENSION]; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
188 |
if (extOffset != 0) { |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
189 |
String extension = strings.get(extOffset); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
190 |
int extLen = extension.length(); |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
191 |
if (length <= index |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
192 |
|| name.charAt(index++) != '.' |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
193 |
|| !name.regionMatches(index, extension, 0, extLen)) { |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
194 |
return false; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
195 |
} |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
196 |
index += extLen; |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
197 |
} |
0d664fca91a7
8175561: Memory churn in jimage code affects startup after resource encapsulation changes
redestad
parents:
41121
diff
changeset
|
198 |
return length == index; |
36511 | 199 |
} |
200 |
||
201 |
long getAttribute(int kind) { |
|
202 |
if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) { |
|
41121
91734a3ed04b
8151832: Improve exception messages in exception thrown by new JDK 9 code
coffeys
parents:
38582
diff
changeset
|
203 |
throw new InternalError( |
91734a3ed04b
8151832: Improve exception messages in exception thrown by new JDK 9 code
coffeys
parents:
38582
diff
changeset
|
204 |
"Invalid jimage attribute kind: " + kind); |
36511 | 205 |
} |
206 |
||
207 |
return attributes[kind]; |
|
208 |
} |
|
209 |
||
210 |
String getAttributeString(int kind) { |
|
211 |
if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) { |
|
41121
91734a3ed04b
8151832: Improve exception messages in exception thrown by new JDK 9 code
coffeys
parents:
38582
diff
changeset
|
212 |
throw new InternalError( |
91734a3ed04b
8151832: Improve exception messages in exception thrown by new JDK 9 code
coffeys
parents:
38582
diff
changeset
|
213 |
"Invalid jimage attribute kind: " + kind); |
36511 | 214 |
} |
215 |
||
216 |
return getStrings().get((int)attributes[kind]); |
|
217 |
} |
|
218 |
||
219 |
public String getModule() { |
|
220 |
return getAttributeString(ATTRIBUTE_MODULE); |
|
221 |
} |
|
222 |
||
223 |
public int getModuleOffset() { |
|
224 |
return (int)getAttribute(ATTRIBUTE_MODULE); |
|
225 |
} |
|
226 |
||
227 |
public String getBase() { |
|
228 |
return getAttributeString(ATTRIBUTE_BASE); |
|
229 |
} |
|
230 |
||
231 |
public int getBaseOffset() { |
|
232 |
return (int)getAttribute(ATTRIBUTE_BASE); |
|
233 |
} |
|
234 |
||
235 |
public String getParent() { |
|
236 |
return getAttributeString(ATTRIBUTE_PARENT); |
|
237 |
} |
|
238 |
||
239 |
public int getParentOffset() { |
|
240 |
return (int)getAttribute(ATTRIBUTE_PARENT); |
|
241 |
} |
|
242 |
||
243 |
public String getExtension() { |
|
244 |
return getAttributeString(ATTRIBUTE_EXTENSION); |
|
245 |
} |
|
246 |
||
247 |
public int getExtensionOffset() { |
|
248 |
return (int)getAttribute(ATTRIBUTE_EXTENSION); |
|
249 |
} |
|
250 |
||
251 |
public String getFullName() { |
|
252 |
return getFullName(false); |
|
253 |
} |
|
254 |
||
255 |
public String getFullName(boolean modulesPrefix) { |
|
256 |
StringBuilder builder = new StringBuilder(); |
|
257 |
||
258 |
if (getModuleOffset() != 0) { |
|
259 |
if (modulesPrefix) { |
|
260 |
builder.append("/modules"); |
|
261 |
} |
|
262 |
||
263 |
builder.append('/'); |
|
264 |
builder.append(getModule()); |
|
265 |
builder.append('/'); |
|
266 |
} |
|
267 |
||
268 |
if (getParentOffset() != 0) { |
|
269 |
builder.append(getParent()); |
|
270 |
builder.append('/'); |
|
271 |
} |
|
272 |
||
273 |
builder.append(getBase()); |
|
274 |
||
275 |
if (getExtensionOffset() != 0) { |
|
276 |
builder.append('.'); |
|
277 |
builder.append(getExtension()); |
|
278 |
} |
|
279 |
||
280 |
return builder.toString(); |
|
281 |
} |
|
282 |
||
283 |
String buildName(boolean includeModule, boolean includeParent, |
|
284 |
boolean includeName) { |
|
285 |
StringBuilder builder = new StringBuilder(); |
|
286 |
||
287 |
if (includeModule && getModuleOffset() != 0) { |
|
288 |
builder.append("/modules/"); |
|
289 |
builder.append(getModule()); |
|
290 |
} |
|
291 |
||
292 |
if (includeParent && getParentOffset() != 0) { |
|
293 |
builder.append('/'); |
|
294 |
builder.append(getParent()); |
|
295 |
} |
|
296 |
||
297 |
if (includeName) { |
|
298 |
if (includeModule || includeParent) { |
|
299 |
builder.append('/'); |
|
300 |
} |
|
301 |
||
302 |
builder.append(getBase()); |
|
303 |
||
304 |
if (getExtensionOffset() != 0) { |
|
305 |
builder.append('.'); |
|
306 |
builder.append(getExtension()); |
|
307 |
} |
|
308 |
} |
|
309 |
||
310 |
return builder.toString(); |
|
311 |
} |
|
312 |
||
313 |
public long getContentOffset() { |
|
314 |
return getAttribute(ATTRIBUTE_OFFSET); |
|
315 |
} |
|
316 |
||
317 |
public long getCompressedSize() { |
|
318 |
return getAttribute(ATTRIBUTE_COMPRESSED); |
|
319 |
} |
|
320 |
||
321 |
public long getUncompressedSize() { |
|
322 |
return getAttribute(ATTRIBUTE_UNCOMPRESSED); |
|
27565 | 323 |
} |
324 |
||
31673 | 325 |
static ImageLocation readFrom(BasicImageReader reader, int offset) { |
38582
8618f4ccb220
8156209: Add argument checks to BasicImageReader calls
jlaskey
parents:
36511
diff
changeset
|
326 |
Objects.requireNonNull(reader); |
31673 | 327 |
long[] attributes = reader.getAttributes(offset); |
328 |
ImageStringsReader strings = reader.getStrings(); |
|
27565 | 329 |
|
31673 | 330 |
return new ImageLocation(attributes, strings); |
27565 | 331 |
} |
332 |
} |