Class InputStreamImageSource.ExifCaptureInputStream
- java.lang.Object
-
- java.io.InputStream
-
- net.coobird.thumbnailator.tasks.io.InputStreamImageSource.ExifCaptureInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Enclosing class:
- InputStreamImageSource
private static final class InputStreamImageSource.ExifCaptureInputStream extends java.io.InputStreamAnInputStreamwhich intercepts the data stream to find Exif data and captures it if present.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]bufferBuffer to collect the input data to read JPEG images for JFIF marker segments.private booleandoCaptureApp1A flag to indicate that we expect APP1 payload (which contains Exif contents) is being streamed, so they should be captured into thebuffer.private booleandoInterceptFlag to indicate data stream should be intercepted and collected.private intendApp1Marker for the end of the APP1 marker segment.private booleanhasCapturedExifA flag to indicate that thebuffercontains the complete Exif information.private static intINTERCEPT_THRESHOLDA threshold on how much data to be intercepted.private java.io.InputStreamisOriginalInputStreamwhich reads from the image source.private booleanisDebugA flag to indicate whether to output debug logs.(package private) intpositionCurrent position for reading the buffer.(package private) intremainingSkipNumber of remaining bytes to skip ahead in the buffer.private intstartApp1Marker for the beginning of the APP1 marker segment.(package private) inttotalReadTotal bytes intercepted from the data stream.
-
Constructor Summary
Constructors Modifier Constructor Description privateExifCaptureInputStream(java.io.InputStream is)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voiddebugln(java.lang.String format, byte[] array)Debug message, optimized to reduce calls on Arrays.toString.private voiddebugln(java.lang.String format, java.lang.Object... args)Debug message.private byte[]getExifData()Returns Exif data captured from the JPEG image.private static intgetPayloadLength(byte a, byte b)Returns the payload length from the marker header.intread()intread(byte[] b, int off, int len)private voidterminateIntercept()Terminate intercept.
-
-
-
Field Detail
-
is
private final java.io.InputStream is
OriginalInputStreamwhich 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 thebuffer.
-
hasCapturedExif
private boolean hasCapturedExif
A flag to indicate that thebuffercontains the complete Exif information.
-
isDebug
private final boolean isDebug
A flag to indicate whether to output debug logs.
-
-
Method Detail
-
getExifData
private byte[] getExifData()
Returns Exif data captured from the JPEG image.- Returns:
- Returns captured Exif data, or
nullif 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:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.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.
-
-