Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
* Windows XP onwards store some tags using UTF-16LE, but the field type is byte
* - here we deal with this.
*/
public class TagInfoXpString extends TagInfo {
public class TagInfoXpString extends TagInfoAsciiOrByte {

public TagInfoXpString(final String name, final int tag, final int length,
final TiffDirectoryType directoryType) {
super(name, tag, FieldType.BYTE, length, directoryType);
super(name, tag, length, directoryType);
}

@Override
Expand All @@ -41,23 +42,34 @@ public byte[] encodeValue(final FieldType fieldType, final Object value, final B
if (!(value instanceof String)) {
throw new ImageWriteException("Text value not String", value);
}
final String s = (String) value;
try {
return s.getBytes("UTF-16LE");
} catch (final UnsupportedEncodingException cannotHappen) {
return null;

if (fieldType == FieldType.ASCII) {
return super.encodeValue(fieldType, value, byteOrder);
} else if (fieldType == FieldType.BYTE) {
final String s = (String) value;
try {
return s.getBytes("UTF-16LE");
} catch (final UnsupportedEncodingException cannotHappen) {
return null;
}
} else {
throw new ImageWriteException("Invalid data", value);
}
}

@Override
public String getValue(final TiffField entry) throws ImageReadException {
if (entry.getFieldType() != FieldType.BYTE) {
throw new ImageReadException("Text field not encoded as bytes.");
if (entry.getFieldType() == FieldType.ASCII) {
return (String)super.getValue(entry);
}
try {
return new String(entry.getByteArrayValue(), "UTF-16LE");
} catch (final UnsupportedEncodingException cannotHappen) {
return null;
else if (entry.getFieldType() == FieldType.BYTE) {
try {
return new String(entry.getByteArrayValue(), "UTF-16LE");
} catch (final UnsupportedEncodingException cannotHappen) {
return null;
}
} else {
throw new ImageReadException("Text field not encoded as ascii or bytes.");
}
}
}