com.drew.imaging.jpeg
Class JpegSegmentReader

java.lang.Object
  extended by com.drew.imaging.jpeg.JpegSegmentReader

public class JpegSegmentReader
extends Object

Performs read functions of Jpeg files, returning specific file segments.

Author:
Drew Noakes http://drewnoakes.com

Field Summary
static byte SEGMENT_APP0
          APP0 Jpeg segment identifier -- JFIF data (also JFXX apparently).
static byte SEGMENT_APP1
          APP1 Jpeg segment identifier -- where Exif data is kept.
static byte SEGMENT_APP2
          APP2 Jpeg segment identifier.
static byte SEGMENT_APP3
          APP3 Jpeg segment identifier.
static byte SEGMENT_APP4
          APP4 Jpeg segment identifier.
static byte SEGMENT_APP5
          APP5 Jpeg segment identifier.
static byte SEGMENT_APP6
          APP6 Jpeg segment identifier.
static byte SEGMENT_APP7
          APP7 Jpeg segment identifier.
static byte SEGMENT_APP8
          APP8 Jpeg segment identifier.
static byte SEGMENT_APP9
          APP9 Jpeg segment identifier.
static byte SEGMENT_APPA
          APPA (App10) Jpeg segment identifier -- can hold Unicode comments.
static byte SEGMENT_APPB
          APPB (App11) Jpeg segment identifier.
static byte SEGMENT_APPC
          APPC (App12) Jpeg segment identifier.
static byte SEGMENT_APPD
          APPD (App13) Jpeg segment identifier -- IPTC data in here.
static byte SEGMENT_APPE
          APPE (App14) Jpeg segment identifier.
static byte SEGMENT_APPF
          APPF (App15) Jpeg segment identifier.
static byte SEGMENT_COM
          Jpeg comment segment identifier.
static byte SEGMENT_DHT
          Define Huffman Table segment identifier.
static byte SEGMENT_DQT
          Define Quantization Table segment identifier.
static byte SEGMENT_SOF0
          Start-of-Frame Zero segment identifier.
static byte SEGMENT_SOI
          Start Of Image segment identifier.
 
Constructor Summary
JpegSegmentReader(byte[] fileContents)
          Creates a JpegSegmentReader for a byte array.
JpegSegmentReader(File file)
          Creates a JpegSegmentReader for a specific file.
JpegSegmentReader(InputStream inputStream, boolean waitForBytes)
          Creates a JpegSegmentReader for an InputStream.
 
Method Summary
 int getSegmentCount(byte segmentMarker)
          Returns the number of segments having the specified JPEG segment marker.
 JpegSegmentData getSegmentData()
          Returns the JpegSegmentData object used by this reader.
 byte[] readSegment(byte segmentMarker)
          Reads the first instance of a given Jpeg segment, returning the contents as a byte array.
 byte[] readSegment(byte segmentMarker, int occurrence)
          Reads the Nth instance of a given Jpeg segment, returning the contents as a byte array.
 Iterable<byte[]> readSegments(byte segmentMarker)
          Returns all instances of a given Jpeg segment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEGMENT_APP0

public static final byte SEGMENT_APP0
APP0 Jpeg segment identifier -- JFIF data (also JFXX apparently).

See Also:
Constant Field Values

SEGMENT_APP1

public static final byte SEGMENT_APP1
APP1 Jpeg segment identifier -- where Exif data is kept. XMP data is also kept in here, though usually in a second instance.

See Also:
Constant Field Values

SEGMENT_APP2

public static final byte SEGMENT_APP2
APP2 Jpeg segment identifier.

See Also:
Constant Field Values

SEGMENT_APP3

public static final byte SEGMENT_APP3
APP3 Jpeg segment identifier.

See Also:
Constant Field Values

SEGMENT_APP4

public static final byte SEGMENT_APP4
APP4 Jpeg segment identifier.

See Also:
Constant Field Values

SEGMENT_APP5

public static final byte SEGMENT_APP5
APP5 Jpeg segment identifier.

