public class BytesHandle extends BaseHandle<byte[],byte[]> implements BufferableHandle, ContentHandle<byte[]>, BinaryReadHandle, BinaryWriteHandle, GenericReadHandle, GenericWriteHandle, JSONReadHandle, JSONWriteHandle, TextReadHandle, TextWriteHandle, XMLReadHandle, XMLWriteHandle, StructureReadHandle, StructureWriteHandle, QuadsWriteHandle, TriplesReadHandle, TriplesWriteHandle
A Bytes Handle represents document content as a byte array for reading or writing.
When writing JSON, text, or XML content, you should use a byte[] array only if the bytes are encoded in UTF-8. If the characters have a different encoding, use a StringHandle and specify the correct character encoding for the bytes when creating the String.
UNKNOWN_LENGTH| Constructor and Description |
|---|
BytesHandle()
Zero-argument constructor.
|
BytesHandle(byte[] content)
Initializes the handle with a byte array for the content.
|
| Modifier and Type | Method and Description |
|---|---|
void |
fromBuffer(byte[] buffer)
Sets the content of the handle by copying from a byte array buffer encoded in UTF-8.
|
byte[] |
get()
Returns the byte array for the handle content.
|
static ContentHandleFactory |
newFactory()
Creates a factory to create a BytesHandle instance for a byte[] array.
|
void |
set(byte[] content)
Assigns a byte array as the content.
|
byte[] |
toBuffer()
Copies the content of the handle to a byte array buffer encoded in UTF-8.
|
String |
toString()
Returns a byte array as a string with the assumption that the bytes are encoded in UTF-8.
|
BytesHandle |
with(byte[] content)
Assigns a byte array as the content and returns the handle as a fluent convenience.
|
BytesHandle |
withFormat(Format format)
Specifies the format of the content and returns the handle as a fluent convenience.
|
BytesHandle |
withMimetype(String mimetype)
Specifies the mime type of the content and returns the handle as a fluent convenience.
|
getByteLength, getFormat, getMimetype, getServerTimestamp, setByteLength, setFormat, setMimetype, setServerTimestamppublic BytesHandle()
Zero-argument constructor.
public BytesHandle(byte[] content)
Initializes the handle with a byte array for the content.
content - the byte arraypublic static ContentHandleFactory newFactory()
Creates a factory to create a BytesHandle instance for a byte[] array.
public byte[] get()
Returns the byte array for the handle content.
get in interface ContentHandle<byte[]>public void set(byte[] content)
Assigns a byte array as the content.
set in interface ContentHandle<byte[]>content - the byte arraypublic BytesHandle with(byte[] content)
Assigns a byte array as the content and returns the handle as a fluent convenience.
content - the byte arraypublic BytesHandle withFormat(Format format)
Specifies the format of the content and returns the handle as a fluent convenience.
format - the format of the contentpublic BytesHandle withMimetype(String mimetype)
Specifies the mime type of the content and returns the handle as a fluent convenience.
mimetype - the mime type of the contentpublic void fromBuffer(byte[] buffer)
BufferableHandleSets the content of the handle by copying from a byte array buffer encoded in UTF-8.
fromBuffer in interface BufferableHandlebuffer - the byte arraypublic byte[] toBuffer()
BufferableHandleCopies the content of the handle to a byte array buffer encoded in UTF-8.
toBuffer in interface BufferableHandleCopyright © 2013-2017 MarkLogic Corporation.