From 30d14f436e48ab0eacb14e1d1085202446b4fb12 Mon Sep 17 00:00:00 2001 From: ola Date: Thu, 15 Jan 2015 15:23:36 +0100 Subject: [PATCH 1/2] IPTCParser now takes the raw bytes of an IPTCRecord element into account. If it contains bytes then these bytes will be written into the file. Otherwise the string will be written using encoding iso8859-1. This allows to store values encoded to charsets different from iso8859-1 --- .../imaging/formats/jpeg/iptc/IptcParser.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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..1f5b93560 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.value.getBytes(); + } + 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); From 27ed8eb8768a13b02458b8c47b0c537f15f1dade Mon Sep 17 00:00:00 2001 From: ola Date: Thu, 15 Jan 2015 22:34:30 +0100 Subject: [PATCH 2/2] #4: typo - element.getRawBytes() instead of element.value.getBytes() --- .../apache/commons/imaging/formats/jpeg/iptc/IptcParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1f5b93560..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 @@ -444,7 +444,7 @@ public int compare(final IptcRecord e1, final IptcRecord e2) { */ final byte[] recordData; if( element.getRawBytes() != null && element.getRawBytes().length > 0 ) { - recordData = element.value.getBytes(); + recordData = element.getRawBytes(); } else { recordData = element.value.getBytes("ISO-8859-1");