= Blob
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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

[source,java]
.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)     // <.>
  String getName()
  MimeType getMimeType()
  byte[] getBytes()
  Clob toClob(Charset charset)
  void writeBytesTo(OutputStream os)     // <.>
  void consume(Consumer<InputStream> consumer)     // <.>
  R digest(Function<InputStream, R> digester)     // <.>
  Blob zip()
  Blob unZip(CommonMimeType resultingMimeType)
  boolean equals(Object o)
  int hashCode()
  String toString()
  Optional<BufferedImage> asImage()     // <.>
}
----

<.> xref:#of_String_CommonMimeType_byte[of(String, CommonMimeType, byte)]
+
--
Returns a new xref:refguide:applib:index/value/Blob.adoc[Blob] of given _name_ , _mimeType_ and _content_ .
--
<.> xref:#writeBytesTo_OutputStream[writeBytesTo(OutputStream)]
+
--
Does not close the OutputStream.
--
<.> xref:#consume_Consumer[consume(Consumer)]
+
--
The _InputStream_ involved is closed after consumption.
--
<.> xref:#digest_Function[digest(Function)]
+
--
The _InputStream_ involved is closed after digestion.
--
<.> xref:#asImage_[asImage()]

== Members

[#of_String_CommonMimeType_byte]
=== of(String, CommonMimeType, byte)

Returns a new xref:refguide:applib:index/value/Blob.adoc[Blob] of given _name_ , _mimeType_ and _content_ .

_name_ may or may not include the desired filename extension, it is guaranteed, that the resulting xref:refguide:applib:index/value/Blob.adoc[Blob] has the appropriate extension as constraint by the given _mimeType_ .

For more fine-grained control use one of the xref:refguide:applib:index/value/Blob.adoc[Blob] constructors directly.

[#writeBytesTo_OutputStream]
=== writeBytesTo(OutputStream)

Does not close the OutputStream.

[#consume_Consumer]
=== consume(Consumer)

The _InputStream_ involved is closed after consumption.

[#digest_Function]
=== digest(Function)

The _InputStream_ involved is closed after digestion.

[#asImage_]
=== asImage()

include::hooks/Blob_usage-notes.adoc[]
