use of javax.imageio.spi.ImageReaderSpi in project jdk8u_jdk by JetBrains.
the class StreamResetTest method main.
public static void main(String[] args) {
IOException expectedException = null;
TestStream iis = new TestStream();
ImageReader wbmp = ImageIO.getImageReadersByFormatName("WBMP").next();
if (wbmp == null) {
System.out.println("No WBMP reader: skip the test");
return;
}
ImageReaderSpi spi = wbmp.getOriginatingProvider();
iis.checkPosition();
try {
spi.canDecodeInput(iis);
} catch (IOException e) {
expectedException = e;
}
if (expectedException == null) {
throw new RuntimeException("Test FAILED: stream was not used");
}
iis.checkPosition();
System.out.println("Test PASSED");
}
use of javax.imageio.spi.ImageReaderSpi in project jdk8u_jdk by JetBrains.
the class SpiTest method testImageReaderSpiConstructor.
public void testImageReaderSpiConstructor() {
resetConstructorArguments();
checkImageReaderSpiConstructor(true);
vendorName = "My Vendor";
checkImageReaderSpiConstructor(true);
version = "My Version";
checkImageReaderSpiConstructor(true);
names = new String[0];
checkImageReaderSpiConstructor(true);
names = new String[1];
names[0] = "My Format Name";
checkImageReaderSpiConstructor(true);
readerClassName = "com.mycompany.Reader";
checkImageReaderSpiConstructor(true);
inputTypes = new Class[0];
checkImageReaderSpiConstructor(true);
inputTypes = new Class[1];
inputTypes[0] = Object.class;
// Now it should work
checkImageReaderSpiConstructor(false);
// Test normalization of zero-length arrays
suffixes = new String[0];
MIMETypes = new String[0];
writerSpiNames = new String[0];
extraStreamMetadataFormatNames = new String[0];
extraImageMetadataFormatNames = new String[0];
ImageReaderSpi spi = constructImageReaderSpi();
if (spi.getFileSuffixes() != null) {
error("Failed to normalize suffixes!");
}
if (spi.getMIMETypes() != null) {
error("Failed to normalize MIMETypes!");
}
if (spi.getImageWriterSpiNames() != null) {
error("Failed to normalize writerSpiNames!");
}
if (spi.getExtraStreamMetadataFormatNames() != null) {
error("Failed to normalize extraStreamMetadataFormatNames!");
}
if (spi.getExtraImageMetadataFormatNames() != null) {
error("Failed to normalize extraImageMetadataFormatNames!");
}
}
use of javax.imageio.spi.ImageReaderSpi in project jdk8u_jdk by JetBrains.
the class MetadataFormatPrinter method main.
public static void main(String[] args) {
IIOMetadataFormat format = null;
if (args.length == 0 || args[0].equals("javax_imageio_1.0")) {
format = IIOMetadataFormatImpl.getStandardFormatInstance();
} else {
IIORegistry registry = IIORegistry.getDefaultInstance();
Iterator iter = registry.getServiceProviders(ImageReaderSpi.class, false);
while (iter.hasNext()) {
ImageReaderSpi spi = (ImageReaderSpi) iter.next();
if (args[0].equals(spi.getNativeStreamMetadataFormatName())) {
System.out.print(spi.getDescription(null));
System.out.println(": native stream format");
format = spi.getStreamMetadataFormat(args[0]);
break;
}
String[] extraStreamFormatNames = spi.getExtraStreamMetadataFormatNames();
if (extraStreamFormatNames != null && Arrays.asList(extraStreamFormatNames).contains(args[0])) {
System.out.print(spi.getDescription(null));
System.out.println(": extra stream format");
format = spi.getStreamMetadataFormat(args[0]);
break;
}
if (args[0].equals(spi.getNativeImageMetadataFormatName())) {
System.out.print(spi.getDescription(null));
System.out.println(": native image format");
format = spi.getImageMetadataFormat(args[0]);
break;
}
String[] extraImageFormatNames = spi.getExtraImageMetadataFormatNames();
if (extraImageFormatNames != null && Arrays.asList(extraImageFormatNames).contains(args[0])) {
System.out.print(spi.getDescription(null));
System.out.println(": extra image format");
format = spi.getImageMetadataFormat(args[0]);
break;
}
}
}
if (format == null) {
System.err.println("Unknown format: " + args[0]);
System.exit(0);
}
MetadataFormatPrinter printer = new MetadataFormatPrinter(System.out);
printer.print(format);
}
use of javax.imageio.spi.ImageReaderSpi in project jdk8u_jdk by JetBrains.
the class RegisteredFormatsTest method main.
public static void main(String[] args) {
fmts = new Hashtable();
fmts.put("javax_imageio_jpeg_stream_1.0", Boolean.FALSE);
fmts.put("javax_imageio_jpeg_image_1.0", Boolean.FALSE);
fmts.put("javax_imageio_png_1.0", Boolean.FALSE);
fmts.put("javax_imageio_bmp_1.0", Boolean.FALSE);
fmts.put("javax_imageio_wbmp_1.0", Boolean.FALSE);
fmts.put("javax_imageio_gif_stream_1.0", Boolean.FALSE);
fmts.put("javax_imageio_gif_image_1.0", Boolean.FALSE);
IIORegistry registry = IIORegistry.getDefaultInstance();
Iterator iter = registry.getServiceProviders(ImageReaderSpi.class, false);
while (iter.hasNext()) {
ImageReaderSpi spi = (ImageReaderSpi) iter.next();
String fmt_name;
fmt_name = spi.getNativeStreamMetadataFormatName();
testStreamMetadataFormat(spi, fmt_name);
fmt_name = spi.getNativeImageMetadataFormatName();
testImageMetadataFormat(spi, fmt_name);
String[] fmt_names;
fmt_names = spi.getExtraStreamMetadataFormatNames();
for (int i = 0; fmt_names != null && i < fmt_names.length; i++) {
testStreamMetadataFormat(spi, fmt_names[i]);
}
fmt_names = spi.getExtraImageMetadataFormatNames();
for (int i = 0; fmt_names != null && i < fmt_names.length; i++) {
testImageMetadataFormat(spi, fmt_names[i]);
}
}
Enumeration keys = fmts.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
boolean val = ((Boolean) fmts.get(key)).booleanValue();
if (!val) {
throw new RuntimeException("Test failed: format " + key + "is not registered.");
}
}
}
use of javax.imageio.spi.ImageReaderSpi in project jdk8u_jdk by JetBrains.
the class ImageIO method getImageReader.
/**
* Returns an <code>ImageReader</code>corresponding to the given
* <code>ImageWriter</code>, if there is one, or <code>null</code>
* if the plug-in for this <code>ImageWriter</code> does not
* specify a corresponding <code>ImageReader</code>, or if the
* given <code>ImageWriter</code> is not registered. This method
* is provided principally for symmetry with
* <code>getImageWriter(ImageReader)</code>. Note that this
* method returns the "preferred" reader, which is the first in
* the list returned by
* javax.imageio.spi.ImageWriterSpi.<code>getImageReaderSpiNames()</code>.
*
* @param writer an instance of a registered <code>ImageWriter</code>.
*
* @return an <code>ImageReader</code>, or null.
*
* @exception IllegalArgumentException if <code>writer</code> is
* <code>null</code>.
*
* @see #getImageWriter(ImageReader)
* @see javax.imageio.spi.ImageWriterSpi#getImageReaderSpiNames()
*/
public static ImageReader getImageReader(ImageWriter writer) {
if (writer == null) {
throw new IllegalArgumentException("writer == null!");
}
ImageWriterSpi writerSpi = writer.getOriginatingProvider();
if (writerSpi == null) {
Iterator writerSpiIter;
// Ensure category is present
try {
writerSpiIter = theRegistry.getServiceProviders(ImageWriterSpi.class, false);
} catch (IllegalArgumentException e) {
return null;
}
while (writerSpiIter.hasNext()) {
ImageWriterSpi temp = (ImageWriterSpi) writerSpiIter.next();
if (temp.isOwnWriter(writer)) {
writerSpi = temp;
break;
}
}
if (writerSpi == null) {
return null;
}
}
String[] readerNames = writerSpi.getImageReaderSpiNames();
if (readerNames == null) {
return null;
}
Class readerSpiClass = null;
try {
readerSpiClass = Class.forName(readerNames[0], true, ClassLoader.getSystemClassLoader());
} catch (ClassNotFoundException e) {
return null;
}
ImageReaderSpi readerSpi = (ImageReaderSpi) theRegistry.getServiceProviderByClass(readerSpiClass);
if (readerSpi == null) {
return null;
}
try {
return readerSpi.createReaderInstance();
} catch (IOException e) {
// Deregister the spi in this case, but only as a readerSpi
theRegistry.deregisterServiceProvider(readerSpi, ImageReaderSpi.class);
return null;
}
}
Aggregations