< prev index next >
test/javax/imageio/plugins/png/ITXtTest.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2008, 2016 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 19,38 ****
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
! /**
* @test
! * @bug 6541476
! * @summary Test verifies that ImageIO PNG plugin correcly handles the
* iTxt chunk (International textual data).
*
* @run main ITXtTest
*/
-
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
--- 19,37 ----
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
! /*
* @test
! * @bug 6541476 7059970
! * @summary Test verifies that ImageIO PNG plug-in correctly handles the
* iTxt chunk (International textual data).
*
* @run main ITXtTest
*/
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
*** 155,179 ****
System.out.println("Test: " + src.description);
File file = new File("test.png");
writeTo(file, src);
ITXtTest dst = readFrom(file);
-
if (dst == null || !dst.equals(src)) {
throw new RuntimeException("Test failed.");
}
!
System.out.println("Test passed.");
}
private static void writeTo(File f, ITXtTest t) {
BufferedImage src = createBufferedImage();
! try {
! ImageOutputStream imageOutputStream =
! ImageIO.createImageOutputStream(f);
ImageTypeSpecifier imageTypeSpecifier =
new ImageTypeSpecifier(src);
ImageWriter imageWriter =
ImageIO.getImageWritersByFormatName("PNG").next();
--- 154,181 ----
System.out.println("Test: " + src.description);
File file = new File("test.png");
+ try {
writeTo(file, src);
ITXtTest dst = readFrom(file);
if (dst == null || !dst.equals(src)) {
throw new RuntimeException("Test failed.");
}
! } catch (RuntimeException e) {
! throw e;
! } finally {
! file.delete();
! }
System.out.println("Test passed.");
}
private static void writeTo(File f, ITXtTest t) {
BufferedImage src = createBufferedImage();
! try (ImageOutputStream imageOutputStream =
! ImageIO.createImageOutputStream(f)) {
ImageTypeSpecifier imageTypeSpecifier =
new ImageTypeSpecifier(src);
ImageWriter imageWriter =
ImageIO.getImageWritersByFormatName("PNG").next();
*** 189,210 ****
IIOMetadataNode iTXt = t.getNode();
root.appendChild(iTXt);
m.setFromTree(format, root);
imageWriter.write(new IIOImage(src, null, m));
- imageOutputStream.close();
System.out.println("Writing done.");
} catch (Throwable e) {
throw new RuntimeException("Writing test failed.", e);
}
}
private static ITXtTest readFrom(File f) {
! try {
! ImageInputStream iis = ImageIO.createImageInputStream(f);
! ImageReader r = ImageIO.getImageReaders(iis).next();
! r.setInput(iis);
IIOImage dst = r.readAll(0, null);
// look for iTXt node
IIOMetadata m = dst.getMetadata();
--- 191,212 ----
IIOMetadataNode iTXt = t.getNode();
root.appendChild(iTXt);
m.setFromTree(format, root);
imageWriter.write(new IIOImage(src, null, m));
System.out.println("Writing done.");
} catch (Throwable e) {
throw new RuntimeException("Writing test failed.", e);
}
}
private static ITXtTest readFrom(File f) {
! try (ImageInputStream imageInputStream =
! ImageIO.createImageInputStream(f)) {
!
! ImageReader r = ImageIO.getImageReaders(imageInputStream).next();
! r.setInput(imageInputStream);
IIOImage dst = r.readAll(0, null);
// look for iTXt node
IIOMetadata m = dst.getMetadata();
*** 232,236 ****
--- 234,239 ----
graph.fillRect(32, 32, 64, 64);
graph.dispose();
return image;
}
}
+
< prev index next >