diff options
author | Earl Ou <shunhsingou@google.com> | 2012-10-19 16:50:34 +0800 |
---|---|---|
committer | Earl Ou <shunhsingou@google.com> | 2012-10-31 14:48:57 +0800 |
commit | 1ec60b41b2b45da482f9318bae82486d82486db8 (patch) | |
tree | 19c98fb7129f59633eabca8d02a38cf69641358f /gallerycommon/src/com/android/gallery3d/exif/ExifParser.java | |
parent | bc6773761fa669f6090b8a1f9a08d9283b94a2ed (diff) | |
download | android_packages_apps_Snap-1ec60b41b2b45da482f9318bae82486d82486db8.tar.gz android_packages_apps_Snap-1ec60b41b2b45da482f9318bae82486d82486db8.tar.bz2 android_packages_apps_Snap-1ec60b41b2b45da482f9318bae82486d82486db8.zip |
Handle the last null byte in Exif tag.
Change-Id: Ic802810d11518dfeb80d1338db65b2e1e1cc8476
Diffstat (limited to 'gallerycommon/src/com/android/gallery3d/exif/ExifParser.java')
-rw-r--r-- | gallerycommon/src/com/android/gallery3d/exif/ExifParser.java | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java b/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java index edc8f190f..2f5c5438d 100644 --- a/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java +++ b/gallerycommon/src/com/android/gallery3d/exif/ExifParser.java @@ -136,6 +136,8 @@ public class ExifParser { private static final int TAG_SIZE = 12; private static final int OFFSET_SIZE = 2; + private static final Charset US_ASCII = Charset.forName("US-ASCII"); + private final CountedDataInputStream mTiffStream; private final int mOptions; private int mIfdStartOffset = 0; @@ -665,26 +667,25 @@ public class ExifParser { /** * Reads a String from the InputStream with US-ASCII charset. + * The parser will read n bytes and convert it to ascii string. * This is used for reading values of type {@link ExifTag#TYPE_ASCII}. */ public String readString(int n) throws IOException { - if (n > 0) { - byte[] buf = new byte[n]; - mTiffStream.readOrThrow(buf); - return new String(buf, 0, n - 1, "US-ASCII"); - } else { - return ""; - } + return readString(n, US_ASCII); } /** * Reads a String from the InputStream with the given charset. + * The parser will read n bytes and convert it to string. * This is used for reading values of type {@link ExifTag#TYPE_ASCII}. */ public String readString(int n, Charset charset) throws IOException { - byte[] buf = new byte[n]; - mTiffStream.readOrThrow(buf); - return new String(buf, 0, n - 1, charset); + if (n > 0) { + byte[] buf = new byte[n]; + return mTiffStream.readString(n, charset); + } else { + return ""; + } } /** @@ -763,4 +764,4 @@ public class ExifParser { public ByteOrder getByteOrder() { return mTiffStream.getByteOrder(); } -}
\ No newline at end of file +} |