use of javax.imageio.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class WritingInterruptionTest method doTest.
public void doTest() {
try {
w.addIIOWriteProgressListener(this);
File f = File.createTempFile("writer_", ".jpg", pwd);
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
w.setOutput(ios);
Thread.sleep(70);
w.write(img);
Thread.sleep(70);
} catch (Exception e) {
/*
* we do expect that concurrent attempt to dispose this
* instance of image writer will be blocked. So, this image
* should be writen sucessfuly. Otherwise, something went wrong
* and we need to report test failure.
*/
throw new RuntimeException("Test FAILED", e);
} finally {
/*
* it would happen that concurrent invocation of dispose() method
* will be successful. Due to race condition it seems to be possible
* that dispose operation will be performed after than write() operation
* leaveled thread lock. In this case all subsequent calls for writer
* methods should results in IllegalStateException. So, we treat
* IllegalStateException as success. Everything else means test failure.
*/
try {
w.reset();
} catch (IllegalStateException e) {
System.out.println("Expected exception was caught: " + e);
} catch (Exception e) {
throw new RuntimeException("Test FAILED.", e);
}
}
System.out.println("Test PASSED.");
}
use of javax.imageio.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class DestTypeTest method writeTest.
public byte[] writeTest(BufferedImage bi, ImageWriteParam p, IIOMetadata m) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// write test image as jpeg
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
w.setOutput(ios);
w.write(null, new IIOImage(bi, null, m), p);
ios.close();
return baos.toByteArray();
}
use of javax.imageio.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class ImageStreamFromRAF method main.
public static void main(String[] args) {
try {
File f = new File("ImageInputStreamFromRAF.tmp");
RandomAccessFile raf = new RandomAccessFile(f, "rw");
ImageInputStream istream = ImageIO.createImageInputStream(raf);
ImageOutputStream ostream = ImageIO.createImageOutputStream(raf);
f.delete();
if (istream == null) {
throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) returned null!");
}
if (ostream == null) {
throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) returned null!");
}
if (!(istream instanceof FileImageInputStream)) {
throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) did not return a FileImageInputStream!");
}
if (!(ostream instanceof FileImageOutputStream)) {
throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) did not return a FileImageOutputStream!");
}
} catch (IOException ioe) {
throw new RuntimeException("Unexpected IOException: " + ioe);
}
}
use of javax.imageio.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class ConcurrentWritingTest method run.
public void run() {
try {
File f = File.createTempFile("writer_", ".jpg", pwd);
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
w.setOutput(ios);
Thread.sleep(70);
w.write(img);
Thread.sleep(70);
w.reset();
} catch (IllegalStateException e) {
System.out.println(e);
} catch (IOException e) {
System.out.println(e);
} catch (Throwable e) {
// Unexpected exception. Test failed.
throw new RuntimeException("Test failed.", e);
} finally {
synchronized (lock) {
completeCount++;
}
}
}
use of javax.imageio.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class EncodeSubImageTest method write.
private void write(File f, boolean subsample) throws IOException {
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
writer.setOutput(ios);
ImageWriteParam p = writer.getDefaultWriteParam();
if (subsample) {
p.setSourceSubsampling(subSampleX, subSampleY, 0, 0);
}
writer.write(null, new IIOImage(img, null, null), p);
ios.close();
writer.reset();
}
Aggregations