}
@Override
public ChunkRaw createRawChunk() {
if (key == null || key.trim().length() == 0)
throw new PngjException("Text chunk key must be non empty");
try {
ByteArrayOutputStream ba = new ByteArrayOutputStream();
ba.write(ChunkHelper.toBytes(key));
ba.write(0); // separator
ba.write(compressed ? 1 : 0);
ba.write(0); // compression method (always 0)
ba.write(ChunkHelper.toBytes(langTag));
ba.write(0); // separator
ba.write(ChunkHelper.toBytesUTF8(translatedTag));
ba.write(0); // separator
byte[] textbytes = ChunkHelper.toBytesUTF8(val);
if (compressed) {
textbytes = ChunkHelper.compressBytes(textbytes, true);
}
ba.write(textbytes);
byte[] b = ba.toByteArray();
ChunkRaw chunk = createEmptyChunk(b.length, false);
chunk.data = b;
return chunk;
} catch (IOException e) {
throw new PngjException(e);
}
}