FileDocCategorySizeDatePackage
ExifData.javaAPI DocAndroid 5.1 API9912Thu Mar 12 22:22:42 GMT 2015com.android.gallery3d.exif

ExifData

public class ExifData extends Object
This class stores the EXIF header in IFDs according to the JPEG specification. It is the result produced by {@link ExifReader}.
see
ExifReader
see
IfdData

Fields Summary
private static final String
TAG
private static final byte[]
USER_COMMENT_ASCII
private static final byte[]
USER_COMMENT_JIS
private static final byte[]
USER_COMMENT_UNICODE
private final IfdData[]
mIfdDatas
private byte[]
mThumbnail
private ArrayList
mStripBytes
private final ByteOrder
mByteOrder
Constructors Summary
ExifData(ByteOrder order)


      
        mByteOrder = order;
    
Methods Summary
protected voidaddIfdData(IfdData data)
Adds IFD data. If IFD data of the same type already exists, it will be replaced by the new data.

        mIfdDatas[data.getId()] = data;
    
protected ExifTagaddTag(ExifTag tag)
Adds the given ExifTag to its default IFD and returns an existing ExifTag with the same TID or null if none exist.

        if (tag != null) {
            int ifd = tag.getIfd();
            return addTag(tag, ifd);
        }
        return null;
    
protected ExifTagaddTag(ExifTag tag, int ifdId)
Adds the given ExifTag to the given IFD and returns an existing ExifTag with the same TID or null if none exist.

        if (tag != null && ExifTag.isValidIfd(ifdId)) {
            IfdData ifdData = getOrCreateIfdData(ifdId);
            return ifdData.setTag(tag);
        }
        return null;
    
protected voidclearThumbnailAndStrips()

        mThumbnail = null;
        mStripBytes.clear();
    
public booleanequals(java.lang.Object obj)

        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (obj instanceof ExifData) {
            ExifData data = (ExifData) obj;
            if (data.mByteOrder != mByteOrder ||
                    data.mStripBytes.size() != mStripBytes.size() ||
                    !Arrays.equals(data.mThumbnail, mThumbnail)) {
                return false;
            }
            for (int i = 0; i < mStripBytes.size(); i++) {
                if (!Arrays.equals(data.mStripBytes.get(i), mStripBytes.get(i))) {
                    return false;
                }
            }
            for (int i = 0; i < IfdId.TYPE_IFD_COUNT; i++) {
                IfdData ifd1 = data.getIfdData(i);
                IfdData ifd2 = getIfdData(i);
                if (ifd1 != ifd2 && ifd1 != null && !ifd1.equals(ifd2)) {
                    return false;
                }
            }
            return true;
        }
        return false;
    
protected java.util.ListgetAllTags()
Returns a list of all {@link ExifTag}s in the ExifData or null if there are none.

        ArrayList<ExifTag> ret = new ArrayList<ExifTag>();
        for (IfdData d : mIfdDatas) {
            if (d != null) {
                ExifTag[] tags = d.getAllTags();
                if (tags != null) {
                    for (ExifTag t : tags) {
                        ret.add(t);
                    }
                }
            }
        }
        if (ret.size() == 0) {
            return null;
        }
        return ret;
    
protected java.util.ListgetAllTagsForIfd(int ifd)
Returns a list of all {@link ExifTag}s in a given IFD or null if there are none.

        IfdData d = mIfdDatas[ifd];
        if (d == null) {
            return null;
        }
        ExifTag[] tags = d.getAllTags();
        if (tags == null) {
            return null;
        }
        ArrayList<ExifTag> ret = new ArrayList<ExifTag>(tags.length);
        for (ExifTag t : tags) {
            ret.add(t);
        }
        if (ret.size() == 0) {
            return null;
        }
        return ret;
    
protected java.util.ListgetAllTagsForTagId(short tag)
Returns a list of all {@link ExifTag}s with a given TID or null if there are none.

        ArrayList<ExifTag> ret = new ArrayList<ExifTag>();
        for (IfdData d : mIfdDatas) {
            if (d != null) {
                ExifTag t = d.getTag(tag);
                if (t != null) {
                    ret.add(t);
                }
            }
        }
        if (ret.size() == 0) {
            return null;
        }
        return ret;
    
