com.drew.metadata.jpeg
Class JpegReader

java.lang.Object
  extended by com.drew.metadata.jpeg.JpegReader
All Implemented Interfaces:
MetadataReader

public class JpegReader
extends Object
implements MetadataReader

Decodes Jpeg SOF0 data, populating a Metadata object with tag values in a JpegDirectory.

Author:
Darrell Silver http://www.darrellsilver.com and Drew Noakes

Field Summary
private  byte[] _data
          The SOF0 data segment.
 
Constructor Summary
JpegReader(byte[] data)
          Creates a JpegReader for a byte[] containing JPEG data.
JpegReader(File jpegFile)
          Creates a new JpegReader for the specified Jpeg jpegFile.
JpegReader(InputStream is)
          Creates a JpegReader for a JPEG stream.
 
Method Summary
 Metadata extract()
          Performs the Jpeg data extraction, returning a new instance of Metadata.
 Metadata extract(Metadata metadata)
          Performs the Jpeg data extraction, adding found values to the specified instance of Metadata.
private  int get16Bits(int offset)
          Returns an int calculated from one byte of data at the specified offset.
private  int get32Bits(int offset)
          Returns an int calculated from two bytes of data at the specified offset (MSB, LSB).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_data

private final byte[] _data
The SOF0 data segment.

Constructor Detail

JpegReader

public JpegReader(File jpegFile)
           throws JpegProcessingException
Creates a new JpegReader for the specified Jpeg jpegFile.

Throws:
JpegProcessingException

JpegReader

public JpegReader(InputStream is)
           throws JpegProcessingException
Creates a JpegReader for a JPEG stream.

Parameters:
is - JPEG stream. Stream will be closed.
Throws:
JpegProcessingException

JpegReader

public JpegReader(byte[] data)
Creates a JpegReader for a byte[] containing JPEG data.

Parameters:
data - the contents of an entire JPEG file as a byte[]
Method Detail

extract

public Metadata extract()
Performs the Jpeg data extraction, returning a new instance of Metadata.

Specified by:
extract in interface MetadataReader
Returns:
The populated Metadata object.

extract

public Metadata extract(Metadata metadata)
Performs the Jpeg data extraction, adding found values to the specified instance of Metadata.

Specified by:
extract in interface MetadataReader
Returns:
The updated Metadata object.

get32Bits

private int get32Bits(int offset)
               throws MetadataException
Returns an int calculated from two bytes of data at the specified offset (MSB, LSB).

Parameters:
offset - position within the data buffer to read first byte
Returns:
the 32 bit int value, between 0x0000 and 0xFFFF
Throws:
MetadataException

get16Bits

private int get16Bits(int offset)
               throws MetadataException
Returns an int calculated from one byte of data at the specified offset.

Parameters:
offset - position within the data buffer to read byte
Returns:
the 16 bit int value, between 0x00 and 0xFF
Throws:
MetadataException