Class ProfilePicture

java.lang.Object
com.iizix.license.ProfilePicture
All Implemented Interfaces:
Serializable, Cloneable

public final class ProfilePicture extends Object implements Serializable, Cloneable
Class for profile picture.
Author:
Christopher Mindus
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The most image bytes a serialized picture may declare, 16,000,000: the value of LicenseFileData.MAX_LICENSE_BYTES in com.iizix.server.license, the most bytes a licence map may occupy inflated on the License System and the maxbytes of its deserialization filter.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    Clones the instance.
    boolean
    Cleans up any temporary files or directories created.
    boolean
    Checks if equal with another.
    protected void
    Finalized: delete temporaries.
    Gets the file for the profile image.
    getFile(File dir, boolean isTemporary)
    Gets the file for the profile image.
    int
    Gets the size of the image byte data.
    Gets the image extension without ".".
    Gets the image array as an input stream.
    Returns the (file) name of the profile picture.
    Gets the profile image details type string.
    int
    Hash code of the instance.
    A string representation.

    Methods inherited from class Object

    getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • MAX_SERIALIZED_IMAGE_BYTES

      public static final int MAX_SERIALIZED_IMAGE_BYTES
      The most image bytes a serialized picture may declare, 16,000,000: the value of LicenseFileData.MAX_LICENSE_BYTES in com.iizix.server.license, the most bytes a licence map may occupy inflated on the License System and the maxbytes of its deserialization filter. A picture travels inside a licence map, so it can never be larger than the licence that carries it. This bundle cannot reference that one, so the two values are kept equal by hand (a test of com.iizix.server.license.tests compares them). A picture a user uploads is limited to 1 MB by ProfilePicture(File,String); the wire format is unchanged.
      See Also:
  • Constructor Details

  • Method Details

    • clone

      public ProfilePicture clone()
      Clones the instance.
      Overrides:
      clone in class 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.
    • getType

    • getName

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

      public 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 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 File getFile(File dir, boolean isTemporary) throws 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:
      IOException - For I/O errors.
    • getFile

      public File getFile() throws 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:
      IOException - For I/O errors.
    • toString

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

      public boolean equals(Object o)
      Checks if equal with another.
      Overrides:
      equals in class 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 Object
      Returns:
      Hash code of name, type and data.
    • finalize

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