protected java.nio.ByteOrdergetByteOrder()
Gets the byte order.

        return mByteOrder;
    
protected byte[]getCompressedThumbnail()
Gets the compressed thumbnail. Returns null if there is no compressed thumbnail.

see
#hasCompressedThumbnail()

        return mThumbnail;
    
protected IfdDatagetIfdData(int ifdId)
Returns the {@link IfdData} object corresponding to a given IFD if it exists or null.

        if (ExifTag.isValidIfd(ifdId)) {
            return mIfdDatas[ifdId];
        }
        return null;
    
protected IfdDatagetOrCreateIfdData(int ifdId)
Returns the {@link IfdData} object corresponding to a given IFD or generates one if none exist.

        IfdData ifdData = mIfdDatas[ifdId];
        if (ifdData == null) {
            ifdData = new IfdData(ifdId);
            mIfdDatas[ifdId] = ifdData;
        }
        return ifdData;
    
protected byte[]getStrip(int index)
Gets the strip at the specified index.

exceptions
#IndexOutOfBoundException

        return mStripBytes.get(index);
    
protected intgetStripCount()
Gets the strip count.

        return mStripBytes.size();
    
protected ExifTaggetTag(short tag, int ifd)
Returns the tag with a given TID in the given IFD if the tag exists. Otherwise returns null.

        IfdData ifdData = mIfdDatas[ifd];
        return (ifdData == null) ? null : ifdData.getTag(tag);
    
protected java.lang.StringgetUserComment()
Decodes the user comment tag into string as specified in the EXIF standard. Returns null if decoding failed.

        IfdData ifdData = mIfdDatas[IfdId.TYPE_IFD_0];
        if (ifdData == null) {
            return null;
        }
        ExifTag tag = ifdData.getTag(ExifInterface.getTrueTagKey(ExifInterface.TAG_USER_COMMENT));
        if (tag == null) {
            return null;
        }
        if (tag.getComponentCount() < 8) {
            return null;
        }

        byte[] buf = new byte[tag.getComponentCount()];
        tag.getBytes(buf);

        byte[] code = new byte[8];
        System.arraycopy(buf, 0, code, 0, 8);

        try {
            if (Arrays.equals(code, USER_COMMENT_ASCII)) {
                return new String(buf, 8, buf.length - 8, "US-ASCII");
            } else if (Arrays.equals(code, USER_COMMENT_JIS)) {
                return new String(buf, 8, buf.length - 8, "EUC-JP");
            } else if (Arrays.equals(code, USER_COMMENT_UNICODE)) {
                return new String(buf, 8, buf.length - 8, "UTF-16");
            } else {
                return null;
            }
        } catch (UnsupportedEncodingException e) {
            Log.w(TAG, "Failed to decode the user comment");
            return null;
        }
    
protected booleanhasCompressedThumbnail()
Returns true it this header contains a compressed thumbnail.

        return mThumbnail != null;
    
protected booleanhasUncompressedStrip()
Returns true if this header contains uncompressed strip.

        return mStripBytes.size() != 0;
    
protected voidremoveTag(short tagId, int ifdId)
Removes the tag with a given TID and IFD.

        IfdData ifdData = mIfdDatas[ifdId];
        if (ifdData == null) {
            return;
        }
        ifdData.removeTag(tagId);
    
protected voidremoveThumbnailData()
Removes the thumbnail and its related tags. IFD1 will be removed.

        clearThumbnailAndStrips();
        mIfdDatas[IfdId.TYPE_IFD_1] = null;
    
protected voidsetCompressedThumbnail(byte[] thumbnail)
Sets the compressed thumbnail.

        mThumbnail = thumbnail;
    
protected voidsetStripBytes(int index, byte[] strip)
Adds an uncompressed strip.

        if (index < mStripBytes.size()) {
            mStripBytes.set(index, strip);
        } else {
            for (int i = mStripBytes.size(); i < index; i++) {
                mStripBytes.add(null);
            }
            mStripBytes.add(strip);
        }