Class Binary
java.lang.Object
ch.tocco.nice2.persist.core.api.entity.Binary
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
BinaryEntityServiceValuePostProcessorTypeAdapter.ConvertibleBinary,BinaryQueryParameter,FileBackedBinary
Representation of a chunk of binary data.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionBinary(long size, com.google.common.hash.HashCode hash, Binary.Store store, @Nullable String mimeType, @Nullable String fileExtension, BinaryHashingService.ToStringGenerator toStringGenerator) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Release any resources associated with this binary.booleanTwo binaries are equals if their contents are equal.protected voidfinalize()@Nullable StringReturns the file extension when available.@Nullable Binary.BinaryUrlcom.google.common.hash.HashCodehash()Get the hash code of the data.inthashCode()Return aninthash code for the data.booleanOpen an input stream to read the data.longsize()Return the size of this binary in bytes.toString()
-
Constructor Details
-
Binary
public Binary(long size, com.google.common.hash.HashCode hash, Binary.Store store, @Nullable @Nullable String mimeType, @Nullable @Nullable String fileExtension, BinaryHashingService.ToStringGenerator toStringGenerator) -
Binary
-
-
Method Details
-
openStream
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
-
equals
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. -
hashCode
public int hashCode()Return aninthash code for the data. This should be theinthash code of the full hash code returned byhash(). -
size
public long size()Return the size of this binary in bytes.- Returns:
- The size of the binary in bytes or a value
< 0if the size is unknown.
-
getMimeType
-
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:
closein interfaceAutoCloseable
-
finalize
-
toString
-
getBase64DataUri
- Returns:
- a
Stringcontaining thebase64encoded binary as it might be used assrcanimgtag. - Throws:
IOException
-
getUrl
-
mayBeStored
public boolean mayBeStored()- Returns:
- if false, this binary can only be used as query parameter and does not contain any data
-