Blob
Represents a binary large object.
Conceptually you can consider it as a set of bytes (a picture, a video etc), though in fact it wraps three pieces of information:
-
the set of bytes
-
a name
-
a mime type
API
class Blob {
Blob(final String name, final String primaryType, final String subtype, final byte[] bytes)
Blob(final String name, final String mimeTypeBase, final byte[] bytes)
Blob(final String name, final MimeType mimeType, final byte[] bytes)
Blob of(final String name, final CommonMimeType mimeType, final byte[] content) (1)
String getName()
MimeType getMimeType()
byte[] getBytes()
Clob toClob(final Charset charset)
void writeBytesTo(final OutputStream os) (2)
void consume(final Consumer<InputStream> consumer) (3)
R digest(final Function<InputStream, R> digester) (4)
Blob zip()
Blob unZip(final CommonMimeType resultingMimeType)
boolean equals(final Object o)
int hashCode()
String toString()
Optional<BufferedImage> asImage() (5)
}
1 | [of__String_CommonMimeType_byte][of(String, CommonMimeType, byte[])]
Returns a new Blob of given name , mimeType and content . |
2 | writeBytesTo(OutputStream)
Does not close the OutputStream. |
3 | consume(Consumer)
The InputStream involved is closed after consumption. |
4 | digest(Function)
The InputStream involved is closed after digestion. |
5 | asImage() |
Members
of(String, CommonMimeType, byte[])
Returns a new Blob of given name , mimeType and content .
name may or may not include the desired filename extension, it is guaranteed, that the resulting Blob has the appropriate extension as constraint by the given mimeType .
For more fine-grained control use one of the Blob constructors directly.
Usage Notes
If using JDO/DataNucleus, Blob
properties can be mapped using:
@javax.jdo.annotations.Persistent(defaultFetchGroup="false")
@javax.jdo.annotations.Persistent(defaultFetchGroup="false", columns = {
@javax.jdo.annotations.Column(name = "attachment_name"),
@javax.jdo.annotations.Column(name = "attachment_mimetype"),
@javax.jdo.annotations.Column(name = "attachment_bytes", jdbcType = "BLOB", sqlType = "BLOB")
})
@Property(optionality = Optionality.OPTIONAL)
@Getter @Setter
private Blob attachment;
If the property is mandatory, add allowsNull = "false
for each of the @Column
s.