diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java index 17698a067..ae615d7ad 100644 --- a/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java +++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java @@ -438,10 +438,20 @@ public int compare(final IptcRecord e1, final IptcRecord e2) { } bos.write(element.iptcType.getType()); - final byte[] recordData = element.value.getBytes("ISO-8859-1"); - if (!new String(recordData, "ISO-8859-1").equals(element.value)) { - throw new ImageWriteException( - "Invalid record value, not ISO-8859-1"); + /** + * favor raw bytes over value. This allows callers to use their + * own encoding of fields. + */ + final byte[] recordData; + if( element.getRawBytes() != null && element.getRawBytes().length > 0 ) { + recordData = element.getRawBytes(); + } + else { + recordData = element.value.getBytes("ISO-8859-1"); + if (!new String(recordData, "ISO-8859-1").equals(element.value)) { + throw new ImageWriteException( + "Invalid record value, not ISO-8859-1"); + } } bos.write2Bytes(recordData.length);