/* * 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. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * 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 6782079 * @summary Write and read a PNG file including an non-latin1 iTXt chunk * Test also verifies that trunkated png images does not cause * an OoutOfMemory error. * * @run main ItxtUtf8Test * * @run main/othervm/timeout=10 -Xmx6m ItxtUtf8Test truncate
*/
byte[] bytes = os.toByteArray(); if (dump)
System.out.write(bytes); if (findBytes(VBYTES, bytes) < 0) thrownew AssertionError("verbatim block not found"); if (findBytes(CBYTES, bytes) < 0) thrownew AssertionError("compressed block not found"); int length = bytes.length; if (truncate)
length = findBytes(VBYTES, bytes) + 32;
ImageReader ir = ImageIO.getImageReader(iw);
ByteArrayInputStream is = new ByteArrayInputStream(bytes, 0, length);
ImageInputStream iis = new MemoryCacheImageInputStream(is);
ir.setInput(iis);
meta = ir.getImageMetadata(0);
Node node = meta.getAsTree(format); for (node = node.getFirstChild();
!"iTXt".equals(node.getNodeName());
node = node.getNextSibling()); boolean verbatimSeen = false, compressedSeen = false; for (node = node.getFirstChild();
node != null;
node = node.getNextSibling()) {
entry = (Element)node;
String keyword = entry.getAttribute("keyword");
String translatedKeyword = entry.getAttribute("translatedKeyword");
String text = entry.getAttribute("text"); if ("verbatim".equals(keyword)) { if (verbatimSeen) thrownew AssertionError("Duplicate");
verbatimSeen = true; if (!VERBATIM.equals(translatedKeyword)) thrownew AssertionError("Wrong translated keyword"); if (!TEXT.equals(text)) thrownew AssertionError("Wrong text");
} elseif ("compressed".equals(keyword)) { if (compressedSeen) thrownew AssertionError("Duplicate");
compressedSeen = true; if (!COMPRESSED.equals(translatedKeyword)) thrownew AssertionError("Wrong translated keyword"); if (!TEXT.equals(text)) thrownew AssertionError("Wrong text");
} else { thrownew AssertionError("Unexpected keyword");
}
} if (!(verbatimSeen && compressedSeen)) thrownew AssertionError("Missing chunk");
}
privatestaticfinalint findBytes(byte[] needle, byte[] haystack) {
HAYSTACK: for (int h = 0; h <= haystack.length - needle.length; ++h) { for (int n = 0; n < needle.length; ++n) { if (needle[n] != haystack[h + n]) { continue HAYSTACK;
}
} return h;
} return -1;
}
}
Messung V0.5
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.10Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.