public PngChunkItxt(final int length, final int chunkType, final int crc, final byte[] bytes)
throws ImageReadException, IOException {
super(length, chunkType, crc, bytes);
int terminator = findNull(bytes);
if (terminator < 0) {
throw new ImageReadException(
"PNG iTXt chunk keyword is not terminated.");
}
keyword = new String(bytes, 0, terminator, "ISO-8859-1");
int index = terminator + 1;
final int compressionFlag = bytes[index++];
if (compressionFlag != 0 && compressionFlag != 1) {
throw new ImageReadException(
"PNG iTXt chunk has invalid compression flag: "
+ compressionFlag);
}
final boolean compressed = compressionFlag == 1;
final int compressionMethod = bytes[index++];
if (compressed && compressionMethod != PngConstants.COMPRESSION_DEFLATE_INFLATE) {
throw new ImageReadException("PNG iTXt chunk has unexpected compression method: " + compressionMethod);
}
terminator = findNull(bytes, index);
if (terminator < 0) {
throw new ImageReadException("PNG iTXt chunk language tag is not terminated.");
}
languageTag = new String(bytes, index, terminator - index, "ISO-8859-1");
index = terminator + 1;
terminator = findNull(bytes, index);
if (terminator < 0) {
throw new ImageReadException("PNG iTXt chunk translated keyword is not terminated.");
}
translatedKeyword = new String(bytes, index, terminator - index, "utf-8");
index = terminator + 1;