public class InputStreamHandle extends BaseHandle<InputStream,InputStream> implements BufferableHandle, ContentHandle<InputStream>, BinaryReadHandle, BinaryWriteHandle, GenericReadHandle, GenericWriteHandle, JSONReadHandle, JSONWriteHandle, TextReadHandle, TextWriteHandle, XMLReadHandle, XMLWriteHandle, StructureReadHandle, StructureWriteHandle, TriplesReadHandle, TriplesWriteHandle, QuadsWriteHandle, SPARQLResultsReadHandle, Closeable
An InputStreamHandle represents a resource as an InputStream for reading or writing.
When writing JSON, text, or XML content, you should use an InputStream only
if the stream is encoded in UTF-8. If the characters have a different encoding, use
a ReaderHandle and specify the correct character encoding for the stream when
creating the Reader.
Either call close() or get().close() when finished with this handle
to release the resources.
UNKNOWN_LENGTH| Constructor and Description |
|---|
InputStreamHandle()
Zero-argument constructor.
|
InputStreamHandle(InputStream content)
Initializes the handle with an input stream for the content.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Either call close() or get().close() when finished with this handle to close the underlying InputStream.
|
void |
fromBuffer(byte[] buffer)
Sets the content of the handle by copying from a byte array buffer encoded in UTF-8.
|
InputStream |
get()
Returns an input stream for a resource read from the database.
|
static ContentHandleFactory |
newFactory()
Creates a factory to create an InputStreamHandle instance for an input stream.
|
void |
set(InputStream content)
Assigns an input stream as the content.
|
byte[] |
toBuffer()
Copies the content of the handle to a byte array buffer encoded in UTF-8.
|
String |
toString()
Buffers the input stream and returns the buffer as a string with the assumption that the stream is encoded in UTF-8.
|
InputStreamHandle |
with(InputStream content)
Assigns an input stream as the content and returns the handle as a fluent convenience.
|
InputStreamHandle |
withFormat(Format format)
Specifies the format of the content and returns the handle as a fluent convenience.
|
InputStreamHandle |
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 InputStreamHandle()
Zero-argument constructor.
public InputStreamHandle(InputStream content)
Initializes the handle with an input stream for the content.
content - an input streampublic static ContentHandleFactory newFactory()
Creates a factory to create an InputStreamHandle instance for an input stream.
public InputStream get()
Returns an input stream for a resource read from the database.
When finished with the input stream, close the input stream to release the response.
get in interface ContentHandle<InputStream>public void set(InputStream content)
Assigns an input stream as the content.
set in interface ContentHandle<InputStream>content - an input streampublic InputStreamHandle with(InputStream content)
Assigns an input stream as the content and returns the handle as a fluent convenience.
content - an input streampublic InputStreamHandle withFormat(Format format)
Specifies the format of the content and returns the handle as a fluent convenience.
format - the format of the contentpublic InputStreamHandle 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 BufferableHandlepublic String toString()
Buffers the input stream and returns the buffer as a string with the assumption that the stream is encoded in UTF-8. If the stream has a different encoding, use InputStreamReader instead of calling this method.
public void close()
Either call close() or get().close() when finished with this handle to close the underlying InputStream.
close in interface Closeableclose in interface AutoCloseableCopyright © 2013-2017 MarkLogic Corporation.