java.lang.Object
ch.tocco.nice2.persist.core.api.entity.Binary
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
BinaryEntityServiceValuePostProcessorTypeAdapter.ConvertibleBinary, BinaryQueryParameter, FileBackedBinary

public class Binary extends Object implements AutoCloseable
Representation of a chunk of binary data.
  • Constructor Details

  • Method Details

    • openStream

      public InputStream openStream() throws IOException
      Open an input stream to read the data.
      Throws:
      IOException
    • hash

      public com.google.common.hash.HashCode hash()
      Get the hash code of the data. It's recommended to use SHA1.
      Returns:
      A hash code of the data.
    • hashAsString

      public String hashAsString()
    • equals

      public boolean equals(Object o)
      Two binaries are equals if their contents are equal. Two binaries should be considered equal if their hash code is equal. It's recommended to use SHA1.
      Overrides:
      equals in class Object
      Parameters:
      o - The other object
      Returns:
      true if both objects are Binaries with equal content.
    • hashCode

      public int hashCode()
      Return an int hash code for the data. This should be the int hash code of the full hash code returned by hash().
      Overrides:
      hashCode in class Object
      Returns:
      An int hash code.
    • size

      public long size()
      Return the size of this binary in bytes.
      Returns:
      The size of the binary in bytes or a value < 0 if the size is unknown.
    • getMimeType

      public String getMimeType()
    • getFileExtension

      @Nullable public @Nullable String getFileExtension()
      Returns the file extension when available. The file extension can be more specific than the mime-type.
    • close

      public void close()
      Release any resources associated with this binary.
      Specified by:
      close in interface AutoCloseable
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getBase64DataUri

      public String getBase64DataUri() throws IOException
      Returns:
      a String containing the base64 encoded binary as it might be used as src an img tag.
      Throws:
      IOException
    • getUrl

      @Nullable public @Nullable Binary.BinaryUrl getUrl(String contentDisposition)
    • mayBeStored

      public boolean mayBeStored()
      Returns:
      if false, this binary can only be used as query parameter and does not contain any data