/** * Gets the byte order of the current InputStream. */ protected ByteOrder getByteOrder() { if( null != mTiffStream ) return mTiffStream.getByteOrder(); return null; }
/** * Equivalent to read(buffer, 0, buffer.length). */ protected int read( byte[] buffer ) throws IOException { return mTiffStream.read( buffer ); }
/** * Reads value of type {@link ExifTag#TYPE_LONG} from the InputStream. */ protected int readLong() throws IOException { return mTiffStream.readInt(); }
private CountedDataInputStream seekTiffData( InputStream inputStream ) throws IOException, ExifInvalidFormatException { CountedDataInputStream dataStream = new CountedDataInputStream( inputStream ); CountedDataInputStream tiffStream = null; int a = dataStream.readUnsignedByte(); int b = dataStream.readUnsignedByte(); marker = dataStream.readUnsignedByte(); if( marker != 0xff && prev == 0xff ) break; prev = marker; lh = dataStream.readByte(); ll = dataStream.readByte(); itemlen = ( ( lh & 0xff ) << 8 ) | ( ll & 0xff ); mUncompressedDataPosition = dataStream.getReadByteCount(); return tiffStream; tiffStream = new CountedDataInputStream( new ByteArrayInputStream( data, 8, itemlen - 8 ) ); tiffStream.setEnd( itemlen - 6 ); ignore = false; } else {
private ExifTag readTag() throws IOException, ExifInvalidFormatException { short tagId = mTiffStream.readShort(); short dataFormat = mTiffStream.readShort(); long numOfComp = mTiffStream.readUnsignedInt(); if( numOfComp > Integer.MAX_VALUE ) { throw new ExifInvalidFormatException( "Number of component is larger then Integer.MAX_VALUE" ); mTiffStream.skip( 4 ); return null; int dataSize = tag.getDataSize(); if( dataSize > 4 ) { long offset = mTiffStream.readUnsignedInt(); if( offset > Integer.MAX_VALUE ) { throw new ExifInvalidFormatException( "offset is larger then Integer.MAX_VALUE" ); mTiffStream.skip( 4 - dataSize ); tag.setOffset( mTiffStream.getReadByteCount() - 4 );
int offset = mTiffStream.getReadByteCount(); int endOfTags = mIfdStartOffset + OFFSET_SIZE + TAG_SIZE * mNumOfTagInIfd; if( offset < endOfTags ) { offsetSize = mCorrespondingEvent.firstEntry().getKey() - mTiffStream.getReadByteCount(); mNumOfTagInIfd = mTiffStream.readUnsignedShort(); mIfdStartOffset = entry.getKey(); if( mNumOfTagInIfd * TAG_SIZE + mIfdStartOffset + OFFSET_SIZE > mTiffStream.getEnd() ) { Log.w( TAG, "Invalid size of IFD " + mIfdType ); return EVENT_END;
public void readOrThrow( byte[] b ) throws IOException { readOrThrow( b, 0, b.length ); }
private void parseTiffHeader( final CountedDataInputStream stream ) throws IOException, ExifInvalidFormatException { short byteOrder = stream.readShort(); if( LITTLE_ENDIAN_TAG == byteOrder ) { stream.setByteOrder( ByteOrder.LITTLE_ENDIAN ); } else if( BIG_ENDIAN_TAG == byteOrder ) { stream.setByteOrder( ByteOrder.BIG_ENDIAN ); } else { throw new ExifInvalidFormatException( "Invalid TIFF header" ); } if( stream.readShort() != TIFF_HEADER_TAIL ) { throw new ExifInvalidFormatException( "Invalid TIFF header" ); } }
/** * When getting {@link #EVENT_NEW_TAG} in the tag area of IFD, the tag may * not contain the value if the size of the value is greater than 4 bytes. * When the value is not available here, call this method so that the parser * will emit {@link #EVENT_VALUE_OF_REGISTERED_TAG} when it reaches the area * where the value is located. * * @see #EVENT_VALUE_OF_REGISTERED_TAG */ protected void registerForTagValue( ExifTag tag ) { if( tag.getOffset() >= mTiffStream.getReadByteCount() ) { mCorrespondingEvent.put( tag.getOffset(), new ExifTagEvent( tag, true ) ); } }
/** * Reads value of type {@link ExifTag#TYPE_UNSIGNED_SHORT} from the * InputStream. */ protected int readUnsignedShort() throws IOException { return mTiffStream.readShort() & 0xffff; }
/** * 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}. */ protected String readString( int n, Charset charset ) throws IOException { if( n > 0 ) { return mTiffStream.readString( n, charset ); } else { return ""; } }
private CountedDataInputStream seekTiffData( InputStream inputStream ) throws IOException, ExifInvalidFormatException { CountedDataInputStream dataStream = new CountedDataInputStream( inputStream ); CountedDataInputStream tiffStream = null; int a = dataStream.readUnsignedByte(); int b = dataStream.readUnsignedByte(); marker = dataStream.readUnsignedByte(); if( marker != 0xff && prev == 0xff ) break; prev = marker; lh = dataStream.readByte(); ll = dataStream.readByte(); itemlen = ( ( lh & 0xff ) << 8 ) | ( ll & 0xff ); mUncompressedDataPosition = dataStream.getReadByteCount(); return tiffStream; tiffStream = new CountedDataInputStream( new ByteArrayInputStream( data, 8, itemlen - 8 ) ); tiffStream.setEnd( itemlen - 6 ); ignore = false; } else {
private ExifTag readTag() throws IOException, ExifInvalidFormatException { short tagId = mTiffStream.readShort(); short dataFormat = mTiffStream.readShort(); long numOfComp = mTiffStream.readUnsignedInt(); if( numOfComp > Integer.MAX_VALUE ) { throw new ExifInvalidFormatException( "Number of component is larger then Integer.MAX_VALUE" ); mTiffStream.skip( 4 ); return null; int dataSize = tag.getDataSize(); if( dataSize > 4 ) { long offset = mTiffStream.readUnsignedInt(); if( offset > Integer.MAX_VALUE ) { throw new ExifInvalidFormatException( "offset is larger then Integer.MAX_VALUE" ); mTiffStream.skip( 4 - dataSize ); tag.setOffset( mTiffStream.getReadByteCount() - 4 );
int offset = mTiffStream.getReadByteCount(); int endOfTags = mIfdStartOffset + OFFSET_SIZE + TAG_SIZE * mNumOfTagInIfd; if( offset < endOfTags ) { offsetSize = mCorrespondingEvent.firstEntry().getKey() - mTiffStream.getReadByteCount(); mNumOfTagInIfd = mTiffStream.readUnsignedShort(); mIfdStartOffset = entry.getKey(); if( mNumOfTagInIfd * TAG_SIZE + mIfdStartOffset + OFFSET_SIZE > mTiffStream.getEnd() ) { Log.w( TAG, "Invalid size of IFD " + mIfdType ); return EVENT_END;
public void readOrThrow( byte[] b ) throws IOException { readOrThrow( b, 0, b.length ); }
private void parseTiffHeader( final CountedDataInputStream stream ) throws IOException, ExifInvalidFormatException { short byteOrder = stream.readShort(); if( LITTLE_ENDIAN_TAG == byteOrder ) { stream.setByteOrder( ByteOrder.LITTLE_ENDIAN ); } else if( BIG_ENDIAN_TAG == byteOrder ) { stream.setByteOrder( ByteOrder.BIG_ENDIAN ); } else { throw new ExifInvalidFormatException( "Invalid TIFF header" ); } if( stream.readShort() != TIFF_HEADER_TAIL ) { throw new ExifInvalidFormatException( "Invalid TIFF header" ); } }
/** * When getting {@link #EVENT_NEW_TAG} in the tag area of IFD, the tag may * not contain the value if the size of the value is greater than 4 bytes. * When the value is not available here, call this method so that the parser * will emit {@link #EVENT_VALUE_OF_REGISTERED_TAG} when it reaches the area * where the value is located. * * @see #EVENT_VALUE_OF_REGISTERED_TAG */ protected void registerForTagValue( ExifTag tag ) { if( tag.getOffset() >= mTiffStream.getReadByteCount() ) { mCorrespondingEvent.put( tag.getOffset(), new ExifTagEvent( tag, true ) ); } }
/** * Reads value of type {@link ExifTag#TYPE_UNSIGNED_SHORT} from the * InputStream. */ protected int readUnsignedShort() throws IOException { return mTiffStream.readShort() & 0xffff; }
/** * 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}. */ protected String readString( int n, Charset charset ) throws IOException { if( n > 0 ) { return mTiffStream.readString( n, charset ); } else { return ""; } }
public String readString( int n, Charset charset ) throws IOException { byte buf[] = new byte[n]; readOrThrow( buf ); return new String( buf, charset ); } }