Package 

Class EncodedImage

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

    • Constructor Detail

      • EncodedImage

        EncodedImage(CloseableReference<PooledByteBuffer> pooledByteBufferRef)
      • EncodedImage

        EncodedImage(Supplier<FileInputStream> inputStreamSupplier, int streamSize)
    • Method Detail

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

      • 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

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

      • getSampleSize

         int getSampleSize()

        Only valid if the image format is JPEG.

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