final List<IptcBlock> blocks = data.getRawBlocks();
for (IptcBlock block : blocks) {
bos.write4Bytes(JpegConstants.CONST_8BIM);
if (block.blockType < 0 || block.blockType > 0xffff) {
throw new ImageWriteException("Invalid IPTC block type.");
}
bos.write2Bytes(block.blockType);
if (block.blockNameBytes.length > 255) {
throw new ImageWriteException("IPTC block name is too long: "
+ block.blockNameBytes.length);
}
bos.write(block.blockNameBytes.length);
bos.write(block.blockNameBytes);
if (block.blockNameBytes.length % 2 == 0) {
bos.write(0); // pad to even size, including length byte.
}
if (block.blockData.length > IptcConstants.IPTC_NON_EXTENDED_RECORD_MAXIMUM_SIZE) {
throw new ImageWriteException("IPTC block data is too long: "
+ block.blockData.length);
}
bos.write4Bytes(block.blockData.length);
bos.write(block.blockData);
if (block.blockData.length % 2 == 1) {