JpegSegmentReader Class Reference

Collaboration diagram for JpegSegmentReader:

Collaboration graph
[legend]

List of all members.

Public Member Functions

final int getSegmentCount (byte segmentMarker)
 JpegSegmentReader (InputStream in) throws JpegProcessingException
 JpegSegmentReader (byte[] fileContents) throws JpegProcessingException
 JpegSegmentReader (File file) throws JpegProcessingException
byte[] readSegment (byte segmentMarker, int occurrence)
byte[] readSegment (byte segmentMarker) throws JpegProcessingException

Static Public Attributes

static final byte SEGMENT_APP0 = (byte)0xE0
static final byte SEGMENT_APP1 = (byte)0xE1
static final byte SEGMENT_APP2 = (byte)0xE2
static final byte SEGMENT_APP3 = (byte)0xE3
static final byte SEGMENT_APP4 = (byte)0xE4
static final byte SEGMENT_APP5 = (byte)0xE5
static final byte SEGMENT_APP6 = (byte)0xE6
static final byte SEGMENT_APP7 = (byte)0xE7
static final byte SEGMENT_APP8 = (byte)0xE8
static final byte SEGMENT_APP9 = (byte)0xE9
static final byte SEGMENT_APPA = (byte)0xEA
static final byte SEGMENT_APPB = (byte)0xEB
static final byte SEGMENT_APPC = (byte)0xEC
static final byte SEGMENT_APPD = (byte)0xED
static final byte SEGMENT_APPE = (byte)0xEE
static final byte SEGMENT_APPF = (byte)0xEF
static final byte SEGMENT_COM = (byte)0xFE
static final byte SEGMENT_DHT = (byte)0xC4
static final byte SEGMENT_DQT = (byte)0xDB
static final byte SEGMENT_SOF0 = (byte)0xC0
static final byte SEGMENT_SOI = (byte)0xD8

Private Member Functions

BufferedInputStream getJpegInputStream () throws JpegProcessingException
boolean isValidJpegHeaderBytes (InputStream fileStream) throws IOException
void readSegments () throws JpegProcessingException

Private Attributes

final byte[] _data
final File _file
HashMap _segmentDataMap
InputStream _stream

Static Private Attributes

static final byte MARKER_EOI = (byte)0xD9
static final byte SEGMENT_SOS = (byte)0xDA


Detailed Description

Performs read functions of Jpeg files, returning specific file segments. TODO add a findAvailableSegments() method TODO add more segment identifiers TODO add a getSegmentDescription() method, returning for example 'App1 application data segment, commonly containing Exif data'
Author:
Drew Noakes http://drewnoakes.com

Constructor & Destructor Documentation

JpegSegmentReader ( File  file  )  throws JpegProcessingException

Creates a JpegSegmentReader for a specific file.

Parameters:
file the Jpeg file to read segments from

JpegSegmentReader ( byte[]  fileContents  )  throws JpegProcessingException

Creates a JpegSegmentReader for a byte array.

Parameters:
fileContents the byte array containing Jpeg data

JpegSegmentReader ( InputStream  in  )  throws JpegProcessingException


Member Function Documentation

BufferedInputStream getJpegInputStream (  )  throws JpegProcessingException [private]

Private helper method to create a BufferedInputStream of Jpeg data from whichever data source was specified upon construction of this instance.

Returns:
a a BufferedInputStream of Jpeg data
Exceptions:
JpegProcessingException for any problems obtaining the stream

final int getSegmentCount ( byte  segmentMarker  ) 

boolean isValidJpegHeaderBytes ( InputStream  fileStream  )  throws IOException [private]

Helper method that validates the Jpeg file's magic number.

Parameters:
fileStream the InputStream to read bytes from, which must be positioned at its start (i.e. no bytes read yet)
Returns:
true if the magic number is Jpeg (0xFFD8)
Exceptions:
IOException for any problem in reading the file

byte [] readSegment ( byte  segmentMarker,
int  occurrence 
)

Reads the first instance of a given Jpeg segment, returning the contents as a byte array.

Parameters:
segmentMarker the byte identifier for the desired segment
occurrence the occurrence of the specified segment within the jpeg file
Returns:
the byte array if found, else null
Exceptions:
JpegProcessingException for any problems processing the Jpeg data, including inner IOExceptions

byte [] readSegment ( byte  segmentMarker  )  throws JpegProcessingException

Reads the first instance of a given Jpeg segment, returning the contents as a byte array.

Parameters:
segmentMarker the byte identifier for the desired segment
Returns:
the byte array if found, else null
Exceptions:
JpegProcessingException for any problems processing the Jpeg data, including inner IOExceptions

void readSegments (  )  throws JpegProcessingException [private]


Member Data Documentation

final byte [] _data [private]

Jpeg data as byte array.

final File _file [private]

Jpeg file.

HashMap _segmentDataMap [private]

InputStream _stream [private]

Jpeg data as an InputStream.

final byte MARKER_EOI = (byte)0xD9 [static, private]

Private, because one wouldn't search for it.

final byte SEGMENT_APP0 = (byte)0xE0 [static]

APP0 Jpeg segment identifier -- Jfif data.

final byte SEGMENT_APP1 = (byte)0xE1 [static]

APP1 Jpeg segment identifier -- where Exif data is kept.

final byte SEGMENT_APP2 = (byte)0xE2 [static]

APP2 Jpeg segment identifier.

final byte SEGMENT_APP3 = (byte)0xE3 [static]

APP3 Jpeg segment identifier.

final byte SEGMENT_APP4 = (byte)0xE4 [static]

APP4 Jpeg segment identifier.

final byte SEGMENT_APP5 = (byte)0xE5 [static]

APP5 Jpeg segment identifier.

final byte SEGMENT_APP6 = (byte)0xE6 [static]

APP6 Jpeg segment identifier.

final byte SEGMENT_APP7 = (byte)0xE7 [static]

APP7 Jpeg segment identifier.

final byte SEGMENT_APP8 = (byte)0xE8 [static]

APP8 Jpeg segment identifier.

final byte SEGMENT_APP9 = (byte)0xE9 [static]

APP9 Jpeg segment identifier.

final byte SEGMENT_APPA = (byte)0xEA [static]

APPA Jpeg segment identifier.

final byte SEGMENT_APPB = (byte)0xEB [static]

APPB Jpeg segment identifier.

final byte SEGMENT_APPC = (byte)0xEC [static]

APPC Jpeg segment identifier.

final byte SEGMENT_APPD = (byte)0xED [static]

APPD Jpeg segment identifier -- IPTC data in here.

final byte SEGMENT_APPE = (byte)0xEE [static]

APPE Jpeg segment identifier.

final byte SEGMENT_APPF = (byte)0xEF [static]

APPF Jpeg segment identifier.

final byte SEGMENT_COM = (byte)0xFE [static]

Comment segment identifier

final byte SEGMENT_DHT = (byte)0xC4 [static]

Define Huffman Table segment identifier.

final byte SEGMENT_DQT = (byte)0xDB [static]

Define Quantization Table segment identifier.

final byte SEGMENT_SOF0 = (byte)0xC0 [static]

Start-of-Frame Zero segment identifier.

final byte SEGMENT_SOI = (byte)0xD8 [static]

Start Of Image segment identifier.

final byte SEGMENT_SOS = (byte)0xDA [static, private]

Private, because this segment crashes my algorithm, and searching for it doesn't work (yet).


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:42:29 2012 for Project Wonder by  doxygen 1.5.8