com.drew.imaging.jpeg
Class JpegSegmentData

java.lang.Object
  extended by com.drew.imaging.jpeg.JpegSegmentData
All Implemented Interfaces:
Serializable

public class JpegSegmentData
extends Object
implements Serializable

Holds a collection of Jpeg data segments. This need not necessarily be all segments within the Jpeg. For example, it may be convenient to store only the non-image segments when analysing (or serializing) metadata. Segments are keyed via their segment marker (a byte). Where multiple segments use the same segment marker, they will all be stored and available.

See Also:
Serialized Form

Field Summary
private  HashMap _segmentDataMap
          A map of byte[], keyed by the segment marker
(package private) static long serialVersionUID
           
 
Constructor Summary
JpegSegmentData()
          Creates a new JpegSegmentData collection object.
 
Method Summary
 void addSegment(byte segmentMarker, byte[] segmentBytes)
          Adds segment bytes to the collection.
 boolean containsSegment(byte segmentMarker)
          Determines whether data is present for a given segment marker.
static JpegSegmentData FromFile(File file)
          Deserialises the contents of a JpegSegmentData from a file.
private  List getOrCreateSegmentList(byte segmentMarker)
           
 byte[] getSegment(byte segmentMarker)
          Gets the first Jpeg segment data for the specified marker.
 byte[] getSegment(byte segmentMarker, int occurrence)
          Gets segment data for a specific occurrence and marker.
 int getSegmentCount(byte segmentMarker)
          Returns the count of segment data byte arrays stored for a given segment marker.
private  List getSegmentList(byte segmentMarker)
           
 void removeSegment(byte segmentMarker)
          Removes all segments from the collection having the specified marker.
 void removeSegmentOccurrence(byte segmentMarker, int occurrence)
          Removes a specified instance of a segment's data from the collection.
static void ToFile(File file, JpegSegmentData segmentData)
          Serialises the contents of a JpegSegmentData to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

_segmentDataMap

private final HashMap _segmentDataMap
A map of byte[], keyed by the segment marker

Constructor Detail

JpegSegmentData

public JpegSegmentData()
Creates a new JpegSegmentData collection object.

Method Detail

addSegment

public void addSegment(byte segmentMarker,
                       byte[] segmentBytes)
Adds segment bytes to the collection.

Parameters:
segmentMarker -
segmentBytes -

getSegment

public byte[] getSegment(byte segmentMarker)
Gets the first Jpeg segment data for the specified marker.

Parameters:
segmentMarker - the byte identifier for the desired segment
Returns:
a byte[] containing segment data or null if no data exists for that segment

getSegment

public byte[] getSegment(byte segmentMarker,
                         int occurrence)
Gets segment data for a specific occurrence and marker. Use this method when more than one occurrence of segment data for a given marker exists.

Parameters:
segmentMarker - identifies the required segment
occurrence - the zero-based index of the occurrence
Returns:
the segment data as a byte[], or null if no segment exists for the marker & occurrence

getSegmentCount

public int getSegmentCount(byte segmentMarker)
Returns the count of segment data byte arrays stored for a given segment marker.

Parameters:
segmentMarker - identifies the required segment
Returns:
the segment count (zero if no segments exist).

removeSegmentOccurrence

public void removeSegmentOccurrence(byte segmentMarker,
                                    int occurrence)
Removes a specified instance of a segment's data from the collection. Use this method when more than one occurrence of segment data for a given marker exists.

Parameters:
segmentMarker - identifies the required segment
occurrence - the zero-based index of the segment occurrence to remove.

removeSegment

public void removeSegment(byte segmentMarker)
Removes all segments from the collection having the specified marker.

Parameters:
segmentMarker - identifies the required segment

containsSegment

public boolean containsSegment(byte segmentMarker)
Determines whether data is present for a given segment marker.

Parameters:
segmentMarker - identifies the required segment
Returns:
true if data exists, otherwise false

ToFile

public static void ToFile(File file,
                          JpegSegmentData segmentData)
                   throws IOException
Serialises the contents of a JpegSegmentData to a file.

Parameters:
file - to file to write from
segmentData - the data to write
Throws:
IOException - if problems occur while writing

FromFile

public static JpegSegmentData FromFile(File file)
                                throws IOException,
                                       ClassNotFoundException
Deserialises the contents of a JpegSegmentData from a file.

Parameters:
file - the file to read from
Returns:
the JpegSegmentData as read
Throws:
IOException - if problems occur while reading
ClassNotFoundException - if problems occur while deserialising

getSegmentList

private List getSegmentList(byte segmentMarker)

getOrCreateSegmentList

private List getOrCreateSegmentList(byte segmentMarker)