Package com.drew.imaging.jpeg
Class JpegSegmentData
java.lang.Object
com.drew.imaging.jpeg.JpegSegmentData
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 metadata.
Segments are keyed via their JpegSegmentType. Where multiple segments use the
same segment type, they will all be stored and available.
Each segment type may contain multiple entries. Conceptually the model is:
Map<JpegSegmentType, Collection<byte[]>>. This class provides
convenience methods around that structure.
- Author:
- Drew Noakes https://drewnoakes.com
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSegment(byte segmentType, byte[] segmentBytes) Adds segment bytes to the collection.booleancontainsSegment(byte segmentType) Determines whether data is present for a given segment type.booleancontainsSegment(JpegSegmentType segmentType) Determines whether data is present for a given segment type.byte[]getSegment(byte segmentType) Gets the first JPEG segment data for the specified type.byte[]getSegment(byte segmentType, int occurrence) Gets segment data for a specific occurrence and type.byte[]getSegment(JpegSegmentType segmentType) Gets the first JPEG segment data for the specified type.byte[]getSegment(JpegSegmentType segmentType, int occurrence) Gets segment data for a specific occurrence and type.intgetSegmentCount(byte segmentType) Returns the count of segment data byte arrays stored for a given segment type.intgetSegmentCount(JpegSegmentType segmentType) Returns the count of segment data byte arrays stored for a given segment type.Iterable<byte[]>getSegments(byte segmentType) Returns all instances of a given JPEG segment.Iterable<byte[]>getSegments(JpegSegmentType segmentType) Returns all instances of a given JPEG segment.Gets the set of JPEG segment type identifiers.voidremoveSegment(byte segmentType) Removes all segments from the collection having the specified type.voidremoveSegment(JpegSegmentType segmentType) Removes all segments from the collection having the specified type.voidremoveSegmentOccurrence(byte segmentType, int occurrence) Removes a specified instance of a segment's data from the collection.voidremoveSegmentOccurrence(JpegSegmentType segmentType, int occurrence) Removes a specified instance of a segment's data from the collection.
-
Constructor Details
-
JpegSegmentData
public JpegSegmentData()
-
-
Method Details
-
addSegment
public void addSegment(byte segmentType, byte[] segmentBytes) Adds segment bytes to the collection.- Parameters:
segmentType- the type of the segment being addedsegmentBytes- the byte array holding data for the segment being added
-
getSegmentTypes
Gets the set of JPEG segment type identifiers. -
getSegment
public byte[] getSegment(byte segmentType) Gets the first JPEG segment data for the specified type.- Parameters:
segmentType- the JpegSegmentType for the desired segment- Returns:
- a byte[] containing segment data or null if no data exists for that segment
-
getSegment
Gets the first JPEG segment data for the specified type.- Parameters:
segmentType- the JpegSegmentType for the desired segment- Returns:
- a byte[] containing segment data or null if no data exists for that segment
-
getSegment
Gets segment data for a specific occurrence and type. Use this method when more than one occurrence of segment data for a given type exists.- Parameters:
segmentType- identifies the required segmentoccurrence- the zero-based index of the occurrence- Returns:
- the segment data as a byte[], or null if no segment exists for the type & occurrence
-
getSegment
public byte[] getSegment(byte segmentType, int occurrence) Gets segment data for a specific occurrence and type. Use this method when more than one occurrence of segment data for a given type exists.- Parameters:
segmentType- identifies the required segmentoccurrence- the zero-based index of the occurrence- Returns:
- the segment data as a byte[], or null if no segment exists for the type & occurrence
-
getSegments
Returns all instances of a given JPEG segment. If no instances exist, an empty sequence is returned.- Parameters:
segmentType- 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
-
getSegments
Returns all instances of a given JPEG segment. If no instances exist, an empty sequence is returned.- Parameters:
segmentType- 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
Returns the count of segment data byte arrays stored for a given segment type.- Parameters:
segmentType- identifies the required segment- Returns:
- the segment count (zero if no segments exist).
-
getSegmentCount
public int getSegmentCount(byte segmentType) Returns the count of segment data byte arrays stored for a given segment type.- Parameters:
segmentType- identifies the required segment- Returns:
- the segment count (zero if no segments exist).
-
removeSegmentOccurrence
Removes a specified instance of a segment's data from the collection. Use this method when more than one occurrence of segment data exists for a given type exists.- Parameters:
segmentType- identifies the required segmentoccurrence- the zero-based index of the segment occurrence to remove.
-
removeSegmentOccurrence
public void removeSegmentOccurrence(byte segmentType, 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 exists for a given type exists.- Parameters:
segmentType- identifies the required segmentoccurrence- the zero-based index of the segment occurrence to remove.
-
removeSegment
Removes all segments from the collection having the specified type.- Parameters:
segmentType- identifies the required segment
-
removeSegment
public void removeSegment(byte segmentType) Removes all segments from the collection having the specified type.- Parameters:
segmentType- identifies the required segment
-
containsSegment
Determines whether data is present for a given segment type.- Parameters:
segmentType- identifies the required segment- Returns:
- true if data exists, otherwise false
-
containsSegment
public boolean containsSegment(byte segmentType) Determines whether data is present for a given segment type.- Parameters:
segmentType- identifies the required segment- Returns:
- true if data exists, otherwise false
-