author | alanb |
Fri, 07 Apr 2017 08:05:54 +0000 | |
changeset 44545 | 83b611b88ac8 |
parent 40138 | d294794a0878 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
2 |
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.imageio.spi; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.lang.reflect.Constructor; |
|
30 |
import java.lang.reflect.Method; |
|
36511 | 31 |
import java.security.AccessController; |
32 |
import java.security.PrivilegedAction; |
|
2 | 33 |
import java.util.Arrays; |
34 |
import java.util.Iterator; |
|
35 |
import javax.imageio.ImageReader; |
|
36 |
import javax.imageio.metadata.IIOMetadata; |
|
37 |
import javax.imageio.metadata.IIOMetadataFormat; |
|
38 |
import javax.imageio.metadata.IIOMetadataFormatImpl; |
|
39 |
import javax.imageio.stream.ImageInputStream; |
|
40 |
||
41 |
/** |
|
42 |
* A superclass containing instance variables and methods common to |
|
35667 | 43 |
* {@code ImageReaderSpi} and {@code ImageWriterSpi}. |
2 | 44 |
* |
45 |
* @see IIORegistry |
|
46 |
* @see ImageReaderSpi |
|
47 |
* @see ImageWriterSpi |
|
48 |
* |
|
49 |
*/ |
|
50 |
public abstract class ImageReaderWriterSpi extends IIOServiceProvider { |
|
51 |
||
52 |
/** |
|
53 |
* An array of strings to be returned from |
|
35667 | 54 |
* {@code getFormatNames}, initially {@code null}. |
55 |
* Constructors should set this to a non-{@code null} value. |
|
2 | 56 |
*/ |
57 |
protected String[] names = null; |
|
58 |
||
59 |
/** |
|
60 |
* An array of strings to be returned from |
|
35667 | 61 |
* {@code getFileSuffixes}, initially {@code null}. |
2 | 62 |
*/ |
63 |
protected String[] suffixes = null; |
|
64 |
||
65 |
/** |
|
66 |
* An array of strings to be returned from |
|
35667 | 67 |
* {@code getMIMETypes}, initially {@code null}. |
2 | 68 |
*/ |
69 |
protected String[] MIMETypes = null; |
|
70 |
||
71 |
/** |
|
35667 | 72 |
* A {@code String} containing the name of the associated |
73 |
* plug-in class, initially {@code null}. |
|
2 | 74 |
*/ |
75 |
protected String pluginClassName = null; |
|
76 |
||
77 |
/** |
|
78 |
* A boolean indicating whether this plug-in supports the |
|
79 |
* standard metadata format for stream metadata, initially |
|
35667 | 80 |
* {@code false}. |
2 | 81 |
*/ |
82 |
protected boolean supportsStandardStreamMetadataFormat = false; |
|
83 |
||
84 |
/** |
|
35667 | 85 |
* A {@code String} containing the name of the native stream |
2 | 86 |
* metadata format supported by this plug-in, initially |
35667 | 87 |
* {@code null}. |
2 | 88 |
*/ |
89 |
protected String nativeStreamMetadataFormatName = null; |
|
90 |
||
91 |
/** |
|
35667 | 92 |
* A {@code String} containing the class name of the native |
2 | 93 |
* stream metadata format supported by this plug-in, initially |
35667 | 94 |
* {@code null}. |
2 | 95 |
*/ |
96 |
protected String nativeStreamMetadataFormatClassName = null; |
|
97 |
||
98 |
/** |
|
35667 | 99 |
* An array of {@code String}s containing the names of any |
2 | 100 |
* additional stream metadata formats supported by this plug-in, |
35667 | 101 |
* initially {@code null}. |
2 | 102 |
*/ |
103 |
protected String[] extraStreamMetadataFormatNames = null; |
|
104 |
||
105 |
/** |
|
35667 | 106 |
* An array of {@code String}s containing the class names of |
2 | 107 |
* any additional stream metadata formats supported by this plug-in, |
35667 | 108 |
* initially {@code null}. |
2 | 109 |
*/ |
110 |
protected String[] extraStreamMetadataFormatClassNames = null; |
|
111 |
||
112 |
/** |
|
113 |
* A boolean indicating whether this plug-in supports the |
|
114 |
* standard metadata format for image metadata, initially |
|
35667 | 115 |
* {@code false}. |
2 | 116 |
*/ |
117 |
protected boolean supportsStandardImageMetadataFormat = false; |
|
118 |
||
119 |
/** |
|
35667 | 120 |
* A {@code String} containing the name of the |
2 | 121 |
* native stream metadata format supported by this plug-in, |
35667 | 122 |
* initially {@code null}. |
2 | 123 |
*/ |
124 |
protected String nativeImageMetadataFormatName = null; |
|
125 |
||
126 |
/** |
|
35667 | 127 |
* A {@code String} containing the class name of the |
2 | 128 |
* native stream metadata format supported by this plug-in, |
35667 | 129 |
* initially {@code null}. |
2 | 130 |
*/ |
131 |
protected String nativeImageMetadataFormatClassName = null; |
|
132 |
||
133 |
/** |
|
35667 | 134 |
* An array of {@code String}s containing the names of any |
2 | 135 |
* additional image metadata formats supported by this plug-in, |
35667 | 136 |
* initially {@code null}. |
2 | 137 |
*/ |
138 |
protected String[] extraImageMetadataFormatNames = null; |
|
139 |
||
140 |
/** |
|
35667 | 141 |
* An array of {@code String}s containing the class names of |
2 | 142 |
* any additional image metadata formats supported by this |
35667 | 143 |
* plug-in, initially {@code null}. |
2 | 144 |
*/ |
145 |
protected String[] extraImageMetadataFormatClassNames = null; |
|
146 |
||
147 |
/** |
|
35667 | 148 |
* Constructs an {@code ImageReaderWriterSpi} with a given |
2 | 149 |
* set of values. |
150 |
* |
|
35667 | 151 |
* @param vendorName the vendor name, as a non-{@code null} |
152 |
* {@code String}. |
|
153 |
* @param version a version identifier, as a non-{@code null} |
|
154 |
* {@code String}. |
|
155 |
* @param names a non-{@code null} array of |
|
156 |
* {@code String}s indicating the format names. At least one |
|
2 | 157 |
* entry must be present. |
35667 | 158 |
* @param suffixes an array of {@code String}s indicating the |
2 | 159 |
* common file suffixes. If no suffixes are defined, |
35667 | 160 |
* {@code null} should be supplied. An array of length 0 |
161 |
* will be normalized to {@code null}. |
|
162 |
* @param MIMETypes an array of {@code String}s indicating |
|
2 | 163 |
* the format's MIME types. If no MIME types are defined, |
35667 | 164 |
* {@code null} should be supplied. An array of length 0 |
165 |
* will be normalized to {@code null}. |
|
2 | 166 |
* @param pluginClassName the fully-qualified name of the |
35667 | 167 |
* associated {@code ImageReader} or {@code ImageWriter} |
168 |
* class, as a non-{@code null String}. |
|
2 | 169 |
* @param supportsStandardStreamMetadataFormat a |
35667 | 170 |
* {@code boolean} that indicates whether a stream metadata |
2 | 171 |
* object can use trees described by the standard metadata format. |
172 |
* @param nativeStreamMetadataFormatName a |
|
35667 | 173 |
* {@code String}, or {@code null}, to be returned from |
174 |
* {@code getNativeStreamMetadataFormatName}. |
|
2 | 175 |
* @param nativeStreamMetadataFormatClassName a |
35667 | 176 |
* {@code String}, or {@code null}, to be used to instantiate |
2 | 177 |
* a metadata format object to be returned from |
35667 | 178 |
* {@code getNativeStreamMetadataFormat}. |
2 | 179 |
* @param extraStreamMetadataFormatNames an array of |
35667 | 180 |
* {@code String}s, or {@code null}, to be returned from |
181 |
* {@code getExtraStreamMetadataFormatNames}. An array of length |
|
182 |
* 0 is normalized to {@code null}. |
|
2 | 183 |
* @param extraStreamMetadataFormatClassNames an array of |
35667 | 184 |
* {@code String}s, or {@code null}, to be used to instantiate |
2 | 185 |
* a metadata format object to be returned from |
35667 | 186 |
* {@code getStreamMetadataFormat}. An array of length |
187 |
* 0 is normalized to {@code null}. |
|
2 | 188 |
* @param supportsStandardImageMetadataFormat a |
35667 | 189 |
* {@code boolean} that indicates whether an image metadata |
2 | 190 |
* object can use trees described by the standard metadata format. |
191 |
* @param nativeImageMetadataFormatName a |
|
35667 | 192 |
* {@code String}, or {@code null}, to be returned from |
193 |
* {@code getNativeImageMetadataFormatName}. |
|
2 | 194 |
* @param nativeImageMetadataFormatClassName a |
35667 | 195 |
* {@code String}, or {@code null}, to be used to instantiate |
2 | 196 |
* a metadata format object to be returned from |
35667 | 197 |
* {@code getNativeImageMetadataFormat}. |
2 | 198 |
* @param extraImageMetadataFormatNames an array of |
35667 | 199 |
* {@code String}s to be returned from |
200 |
* {@code getExtraImageMetadataFormatNames}. An array of length 0 |
|
201 |
* is normalized to {@code null}. |
|
2 | 202 |
* @param extraImageMetadataFormatClassNames an array of |
35667 | 203 |
* {@code String}s, or {@code null}, to be used to instantiate |
2 | 204 |
* a metadata format object to be returned from |
35667 | 205 |
* {@code getImageMetadataFormat}. An array of length |
206 |
* 0 is normalized to {@code null}. |
|
2 | 207 |
* |
35667 | 208 |
* @exception IllegalArgumentException if {@code vendorName} |
209 |
* is {@code null}. |
|
210 |
* @exception IllegalArgumentException if {@code version} |
|
211 |
* is {@code null}. |
|
212 |
* @exception IllegalArgumentException if {@code names} |
|
213 |
* is {@code null} or has length 0. |
|
214 |
* @exception IllegalArgumentException if {@code pluginClassName} |
|
215 |
* is {@code null}. |
|
2 | 216 |
*/ |
217 |
public ImageReaderWriterSpi(String vendorName, |
|
218 |
String version, |
|
219 |
String[] names, |
|
220 |
String[] suffixes, |
|
221 |
String[] MIMETypes, |
|
222 |
String pluginClassName, |
|
223 |
boolean supportsStandardStreamMetadataFormat, |
|
224 |
String nativeStreamMetadataFormatName, |
|
225 |
String nativeStreamMetadataFormatClassName, |
|
226 |
String[] extraStreamMetadataFormatNames, |
|
227 |
String[] extraStreamMetadataFormatClassNames, |
|
228 |
boolean supportsStandardImageMetadataFormat, |
|
229 |
String nativeImageMetadataFormatName, |
|
230 |
String nativeImageMetadataFormatClassName, |
|
231 |
String[] extraImageMetadataFormatNames, |
|
232 |
String[] extraImageMetadataFormatClassNames) { |
|
233 |
super(vendorName, version); |
|
234 |
if (names == null) { |
|
235 |
throw new IllegalArgumentException("names == null!"); |
|
236 |
} |
|
237 |
if (names.length == 0) { |
|
238 |
throw new IllegalArgumentException("names.length == 0!"); |
|
239 |
} |
|
240 |
if (pluginClassName == null) { |
|
241 |
throw new IllegalArgumentException("pluginClassName == null!"); |
|
242 |
} |
|
243 |
||
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
244 |
this.names = names.clone(); |
2 | 245 |
// If length == 0, leave it null |
246 |
if (suffixes != null && suffixes.length > 0) { |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
247 |
this.suffixes = suffixes.clone(); |
2 | 248 |
} |
249 |
// If length == 0, leave it null |
|
250 |
if (MIMETypes != null && MIMETypes.length > 0) { |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
251 |
this.MIMETypes = MIMETypes.clone(); |
2 | 252 |
} |
253 |
this.pluginClassName = pluginClassName; |
|
254 |
||
255 |
this.supportsStandardStreamMetadataFormat = |
|
256 |
supportsStandardStreamMetadataFormat; |
|
257 |
this.nativeStreamMetadataFormatName = nativeStreamMetadataFormatName; |
|
258 |
this.nativeStreamMetadataFormatClassName = |
|
259 |
nativeStreamMetadataFormatClassName; |
|
260 |
// If length == 0, leave it null |
|
261 |
if (extraStreamMetadataFormatNames != null && |
|
262 |
extraStreamMetadataFormatNames.length > 0) { |
|
263 |
this.extraStreamMetadataFormatNames = |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
264 |
extraStreamMetadataFormatNames.clone(); |
2 | 265 |
} |
266 |
// If length == 0, leave it null |
|
267 |
if (extraStreamMetadataFormatClassNames != null && |
|
268 |
extraStreamMetadataFormatClassNames.length > 0) { |
|
269 |
this.extraStreamMetadataFormatClassNames = |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
270 |
extraStreamMetadataFormatClassNames.clone(); |
2 | 271 |
} |
272 |
this.supportsStandardImageMetadataFormat = |
|
273 |
supportsStandardImageMetadataFormat; |
|
274 |
this.nativeImageMetadataFormatName = nativeImageMetadataFormatName; |
|
275 |
this.nativeImageMetadataFormatClassName = |
|
276 |
nativeImageMetadataFormatClassName; |
|
277 |
// If length == 0, leave it null |
|
278 |
if (extraImageMetadataFormatNames != null && |
|
279 |
extraImageMetadataFormatNames.length > 0) { |
|
280 |
this.extraImageMetadataFormatNames = |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
281 |
extraImageMetadataFormatNames.clone(); |
2 | 282 |
} |
283 |
// If length == 0, leave it null |
|
284 |
if (extraImageMetadataFormatClassNames != null && |
|
285 |
extraImageMetadataFormatClassNames.length > 0) { |
|
286 |
this.extraImageMetadataFormatClassNames = |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
287 |
extraImageMetadataFormatClassNames.clone(); |
2 | 288 |
} |
289 |
} |
|
290 |
||
291 |
/** |
|
35667 | 292 |
* Constructs a blank {@code ImageReaderWriterSpi}. It is up |
2 | 293 |
* to the subclass to initialize instance variables and/or |
294 |
* override method implementations in order to provide working |
|
295 |
* versions of all methods. |
|
296 |
*/ |
|
297 |
public ImageReaderWriterSpi() { |
|
298 |
} |
|
299 |
||
300 |
/** |
|
35667 | 301 |
* Returns an array of {@code String}s containing |
2 | 302 |
* human-readable names for the formats that are generally usable |
35667 | 303 |
* by the {@code ImageReader} or {@code ImageWriter} |
2 | 304 |
* implementation associated with this service provider. For |
35667 | 305 |
* example, a single {@code ImageReader} might be able to |
2 | 306 |
* process both PBM and PNM files. |
307 |
* |
|
35667 | 308 |
* @return a non-{@code null} array of {@code String}s |
2 | 309 |
* or length at least 1 containing informal format names |
310 |
* associated with this reader or writer. |
|
311 |
*/ |
|
312 |
public String[] getFormatNames() { |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
313 |
return names.clone(); |
2 | 314 |
} |
315 |
||
316 |
/** |
|
35667 | 317 |
* Returns an array of {@code String}s containing a list of |
2 | 318 |
* file suffixes associated with the formats that are generally |
35667 | 319 |
* usable by the {@code ImageReader} or |
320 |
* {@code ImageWriter} implementation associated with this |
|
2 | 321 |
* service provider. For example, a single |
35667 | 322 |
* {@code ImageReader} might be able to process files with |
2 | 323 |
* '.pbm' and '.pnm' suffixes, or both '.jpg' and '.jpeg' |
324 |
* suffixes. If there are no known file suffixes, |
|
35667 | 325 |
* {@code null} will be returned. |
2 | 326 |
* |
327 |
* <p> Returning a particular suffix does not guarantee that files |
|
328 |
* with that suffix can be processed; it merely indicates that it |
|
329 |
* may be worthwhile attempting to decode or encode such files |
|
330 |
* using this service provider. |
|
331 |
* |
|
35667 | 332 |
* @return an array of {@code String}s or length at least 1 |
2 | 333 |
* containing common file suffixes associated with this reader or |
35667 | 334 |
* writer, or {@code null}. |
2 | 335 |
*/ |
336 |
public String[] getFileSuffixes() { |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
337 |
return suffixes == null ? null : suffixes.clone(); |
2 | 338 |
} |
339 |
||
340 |
/** |
|
35667 | 341 |
* Returns an array of {@code String}s containing a list of |
2 | 342 |
* MIME types associated with the formats that are generally |
35667 | 343 |
* usable by the {@code ImageReader} or |
344 |
* {@code ImageWriter} implementation associated with this |
|
2 | 345 |
* service provider. |
346 |
* |
|
347 |
* <p> Ideally, only a single MIME type would be required in order |
|
348 |
* to describe a particular format. However, for several reasons |
|
349 |
* it is necessary to associate a list of types with each service |
|
350 |
* provider. First, many common image file formats do not have |
|
351 |
* standard MIME types, so a list of commonly used unofficial |
|
35667 | 352 |
* names will be required, such as {@code image/x-pbm} and |
353 |
* {@code image/x-portable-bitmap}. Some file formats have |
|
2 | 354 |
* official MIME types but may sometimes be referred to using |
355 |
* their previous unofficial designations, such as |
|
35667 | 356 |
* {@code image/x-png} instead of the official |
357 |
* {@code image/png}. Finally, a single service provider may |
|
2 | 358 |
* be capable of parsing multiple distinct types from the MIME |
35667 | 359 |
* point of view, for example {@code image/x-xbitmap} and |
360 |
* {@code image/x-xpixmap}. |
|
2 | 361 |
* |
362 |
* <p> Returning a particular MIME type does not guarantee that |
|
363 |
* files claiming to be of that type can be processed; it merely |
|
364 |
* indicates that it may be worthwhile attempting to decode or |
|
365 |
* encode such files using this service provider. |
|
366 |
* |
|
35667 | 367 |
* @return an array of {@code String}s or length at least 1 |
2 | 368 |
* containing MIME types associated with this reader or writer, or |
35667 | 369 |
* {@code null}. |
2 | 370 |
*/ |
371 |
public String[] getMIMETypes() { |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
372 |
return MIMETypes == null ? null : MIMETypes.clone(); |
2 | 373 |
} |
374 |
||
375 |
/** |
|
376 |
* Returns the fully-qualified class name of the |
|
35667 | 377 |
* {@code ImageReader} or {@code ImageWriter} plug-in |
2 | 378 |
* associated with this service provider. |
379 |
* |
|
35667 | 380 |
* @return the class name, as a non-{@code null} |
381 |
* {@code String}. |
|
2 | 382 |
*/ |
383 |
public String getPluginClassName() { |
|
384 |
return pluginClassName; |
|
385 |
} |
|
386 |
||
387 |
/** |
|
35667 | 388 |
* Returns {@code true} if the standard metadata format is |
2 | 389 |
* among the document formats recognized by the |
35667 | 390 |
* {@code getAsTree} and {@code setFromTree} methods on |
2 | 391 |
* the stream metadata objects produced or consumed by this |
392 |
* plug-in. |
|
393 |
* |
|
35667 | 394 |
* @return {@code true} if the standard format is supported |
2 | 395 |
* for stream metadata. |
396 |
*/ |
|
397 |
public boolean isStandardStreamMetadataFormatSupported() { |
|
398 |
return supportsStandardStreamMetadataFormat; |
|
399 |
} |
|
400 |
||
401 |
/** |
|
402 |
* Returns the name of the "native" stream metadata format for |
|
403 |
* this plug-in, which typically allows for lossless encoding and |
|
404 |
* transmission of the stream metadata stored in the format handled by |
|
405 |
* this plug-in. If no such format is supported, |
|
35667 | 406 |
* {@code null} will be returned. |
2 | 407 |
* |
408 |
* <p> The default implementation returns the |
|
35667 | 409 |
* {@code nativeStreamMetadataFormatName} instance variable, |
2 | 410 |
* which is typically set by the constructor. |
411 |
* |
|
412 |
* @return the name of the native stream metadata format, or |
|
35667 | 413 |
* {@code null}. |
2 | 414 |
* |
415 |
*/ |
|
416 |
public String getNativeStreamMetadataFormatName() { |
|
417 |
return nativeStreamMetadataFormatName; |
|
418 |
} |
|
419 |
||
420 |
/** |
|
35667 | 421 |
* Returns an array of {@code String}s containing the names |
2 | 422 |
* of additional document formats, other than the native and |
423 |
* standard formats, recognized by the |
|
35667 | 424 |
* {@code getAsTree} and {@code setFromTree} methods on |
2 | 425 |
* the stream metadata objects produced or consumed by this |
426 |
* plug-in. |
|
427 |
* |
|
428 |
* <p> If the plug-in does not handle metadata, null should be |
|
429 |
* returned. |
|
430 |
* |
|
431 |
* <p> The set of formats may differ according to the particular |
|
432 |
* images being read or written; this method should indicate all |
|
433 |
* the additional formats supported by the plug-in under any |
|
434 |
* circumstances. |
|
435 |
* |
|
436 |
* <p> The default implementation returns a clone of the |
|
35667 | 437 |
* {@code extraStreamMetadataFormatNames} instance variable, |
2 | 438 |
* which is typically set by the constructor. |
439 |
* |
|
35667 | 440 |
* @return an array of {@code String}s, or null. |
2 | 441 |
* |
442 |
* @see IIOMetadata#getMetadataFormatNames |
|
443 |
* @see #getExtraImageMetadataFormatNames |
|
444 |
* @see #getNativeStreamMetadataFormatName |
|
445 |
*/ |
|
446 |
public String[] getExtraStreamMetadataFormatNames() { |
|
447 |
return extraStreamMetadataFormatNames == null ? |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
448 |
null : extraStreamMetadataFormatNames.clone(); |
2 | 449 |
} |
450 |
||
451 |
/** |
|
35667 | 452 |
* Returns {@code true} if the standard metadata format is |
2 | 453 |
* among the document formats recognized by the |
35667 | 454 |
* {@code getAsTree} and {@code setFromTree} methods on |
2 | 455 |
* the image metadata objects produced or consumed by this |
456 |
* plug-in. |
|
457 |
* |
|
35667 | 458 |
* @return {@code true} if the standard format is supported |
2 | 459 |
* for image metadata. |
460 |
*/ |
|
461 |
public boolean isStandardImageMetadataFormatSupported() { |
|
462 |
return supportsStandardImageMetadataFormat; |
|
463 |
} |
|
464 |
||
465 |
/** |
|
466 |
* Returns the name of the "native" image metadata format for |
|
467 |
* this plug-in, which typically allows for lossless encoding and |
|
468 |
* transmission of the image metadata stored in the format handled by |
|
469 |
* this plug-in. If no such format is supported, |
|
35667 | 470 |
* {@code null} will be returned. |
2 | 471 |
* |
472 |
* <p> The default implementation returns the |
|
35667 | 473 |
* {@code nativeImageMetadataFormatName} instance variable, |
2 | 474 |
* which is typically set by the constructor. |
475 |
* |
|
476 |
* @return the name of the native image metadata format, or |
|
35667 | 477 |
* {@code null}. |
2 | 478 |
* |
479 |
* @see #getExtraImageMetadataFormatNames |
|
480 |
*/ |
|
481 |
public String getNativeImageMetadataFormatName() { |
|
482 |
return nativeImageMetadataFormatName; |
|
483 |
} |
|
484 |
||
485 |
/** |
|
35667 | 486 |
* Returns an array of {@code String}s containing the names |
2 | 487 |
* of additional document formats, other than the native and |
488 |
* standard formats, recognized by the |
|
35667 | 489 |
* {@code getAsTree} and {@code setFromTree} methods on |
2 | 490 |
* the image metadata objects produced or consumed by this |
491 |
* plug-in. |
|
492 |
* |
|
493 |
* <p> If the plug-in does not handle image metadata, null should |
|
494 |
* be returned. |
|
495 |
* |
|
496 |
* <p> The set of formats may differ according to the particular |
|
497 |
* images being read or written; this method should indicate all |
|
498 |
* the additional formats supported by the plug-in under any circumstances. |
|
499 |
* |
|
500 |
* <p> The default implementation returns a clone of the |
|
35667 | 501 |
* {@code extraImageMetadataFormatNames} instance variable, |
2 | 502 |
* which is typically set by the constructor. |
503 |
* |
|
35667 | 504 |
* @return an array of {@code String}s, or null. |
2 | 505 |
* |
506 |
* @see IIOMetadata#getMetadataFormatNames |
|
507 |
* @see #getExtraStreamMetadataFormatNames |
|
508 |
* @see #getNativeImageMetadataFormatName |
|
509 |
*/ |
|
510 |
public String[] getExtraImageMetadataFormatNames() { |
|
511 |
return extraImageMetadataFormatNames == null ? |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21278
diff
changeset
|
512 |
null : extraImageMetadataFormatNames.clone(); |
2 | 513 |
} |
514 |
||
515 |
/** |
|
35667 | 516 |
* Returns an {@code IIOMetadataFormat} object describing the |
517 |
* given stream metadata format, or {@code null} if no |
|
2 | 518 |
* description is available. The supplied name must be the native |
519 |
* stream metadata format name, the standard metadata format name, |
|
520 |
* or one of those returned by |
|
35667 | 521 |
* {@code getExtraStreamMetadataFormatNames}. |
2 | 522 |
* |
523 |
* @param formatName the desired stream metadata format. |
|
524 |
* |
|
35667 | 525 |
* @return an {@code IIOMetadataFormat} object. |
2 | 526 |
* |
35667 | 527 |
* @exception IllegalArgumentException if {@code formatName} |
528 |
* is {@code null} or is not a supported name. |
|
2 | 529 |
*/ |
530 |
public IIOMetadataFormat getStreamMetadataFormat(String formatName) { |
|
531 |
return getMetadataFormat(formatName, |
|
532 |
supportsStandardStreamMetadataFormat, |
|
533 |
nativeStreamMetadataFormatName, |
|
534 |
nativeStreamMetadataFormatClassName, |
|
535 |
extraStreamMetadataFormatNames, |
|
536 |
extraStreamMetadataFormatClassNames); |
|
537 |
} |
|
538 |
||
539 |
/** |
|
35667 | 540 |
* Returns an {@code IIOMetadataFormat} object describing the |
541 |
* given image metadata format, or {@code null} if no |
|
2 | 542 |
* description is available. The supplied name must be the native |
21278 | 543 |
* image metadata format name, the standard metadata format name, |
2 | 544 |
* or one of those returned by |
35667 | 545 |
* {@code getExtraImageMetadataFormatNames}. |
2 | 546 |
* |
547 |
* @param formatName the desired image metadata format. |
|
548 |
* |
|
35667 | 549 |
* @return an {@code IIOMetadataFormat} object. |
2 | 550 |
* |
35667 | 551 |
* @exception IllegalArgumentException if {@code formatName} |
552 |
* is {@code null} or is not a supported name. |
|
2 | 553 |
*/ |
554 |
public IIOMetadataFormat getImageMetadataFormat(String formatName) { |
|
555 |
return getMetadataFormat(formatName, |
|
556 |
supportsStandardImageMetadataFormat, |
|
557 |
nativeImageMetadataFormatName, |
|
558 |
nativeImageMetadataFormatClassName, |
|
559 |
extraImageMetadataFormatNames, |
|
560 |
extraImageMetadataFormatClassNames); |
|
561 |
} |
|
562 |
||
563 |
private IIOMetadataFormat getMetadataFormat(String formatName, |
|
564 |
boolean supportsStandard, |
|
565 |
String nativeName, |
|
566 |
String nativeClassName, |
|
567 |
String [] extraNames, |
|
568 |
String [] extraClassNames) { |
|
569 |
if (formatName == null) { |
|
570 |
throw new IllegalArgumentException("formatName == null!"); |
|
571 |
} |
|
572 |
if (supportsStandard && formatName.equals |
|
573 |
(IIOMetadataFormatImpl.standardMetadataFormatName)) { |
|
574 |
||
575 |
return IIOMetadataFormatImpl.getStandardFormatInstance(); |
|
576 |
} |
|
577 |
String formatClassName = null; |
|
578 |
if (formatName.equals(nativeName)) { |
|
579 |
formatClassName = nativeClassName; |
|
580 |
} else if (extraNames != null) { |
|
581 |
for (int i = 0; i < extraNames.length; i++) { |
|
582 |
if (formatName.equals(extraNames[i])) { |
|
583 |
formatClassName = extraClassNames[i]; |
|
584 |
break; // out of for |
|
585 |
} |
|
586 |
} |
|
587 |
} |
|
588 |
if (formatClassName == null) { |
|
589 |
throw new IllegalArgumentException("Unsupported format name"); |
|
590 |
} |
|
591 |
try { |
|
36511 | 592 |
// Try to load from the same location as the module of the SPI |
593 |
final String className = formatClassName; |
|
594 |
PrivilegedAction<Class<?>> pa = () -> { return getMetadataFormatClass(className); }; |
|
595 |
Class<?> cls = AccessController.doPrivileged(pa); |
|
2 | 596 |
Method meth = cls.getMethod("getInstance"); |
597 |
return (IIOMetadataFormat) meth.invoke(null); |
|
598 |
} catch (Exception e) { |
|
599 |
RuntimeException ex = |
|
600 |
new IllegalStateException ("Can't obtain format"); |
|
601 |
ex.initCause(e); |
|
602 |
throw ex; |
|
603 |
} |
|
604 |
} |
|
36511 | 605 |
|
40138 | 606 |
// If updating this method also see the same in IIOMetadata.java |
36511 | 607 |
private Class<?> getMetadataFormatClass(String formatClassName) { |
608 |
Module thisModule = ImageReaderWriterSpi.class.getModule(); |
|
609 |
Module targetModule = this.getClass().getModule(); |
|
40138 | 610 |
Class<?> c = null; |
611 |
try { |
|
612 |
ClassLoader cl = this.getClass().getClassLoader(); |
|
613 |
c = Class.forName(formatClassName, false, cl); |
|
614 |
if (!IIOMetadataFormat.class.isAssignableFrom(c)) { |
|
615 |
return null; |
|
616 |
} |
|
617 |
} catch (ClassNotFoundException e) { |
|
618 |
} |
|
36511 | 619 |
if (thisModule.equals(targetModule) || c == null) { |
620 |
return c; |
|
621 |
} |
|
40138 | 622 |
if (targetModule.isNamed()) { |
36511 | 623 |
int i = formatClassName.lastIndexOf("."); |
624 |
String pn = i > 0 ? formatClassName.substring(0, i) : ""; |
|
625 |
if (!targetModule.isExported(pn, thisModule)) { |
|
626 |
throw new IllegalStateException("Class " + formatClassName + |
|
627 |
" in named module must be exported to java.desktop module."); |
|
628 |
} |
|
629 |
} |
|
630 |
return c; |
|
631 |
} |
|
2 | 632 |
} |