Package gov.nih.mipav.model.file
Class MetadataExtractor.JpegSegmentData
- java.lang.Object
-
- gov.nih.mipav.model.file.MetadataExtractor.JpegSegmentData
-
- Enclosing class:
- MetadataExtractor
public class MetadataExtractor.JpegSegmentData extends java.lang.Object
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
MetadataExtractor.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
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap<java.lang.Byte,java.util.List<byte[]>>
_segmentDataMap
-
Constructor Summary
Constructors Constructor Description JpegSegmentData()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSegment(byte segmentType, byte[] segmentBytes)
Adds segment bytes to the collection.boolean
containsSegment(byte segmentType)
Determines whether data is present for a given segment type.boolean
containsSegment(MetadataExtractor.JpegSegmentType segmentType)
Determines whether data is present for a given segment type.private java.util.List<byte[]>
getOrCreateSegmentList(byte segmentType)
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(MetadataExtractor.JpegSegmentType segmentType)
Gets the first JPEG segment data for the specified type.byte[]
getSegment(MetadataExtractor.JpegSegmentType segmentType, int occurrence)
Gets segment data for a specific occurrence and type.int
getSegmentCount(byte segmentType)
Returns the count of segment data byte arrays stored for a given segment type.int
getSegmentCount(MetadataExtractor.JpegSegmentType segmentType)
Returns the count of segment data byte arrays stored for a given segment type.private java.util.List<byte[]>
getSegmentList(byte segmentType)
java.lang.Iterable<byte[]>
getSegments(byte segmentType)
Returns all instances of a given JPEG segment.java.lang.Iterable<byte[]>
getSegments(MetadataExtractor.JpegSegmentType segmentType)
Returns all instances of a given JPEG segment.java.lang.Iterable<MetadataExtractor.JpegSegmentType>
getSegmentTypes()
Gets the set of JPEG segment type identifiers.void
removeSegment(byte segmentType)
Removes all segments from the collection having the specified type.void
removeSegment(MetadataExtractor.JpegSegmentType segmentType)
Removes all segments from the collection having the specified type.void
removeSegmentOccurrence(byte segmentType, int occurrence)
Removes a specified instance of a segment's data from the collection.void
removeSegmentOccurrence(MetadataExtractor.JpegSegmentType segmentType, int occurrence)
Removes a specified instance of a segment's data from the collection.
-
-
-
Method Detail
-
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
public java.lang.Iterable<MetadataExtractor.JpegSegmentType> 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
public byte[] getSegment(MetadataExtractor.JpegSegmentType 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
public byte[] getSegment(MetadataExtractor.JpegSegmentType 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
-
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
public java.lang.Iterable<byte[]> getSegments(MetadataExtractor.JpegSegmentType segmentType)
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
public java.lang.Iterable<byte[]> getSegments(byte segmentType)
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
-
getSegmentList
private java.util.List<byte[]> getSegmentList(byte segmentType)
-
getOrCreateSegmentList
private java.util.List<byte[]> getOrCreateSegmentList(byte segmentType)
-
getSegmentCount
public int getSegmentCount(MetadataExtractor.JpegSegmentType 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).
-
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
public void removeSegmentOccurrence(MetadataExtractor.JpegSegmentType 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.
-
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
public void removeSegment(MetadataExtractor.JpegSegmentType segmentType)
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
public boolean containsSegment(MetadataExtractor.JpegSegmentType segmentType)
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
-
-