Search in sources :

Example 51 with ImageOutputStream

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.");
}
Also used : File(java.io.File) ImageOutputStream(javax.imageio.stream.ImageOutputStream) IOException(java.io.IOException)

Example 52 with ImageOutputStream

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImageOutputStream(javax.imageio.stream.ImageOutputStream) IIOImage(javax.imageio.IIOImage)

Example 53 with ImageOutputStream

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);
    }
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) RandomAccessFile(java.io.RandomAccessFile) FileImageOutputStream(javax.imageio.stream.FileImageOutputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FileImageOutputStream(javax.imageio.stream.FileImageOutputStream) ImageOutputStream(javax.imageio.stream.ImageOutputStream)

Example 54 with ImageOutputStream

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++;
        }
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) ImageOutputStream(javax.imageio.stream.ImageOutputStream)

Example 55 with ImageOutputStream

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();
}
Also used : ImageWriteParam(javax.imageio.ImageWriteParam) ImageOutputStream(javax.imageio.stream.ImageOutputStream) IIOImage(javax.imageio.IIOImage)

Aggregations

ImageOutputStream (javax.imageio.stream.ImageOutputStream)64 ImageWriter (javax.imageio.ImageWriter)41 BufferedImage (java.awt.image.BufferedImage)37 ByteArrayOutputStream (java.io.ByteArrayOutputStream)36 IIOImage (javax.imageio.IIOImage)33 IOException (java.io.IOException)26 ImageWriteParam (javax.imageio.ImageWriteParam)26 File (java.io.File)24 IIOMetadata (javax.imageio.metadata.IIOMetadata)15 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)12 Iterator (java.util.Iterator)9 ImageInputStream (javax.imageio.stream.ImageInputStream)9 ImageReader (javax.imageio.ImageReader)7 MemoryCacheImageOutputStream (javax.imageio.stream.MemoryCacheImageOutputStream)7 Graphics2D (java.awt.Graphics2D)5 FileOutputStream (java.io.FileOutputStream)5 Color (java.awt.Color)4 Graphics (java.awt.Graphics)4 OutputStream (java.io.OutputStream)4