Metadata Extractor Logo

com.drew.imaging.jpeg
Class JpegSegmentData

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

public class JpegSegmentData
extends java.lang.Object
implements java.io.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

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(java.io.File file)
          Deserialises the contents of a JpegSegmentData from a file.
 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.
 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(java.io.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
 

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(java.io.File file,
                          JpegSegmentData segmentData)
                   throws java.io.IOException
Serialises the contents of a JpegSegmentData to a file.

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

FromFile

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

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

Metadata Extractor Logo

Copyright © 2006 Drew Noakes. All Rights Reserved.