Class Blob
This class provides convenient factory methods to create blobs from:
- File paths (
from(Path)) - InputStreams (
from(InputStream)) - Strings (
from(String)) - Byte arrays (
from(byte[])) - ByteBuffers (
from(ByteBuffer)) - Lists of ByteBuffers (
from(List))
Retry compatibility: Most blob types support HTTP request retries effectively. However, InputStream-backed
blobs (from(InputStream)) do not support retries as the stream gets consumed during the first attempt.
For retry-compatible scenarios, prefer file-based (from(Path)) or in-memory
(from(byte[])) alternatives.
-
Method Summary
Modifier and TypeMethodDescriptionlongReturns the number of bytes in the blob, or -1 if unknown.static Blobfrom(byte[] data) Creates aBlobfrom a byte array.static Blobfrom(InputStream inputStream) Creates aBlobfrom anInputStream.static BlobCreates aBlobfrom a String using UTF-8 encoding.static Blobfrom(ByteBuffer buffer) Creates aBlobfrom a singleByteBuffer.static BlobCreates aBlobfrom a file path.static Blobfrom(List<ByteBuffer> buffers) Creates aBlobfrom a list ofByteBuffers.Returns this blob's content as a transport request body.
-
Method Details
-
from
Creates aBlobfrom a file path. The file is read on each use so the blob supports retries.- Parameters:
path- the path to the file to read- Returns:
- a new
Blobinstance - Throws:
FileNotFoundException- if the file does not exist or cannot be readNullPointerException- ifpathisnull
-
from
Creates aBlobfrom anInputStream. The stream is read lazily when the request body is written.Important: InputStream-backed blobs do not support retries effectively. If the HTTP request fails and is retried, the InputStream will have already been consumed during the first attempt, causing subsequent retry attempts to send empty request bodies. For retry-compatible scenarios, consider using
from(Path)for file-based data orfrom(byte[])for in-memory data.- Parameters:
inputStream- the InputStream to read from- Returns:
- a new
Blobinstance - Throws:
NullPointerException- ifinputStreamisnull
-
from
Creates aBlobfrom a String using UTF-8 encoding.- Parameters:
string- the string to convert to a Blob- Returns:
- a new
Blobinstance - Throws:
NullPointerException- ifstringisnull
-
from
Creates aBlobfrom a byte array.- Parameters:
data- the byte array to wrap as a Blob- Returns:
- a new
Blobinstance - Throws:
NullPointerException- ifdataisnull
-
from
Creates aBlobfrom a singleByteBuffer. The buffer contents are copied so the blob supports retries.- Parameters:
buffer- the ByteBuffer to wrap as a Blob- Returns:
- a new
Blobinstance - Throws:
NullPointerException- ifbufferisnull
-
from
Creates aBlobfrom a list ofByteBuffers. The buffer contents are copied so the blob supports retries.- Parameters:
buffers- the list of ByteBuffers to wrap as a Blob- Returns:
- a new
Blobinstance - Throws:
NullPointerException- ifbuffersisnull
-
toHttpBody
Returns this blob's content as a transport request body.- Returns:
- the request body carrier
-
contentLength
public long contentLength()Returns the number of bytes in the blob, or -1 if unknown.
-