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

Blob.java
class Blob {
  Blob(String name, String primaryType, String subtype, byte[] bytes)
  Blob(String name, String mimeTypeBase, byte[] bytes)
  Blob(String name, MimeType mimeType, byte[] bytes)
  Blob of(String name, CommonMimeType mimeType, byte[] content)     (1)
  String getName()
  MimeType getMimeType()
  byte[] getBytes()
  void writeBytesTo(final OutputStream os)     (2)
  boolean equals(final Object o)
  int hashCode()
  String toString()
  Optional<BufferedImage> asImage()     (3)
}
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 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.

writeBytesTo(OutputStream)

Does not close the OutputStream.

asImage()

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 @Columns.