Class 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 Detail

      • _segmentDataMap

        private final java.util.HashMap<java.lang.Byte,​java.util.List<byte[]>> _segmentDataMap
    • Constructor Detail

      • JpegSegmentData

        public JpegSegmentData()
    • Method Detail

      • addSegment

        public void addSegment​(byte segmentType,
                               byte[] segmentBytes)
        Adds segment bytes to the collection.
        Parameters:
        segmentType - the type of the segment being added
        segmentBytes - the byte array holding data for the segment being added
      • 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 segment
        occurrence - 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 segment
        occurrence - 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 segment
        occurrence - 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 segment
        occurrence - 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