Class InputStreamImageSource.ExifCaptureInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Enclosing class:
    InputStreamImageSource

    private static final class InputStreamImageSource.ExifCaptureInputStream
    extends java.io.InputStream
    An InputStream which intercepts the data stream to find Exif data and captures it if present.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] buffer
      Buffer to collect the input data to read JPEG images for JFIF marker segments.
      private boolean doCaptureApp1
      A flag to indicate that we expect APP1 payload (which contains Exif contents) is being streamed, so they should be captured into the buffer.
      private boolean doIntercept
      Flag to indicate data stream should be intercepted and collected.
      private int endApp1
      Marker for the end of the APP1 marker segment.
      private boolean hasCapturedExif
      A flag to indicate that the buffer contains the complete Exif information.
      private static int INTERCEPT_THRESHOLD
      A threshold on how much data to be intercepted.
      private java.io.InputStream is
      Original InputStream which reads from the image source.
      private boolean isDebug
      A flag to indicate whether to output debug logs.
      (package private) int position
      Current position for reading the buffer.
      (package private) int remainingSkip
      Number of remaining bytes to skip ahead in the buffer.
      private int startApp1
      Marker for the beginning of the APP1 marker segment.
      (package private) int totalRead
      Total bytes intercepted from the data stream.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ExifCaptureInputStream​(java.io.InputStream is)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void debugln​(java.lang.String format, byte[] array)
      Debug message, optimized to reduce calls on Arrays.toString.
      private void debugln​(java.lang.String format, java.lang.Object... args)
      Debug message.
      private byte[] getExifData()
      Returns Exif data captured from the JPEG image.
      private static int getPayloadLength​(byte a, byte b)
      Returns the payload length from the marker header.
      int read()  
      int read​(byte[] b, int off, int len)  
      private void terminateIntercept()
      Terminate intercept.
      • Methods inherited from class java.io.InputStream

        available, close, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • is

        private final java.io.InputStream is
        Original InputStream which reads from the image source.
      • doIntercept

        private boolean doIntercept
        Flag to indicate data stream should be intercepted and collected.
      • INTERCEPT_THRESHOLD

        private static final int INTERCEPT_THRESHOLD
        A threshold on how much data to be intercepted. This is a safety mechanism to prevent buffering too much information.
        See Also:
        Constant Field Values
      • buffer

        private byte[] buffer
        Buffer to collect the input data to read JPEG images for JFIF marker segments. This will also be used to store the Exif data, if found.
      • position

        int position
        Current position for reading the buffer.
      • totalRead

        int totalRead
        Total bytes intercepted from the data stream.
      • remainingSkip

        int remainingSkip
        Number of remaining bytes to skip ahead in the buffer. This value is positive when next location to skip to is outside the buffer's current contents.
      • startApp1

        private int startApp1
        Marker for the beginning of the APP1 marker segment. Its position is where the APP1 marker starts, not the payload.
      • endApp1

        private int endApp1
        Marker for the end of the APP1 marker segment.
      • doCaptureApp1

        private boolean doCaptureApp1
        A flag to indicate that we expect APP1 payload (which contains Exif contents) is being streamed, so they should be captured into the buffer.
      • hasCapturedExif

        private boolean hasCapturedExif
        A flag to indicate that the buffer contains the complete Exif information.
      • isDebug

        private final boolean isDebug
        A flag to indicate whether to output debug logs.
    • Constructor Detail

      • ExifCaptureInputStream

        private ExifCaptureInputStream​(java.io.InputStream is)
    • Method Detail

      • getExifData

        private byte[] getExifData()
        Returns Exif data captured from the JPEG image.
        Returns:
        Returns captured Exif data, or null if unavailable.
      • terminateIntercept

        private void terminateIntercept()
        Terminate intercept. Drops the collected buffer to relieve pressure on memory. Do not call this when Exif was found, as buffer (containing Exif) will be lost.
      • debugln

        private void debugln​(java.lang.String format,
                             java.lang.Object... args)
        Debug message.
      • debugln

        private void debugln​(java.lang.String format,
                             byte[] array)
        Debug message, optimized to reduce calls on Arrays.toString.
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • getPayloadLength

        private static int getPayloadLength​(byte a,
                                            byte b)
        Returns the payload length from the marker header.
        Parameters:
        a - First byte of payload length.
        b - Second byte of payload length.
        Returns:
        Length as an integer.