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
-
Constructor Summary
ConstructorDescriptionBinary
(long size, com.google.common.hash.HashCode hash, Binary.Store store, @Nullable String mimeType, @Nullable String fileExtension, BinaryHashingService.ToStringGenerator toStringGenerator) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Release any resources associated with this binary.boolean
Two binaries are equals if their contents are equal.protected void
finalize()
@Nullable String
Returns the file extension when available.@Nullable Binary.BinaryUrl
com.google.common.hash.HashCode
hash()
Get the hash code of the data.int
hashCode()
Return anint
hash code for the data.boolean
Open an input stream to read the data.long
size()
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 anint
hash code for the data. This should be theint
hash 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
< 0
if 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:
close
in interfaceAutoCloseable
-
finalize
-
toString
-
getBase64DataUri
- Returns:
- a
String
containing thebase64
encoded binary as it might be used assrc
animg
tag. - 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
-