use of javax.imageio.ImageReader in project jdk8u_jdk by JetBrains.
the class CrashAfterDispose method main.
public static void main(String[] args) throws IOException {
InputStream bais = new ByteArrayInputStream(new byte[100]);
ImageInputStream iis = ImageIO.createImageInputStream(bais);
// find the JPEG reader
ImageReader reader = null;
Iterator readers = ImageIO.getImageReadersByFormatName("jpeg");
if (readers.hasNext()) {
reader = (ImageReader) readers.next();
} else {
throw new RuntimeException("Unable to find a reader!");
}
// dispose the reader, then poke and prod it... the reader should
// throw exceptions (which will be caught by this test), but it
// should not crash the VM
reader.dispose();
try {
reader.setInput(iis);
} catch (IllegalStateException e) {
}
try {
reader.read(0);
} catch (IllegalStateException e) {
}
try {
reader.abort();
} catch (IllegalStateException e) {
}
try {
reader.reset();
} catch (IllegalStateException e) {
}
try {
reader.dispose();
} catch (IllegalStateException e) {
}
// find the JPEG writer
ImageWriter writer = null;
Iterator writers = ImageIO.getImageWritersByFormatName("jpeg");
if (writers.hasNext()) {
writer = (ImageWriter) writers.next();
} else {
throw new RuntimeException("Unable to find a writer!");
}
// set up output stream
OutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
// dispose the writer, then poke and prod it... the writer should
// throw exceptions (which will be caught by this test), but it
// should not crash the VM
writer.dispose();
try {
writer.setOutput(ios);
} catch (IllegalStateException e) {
}
try {
writer.write(bi);
} catch (IllegalStateException e) {
}
try {
writer.abort();
} catch (IllegalStateException e) {
}
try {
writer.reset();
} catch (IllegalStateException e) {
}
try {
writer.dispose();
} catch (IllegalStateException e) {
}
}
use of javax.imageio.ImageReader in project jdk8u_jdk by JetBrains.
the class TruncatedImageWarningTest method main.
public static void main(String[] args) throws IOException {
String sep = System.getProperty("file.separator");
String dir = System.getProperty("test.src", ".");
String filePath = dir + sep + fileName;
System.out.println("Test file: " + filePath);
File f = new File(filePath);
ImageInputStream in = ImageIO.createImageInputStream(f);
ImageReader reader = ImageIO.getImageReaders(in).next();
TruncatedImageWarningTest twt = new TruncatedImageWarningTest();
reader.addIIOReadWarningListener(twt);
reader.setInput(in);
reader.read(0);
if (!twt.receivedWarning) {
throw new RuntimeException("No expected warning");
}
}
use of javax.imageio.ImageReader 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.ImageReader in project jdk8u_jdk by JetBrains.
the class ValidWbmpTest method main.
public static void main(String[] args) {
try {
String[] formats = { "JPEG", "PNG", "BMP" };
BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_BYTE_GRAY);
Graphics g = img.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, 100, 100);
g.setColor(Color.black);
g.fillRect(10, 10, 80, 80);
ImageReader ir = (ImageReader) ImageIO.getImageReadersByFormatName("WBMP").next();
if (ir == null) {
throw new RuntimeException("No readers for WBMP format!");
}
for (int i = 0; i < formats.length; i++) {
System.out.println("Test " + formats[i] + " stream...");
boolean passed = false;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, formats[i], baos);
baos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ImageInputStream iis = null;
iis = ImageIO.createImageInputStream(bais);
ir.setInput(iis);
try {
BufferedImage res = ir.read(0);
} catch (IIOException e) {
StackTraceElement[] stack = e.getStackTrace();
if (ir.getClass().getName().equals(stack[0].getClassName()) && "readHeader".equals(stack[0].getMethodName())) {
passed = true;
}
} catch (Throwable t) {
t.printStackTrace();
}
if (!passed) {
throw new RuntimeException("Test failed!");
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Unexpected exception. Test failed.");
}
}
use of javax.imageio.ImageReader in project jdk8u_jdk by JetBrains.
the class EmptyInputWbmpMetadataTest method main.
public static void main(String[] args) {
boolean isPassed = false;
ImageReader ir = (ImageReader) ImageIO.getImageReadersByFormatName(fmt).next();
if (ir == null) {
throw new RuntimeException("No available reader for " + fmt);
}
IIOMetadata meta = null;
try {
meta = ir.getImageMetadata(0);
} catch (IllegalStateException e) {
System.out.println("Correct exception was thrown. Test passed.");
isPassed = true;
} catch (IOException e) {
e.printStackTrace();
}
if (!isPassed) {
throw new RuntimeException("The IllegalStateException was not thrown." + "Test failed.");
}
}
Aggregations