Class JpegSegmentData


  • public class 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 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.

    • 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​(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.
      int getSegmentCount​(byte segmentType)
      Returns the count of segment data byte arrays stored for a given segment type.
      int getSegmentCount​(JpegSegmentType segmentType)
      Returns the count of segment data byte arrays stored for a given segment type.
      java.lang.Iterable<byte[]> getSegments​(byte segmentType)
      Returns all instances of a given JPEG segment.
      java.lang.Iterable<byte[]> getSegments​(JpegSegmentType segmentType)
      Returns all instances of a given JPEG segment.
      java.lang.Iterable<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​(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​(JpegSegmentType segmentType, int occurrence)
      Removes a specified instance of a segment's data from the collection.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
      • getSegmentTypes

        public java.lang.Iterable<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​(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​(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​(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
      • getSegmentCount

        public int getSegmentCount​(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​(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​(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​(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