See Also:
Constant Field Values

SEGMENT_APP6

public static final byte SEGMENT_APP6
APP6 Jpeg segment identifier.

See Also:
Constant Field Values

SEGMENT_APP7

public static final byte SEGMENT_APP7
APP7 Jpeg segment identifier.

See Also:
Constant Field Values

SEGMENT_APP8

public static final byte SEGMENT_APP8
APP8 Jpeg segment identifier.

See Also:
Constant Field Values

SEGMENT_APP9

public static final byte SEGMENT_APP9
APP9 Jpeg segment identifier.

See Also:
Constant Field Values

SEGMENT_APPA

public static final byte SEGMENT_APPA
APPA (App10) Jpeg segment identifier -- can hold Unicode comments.

See Also:
Constant Field Values

SEGMENT_APPB

public static final byte SEGMENT_APPB
APPB (App11) Jpeg segment identifier.

See Also:
Constant Field Values

SEGMENT_APPC

public static final byte SEGMENT_APPC
APPC (App12) Jpeg segment identifier.

See Also:
Constant Field Values

SEGMENT_APPD

public static final byte SEGMENT_APPD
APPD (App13) Jpeg segment identifier -- IPTC data in here.

See Also:
Constant Field Values

SEGMENT_APPE

public static final byte SEGMENT_APPE
APPE (App14) Jpeg segment identifier.

See Also:
Constant Field Values

SEGMENT_APPF

public static final byte SEGMENT_APPF
APPF (App15) Jpeg segment identifier.

See Also:
Constant Field Values

SEGMENT_SOI

public static final byte SEGMENT_SOI
Start Of Image segment identifier.

See Also:
Constant Field Values

SEGMENT_DQT

public static final byte SEGMENT_DQT
Define Quantization Table segment identifier.

See Also:
Constant Field Values

SEGMENT_DHT

public static final byte SEGMENT_DHT
Define Huffman Table segment identifier.

See Also:
Constant Field Values

SEGMENT_SOF0

public static final byte SEGMENT_SOF0
Start-of-Frame Zero segment identifier.

See Also:
Constant Field Values

SEGMENT_COM

public static final byte SEGMENT_COM
Jpeg comment segment identifier.

See Also:
Constant Field Values
Constructor Detail

JpegSegmentReader

public JpegSegmentReader(File file)
                  throws JpegProcessingException,
                         IOException
Creates a JpegSegmentReader for a specific file.

Parameters:
file - the Jpeg file to read segments from
Throws:
JpegProcessingException
IOException

JpegSegmentReader

public JpegSegmentReader(byte[] fileContents)
                  throws JpegProcessingException
Creates a JpegSegmentReader for a byte array.

Parameters:
fileContents - the byte array containing Jpeg data
Throws:
JpegProcessingException

JpegSegmentReader

public JpegSegmentReader(InputStream inputStream,
                         boolean waitForBytes)
                  throws JpegProcessingException
Creates a JpegSegmentReader for an InputStream.

Parameters:
inputStream - the InputStream containing Jpeg data
Throws:
JpegProcessingException
Method Detail

readSegment

public byte[] readSegment(byte segmentMarker)
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

readSegment

public byte[] readSegment(byte segmentMarker,
                          int occurrence)
Reads the Nth 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

readSegments

public Iterable<byte[]> readSegments(byte segmentMarker)
Returns all instances of a given Jpeg segment. If no instances exist, an empty sequence is returned.

Parameters:
segmentMarker - a number which identifies the type of Jpeg segment being queried
Returns:
zero or more byte arrays, each holding the data of a Jpeg segment

getSegmentCount

public final int getSegmentCount(byte segmentMarker)
Returns the number of segments having the specified JPEG segment marker.

Parameters:
segmentMarker - the JPEG segment identifying marker.
Returns:
the count of matching segments.

getSegmentData

public final JpegSegmentData getSegmentData()
Returns the JpegSegmentData object used by this reader.

Returns:
the JpegSegmentData object.


Copyright © 2012. All Rights Reserved.