Class CachedImage


  • public class CachedImage
    extends java.lang.Object
    The cached image class contains a loaded image in memory and can be used to perform various operations on it.
    Author:
    Christopher Mindus
    • Constructor Summary

      Constructors 
      ConstructorDescription
      CachedImage​(java.io.File file, boolean keepFileData)
      Loads an image from a File.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      java.awt.image.BufferedImagegetBufferedImage()
      Gets the buffered image.
      byte[]getData()
      Gets a copy of the original (file) data.
      java.lang.StringgetFileExtension()
      Gets the file extension.
      java.lang.StringgetFileName()
      Gets the original file name.
      • Methods inherited from class java.lang.Object

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

      • CachedImage

        public CachedImage​(java.io.File file,
                           boolean keepFileData)
                    throws java.io.IOException
        Loads an image from a File.

        An error is logged in the server in case of an exception not being a direct {@link IOException}.

        Parameters:
        file - The file.
        keepFileData - Flag to keep the original file data (please note that this requires more memory).
        Throws:
        java.io.FileNotFoundException - If the file is not found.
        java.io.IOException - For I/O errors (could also wrap e.g. OutOfMemoryError or other exceptions).
    • Method Detail

      • getBufferedImage

        public java.awt.image.BufferedImage getBufferedImage()
        Gets the buffered image.
        Returns:
        The buffered image.
      • getFileName

        public java.lang.String getFileName()
        Gets the original file name.
        Returns:
        The original file name can be a canonical file name as well as a "fake" file name where only the file extension should be checked.
      • getFileExtension

        public java.lang.String getFileExtension()
        Gets the file extension.
        Returns:
        The file extension without the "dot", null if none is found.
      • getData

        public byte[] getData()
        Gets a copy of the original (file) data.
        Returns:
        The byte array, or null in case of an OutOfMemoryException or that the file data is not kept in this instance. An error is logged in the server in case of a problem.