-
- All Implemented Interfaces:
-
java.io.Closeable,java.lang.AutoCloseable
@Immutable() public class EncodedImage implements Closeable
Class that contains all the information for an encoded image, both the image bytes (held on a byte buffer or a supplier of input streams) and the extracted meta data that is useful for image transforms.
Only one of the input stream supplier or the byte buffer can be set. If using an input stream supplier, the methods that return a byte buffer will simply return null. However, getInputStream will always be supported, either from the supplier or an input stream created from the byte buffer held.
Currently the data is useful for rotation and resize.
-
-
Field Summary
Fields Modifier and Type Field Description public final static intUNKNOWN_ROTATION_ANGLEpublic final static intUNKNOWN_WIDTHpublic final static intUNKNOWN_HEIGHTpublic final static intUNKNOWN_STREAM_SIZEpublic final static intDEFAULT_SAMPLE_SIZE
-
Constructor Summary
Constructors Constructor Description EncodedImage(CloseableReference<PooledByteBuffer> pooledByteBufferRef)EncodedImage(Supplier<FileInputStream> inputStreamSupplier)EncodedImage(Supplier<FileInputStream> inputStreamSupplier, int streamSize)
-
Method Summary
Modifier and Type Method Description static EncodedImagecloneOrNull(@Nullable() EncodedImage encodedImage)Returns the cloned encoded image if the parameter received is not null, null otherwise. EncodedImagecloneOrNull()voidclose()Closes the buffer enclosed by this class. synchronized booleanisValid()Returns true if the internal buffer reference is valid or the InputStream Supplier is not null,false otherwise. CloseableReference<PooledByteBuffer>getByteBufferRef()Returns a cloned reference to the stored encoded bytes. InputStreamgetInputStream()Returns an InputStream from the internal InputStream Supplier if it's not null. InputStreamgetInputStreamOrThrow()voidsetImageFormat(ImageFormat imageFormat)Sets the image format voidsetHeight(int height)Sets the image height voidsetWidth(int width)Sets the image width voidsetRotationAngle(int rotationAngle)Sets the image rotation angle voidsetExifOrientation(int exifOrientation)Sets the exif orientation voidsetSampleSize(int sampleSize)Sets the image sample size voidsetStreamSize(int streamSize)Sets the size of an image if backed by an InputStreamIgnored if backed by a ByteBuffer voidsetBytesRange(@Nullable() BytesRange bytesRange)voidsetSource(@Nullable() String source)StringgetSource()ImageFormatgetImageFormat()Returns the image format if known, otherwise ImageFormat.UNKNOWN. intgetRotationAngle()intgetExifOrientation()Returns the exif orientation if known (1 - 8), else 0. intgetWidth()Returns the image width if known, else -1. intgetHeight()Returns the image height if known, else -1. ColorSpacegetColorSpace()The color space is always null if Android API level < 26. intgetSampleSize()Only valid if the image format is JPEG. BytesRangegetBytesRange()booleanisCompleteAt(int length)Returns true if the image is a JPEG or DNG and its data is already complete at the specifiedlength, false otherwise. intgetSize()Returns the size of the backing structure. StringgetFirstBytesAsHexString(int length)Returns first n bytes of encoded image as hexbytes voidparseMetaData()voidcopyMetaDataFrom(EncodedImage encodedImage)Copy the meta data from another EncodedImage. static booleanisMetaDataAvailable(EncodedImage encodedImage)Returns true if all the image information has loaded, false otherwise. static voidcloseSafely(@Nullable() EncodedImage encodedImage)Closes the encoded image handling null. static booleanisValid(@Nullable() EncodedImage encodedImage)Checks if the encoded image is valid i.e. synchronized SharedReference<PooledByteBuffer>getUnderlyingReferenceTestOnly()A test-only method to get the underlying references. static voidsetUseCachedMetadata(boolean useCachedMetadata)-
-
Constructor Detail
-
EncodedImage
EncodedImage(CloseableReference<PooledByteBuffer> pooledByteBufferRef)
-
EncodedImage
EncodedImage(Supplier<FileInputStream> inputStreamSupplier)
-
EncodedImage
EncodedImage(Supplier<FileInputStream> inputStreamSupplier, int streamSize)
-
-
Method Detail
-
cloneOrNull
@Nullable() static EncodedImage cloneOrNull(@Nullable() EncodedImage encodedImage)
Returns the cloned encoded image if the parameter received is not null, null otherwise.
- Parameters:
encodedImage- the EncodedImage to clone
-
cloneOrNull
@Nullable() EncodedImage cloneOrNull()
-
close
void close()
Closes the buffer enclosed by this class.
-
isValid
synchronized boolean isValid()
Returns true if the internal buffer reference is valid or the InputStream Supplier is not null,false otherwise.
-
getByteBufferRef
CloseableReference<PooledByteBuffer> getByteBufferRef()
Returns a cloned reference to the stored encoded bytes.
The caller has to close the reference once it has finished using it.
-
getInputStream
@Nullable() InputStream getInputStream()
Returns an InputStream from the internal InputStream Supplier if it's not null. Otherwisereturns an InputStream for the internal buffer reference if valid and null otherwise.
The caller has to close the InputStream after using it.
-
getInputStreamOrThrow
InputStream getInputStreamOrThrow()
-
setImageFormat
void setImageFormat(ImageFormat imageFormat)
Sets the image format
-
setHeight
void setHeight(int height)
Sets the image height
-
setWidth
void setWidth(int width)
Sets the image width
-
setRotationAngle
void setRotationAngle(int rotationAngle)
Sets the image rotation angle
-
setExifOrientation
void setExifOrientation(int exifOrientation)
Sets the exif orientation
-
setSampleSize
void setSampleSize(int sampleSize)
Sets the image sample size
-
setStreamSize
void setStreamSize(int streamSize)
Sets the size of an image if backed by an InputStream
Ignored if backed by a ByteBuffer
-
setBytesRange
void setBytesRange(@Nullable() BytesRange bytesRange)
-
getImageFormat
ImageFormat getImageFormat()
Returns the image format if known, otherwise ImageFormat.UNKNOWN.
-
getRotationAngle
int getRotationAngle()
-
getExifOrientation
int getExifOrientation()
Returns the exif orientation if known (1 - 8), else 0.
-
getWidth
int getWidth()
Returns the image width if known, else -1.
-
getHeight
int getHeight()
Returns the image height if known, else -1.
-
getColorSpace
@Nullable() ColorSpace getColorSpace()
The color space is always null if Android API level < 26.
-
getSampleSize
int getSampleSize()
Only valid if the image format is JPEG.
-
getBytesRange
@Nullable() BytesRange getBytesRange()
-
isCompleteAt
boolean isCompleteAt(int length)
Returns true if the image is a JPEG or DNG and its data is already complete at the specifiedlength, false otherwise.
-
getSize
int getSize()
Returns the size of the backing structure.
If it's a PooledByteBuffer returns its size if its not null, -1 otherwise. If it's anInputStream, return the size if it was set, -1 otherwise.
-
getFirstBytesAsHexString
String getFirstBytesAsHexString(int length)
Returns first n bytes of encoded image as hexbytes
- Parameters:
length- the number of bytes to return
-
parseMetaData
void parseMetaData()
-
copyMetaDataFrom
void copyMetaDataFrom(EncodedImage encodedImage)
Copy the meta data from another EncodedImage.
- Parameters:
encodedImage- the EncodedImage to copy the meta data from.
-
isMetaDataAvailable
static boolean isMetaDataAvailable(EncodedImage encodedImage)
Returns true if all the image information has loaded, false otherwise.
-
closeSafely
static void closeSafely(@Nullable() EncodedImage encodedImage)
Closes the encoded image handling null.
- Parameters:
encodedImage- the encoded image to close.
-
isValid
static boolean isValid(@Nullable() EncodedImage encodedImage)
Checks if the encoded image is valid i.e. is not null, and is not closed.
-
getUnderlyingReferenceTestOnly
@Nullable() synchronized SharedReference<PooledByteBuffer> getUnderlyingReferenceTestOnly()
A test-only method to get the underlying references.
DO NOT USE in application code.
-
setUseCachedMetadata
static void setUseCachedMetadata(boolean useCachedMetadata)
-
-
-
-