Class ProfilePicture

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public final class ProfilePicture
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable
    Class for profile picture.
    Author:
    Christopher Mindus
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      ConstructorDescription
      ProfilePicture​(java.io.File file)
      Constructs the profile picture from a file, assuming it is the "DETAIL_UploadedProfileImage" file.
      ProfilePicture​(java.io.File file, java.lang.String type)
      Constructs the profile picture from a file, assuming it is the "DETAIL_UploadedProfileImage" file.
      ProfilePicture​(java.lang.String type, java.lang.String name, byte[] data)
      Constructor of the file when only data and type and filename is present.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      ProfilePictureclone()
      Clones the instance.
      booleandeleteTemporaries()
      Cleans up any temporary files or directories created.
      booleanequals​(java.lang.Object o)
      Checks if equal with another.
      protected voidfinalize()
      Finalized: delete temporaries.
      java.io.FilegetFile()
      Gets the file for the profile image.
      java.io.FilegetFile​(java.io.File dir, boolean isTemporary)
      Gets the file for the profile image.
      intgetImageDataSize()
      Gets the size of the image byte data.
      java.lang.StringgetImageExtension()
      Gets the image extension without ".".
      java.io.ByteArrayInputStreamgetImageInputStream()
      Gets the image array as an input stream.
      java.lang.StringgetName()
      Returns the (file) name of the profile picture.
      java.lang.StringgetType()
      Gets the profile image details type string.
      inthashCode()
      Hash code of the instance.
      java.lang.StringtoString()
      A string representation.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • clone

        public ProfilePicture clone()
        Clones the instance.
        Overrides:
        clone in class java.lang.Object
        Returns:
        A cloned instance where temporary files are not cloned in, i.e. it's a fresh copy without temporary directory and/or file.
      • getName

        public java.lang.String getName()
        Returns the (file) name of the profile picture.
        Returns:
        The (file) name, without path.
      • getImageInputStream

        public java.io.ByteArrayInputStream getImageInputStream()
        Gets the image array as an input stream.
        Returns:
        Image input stream.
      • getImageDataSize

        public int getImageDataSize()
        Gets the size of the image byte data.
        Returns:
        The byte count of the image data, i.e. the file size on disk in bytes.
      • getImageExtension

        public java.lang.String getImageExtension()
        Gets the image extension without ".".
        Returns:
        The image extension, "png" or "jpg".
      • deleteTemporaries

        public boolean deleteTemporaries()
        Cleans up any temporary files or directories created. If this method is called and there are temporary file(s), nothing will be performed.

        Errors during deleting of files is logged.

        Returns:
        true if temporary file(s) where deleted.
      • getFile

        public java.io.File getFile​(java.io.File dir,
                                    boolean isTemporary)
                             throws java.io.IOException
        Gets the file for the profile image.

        If this method is called with previous temporary files and/or directories, those are deleted prior to returning, depending on the isTemporary flag.

        Parameters:
        dir - Directory where to place the temporary file. If the dir parameter is null then a temporary directory will be created and the profile picture file placed inside. The creation of the temporary file and/or directory is only done once.
        isTemporary - If the file that is created should be considered as temporary or not. If not temporary, the created file (if created) will not be deleted.
        Returns:
        file The file, a potentially temporary file when created depending on the isTemporary parameter.

        Use the method deleteTemporaries() to clean-up.

        Throws:
        java.io.IOException - For I/O errors.
      • getFile

        public java.io.File getFile()
                             throws java.io.IOException
        Gets the file for the profile image.

        If this method is called with previous temporary files and/or directories, those are deleted prior to returning.

        Returns:
        file A temporary file created.

        Use the method deleteTemporaries() to clean-up.

        Throws:
        java.io.IOException - For I/O errors.
      • toString

        public java.lang.String toString()
        A string representation.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String as "className[fileName,type]".
      • equals

        public boolean equals​(java.lang.Object o)
        Checks if equal with another.
        Overrides:
        equals in class java.lang.Object
        Returns:
        true if name, type matched and contents are the same, false otherwise.
      • hashCode

        public int hashCode()
        Hash code of the instance.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        Hash code of name, type and data.
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Finalized: delete temporaries.
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable