public class SourceHandle extends BaseHandle<InputStream,OutputStreamSender> implements OutputStreamSender, BufferableHandle, ContentHandle<Source>, XMLReadHandle, XMLWriteHandle, StructureReadHandle, StructureWriteHandle, Closeable
A Source Handle represents XML content as a transform source for reading or transforms a source into a result for writing.
Always call close() when finished with this handle to release the resources.
UNKNOWN_LENGTH| Constructor and Description |
|---|
SourceHandle()
Zero-argument constructor.
|
SourceHandle(Source content)
Initializes the handle with a transform source for the content.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Always call close() when finished with this handle – it closes the underlying InputStream.
|
void |
fromBuffer(byte[] buffer)
Sets the content of the handle by copying from a byte array buffer encoded in UTF-8.
|
Source |
get()
Returns the transform source that produces the content.
|
Transformer |
getTransformer()
Returns a transformer for modifying the content.
|
static ContentHandleFactory |
newFactory()
Creates a factory to create a SourceHandle instance for a Transformer Source.
|
void |
set(Source content)
Assigns a transform source that produces the content.
|
void |
setFormat(Format format)
Restricts the format to XML.
|
void |
setTransformer(Transformer transformer)
Specifies a transformer for modifying the content.
|
byte[] |
toBuffer()
Copies the content of the handle to a byte array buffer encoded in UTF-8.
|
String |
toString()
Buffers the transform source and returns the buffer as a string.
|
void |
transform(Result result)
Transforms the source for the content output to the result.
|
SourceHandle |
with(Source content)
Assigns a transform source that produces the content and returns the handle as a fluent convenience.
|
SourceHandle |
withMimetype(String mimetype)
Specifies the mime type of the content and returns the handle as a fluent convenience.
|
SourceHandle |
withTransformer(Transformer transformer)
Specifies a transformer for modifying the content and returns the handle as a fluent convenience.
|
void |
write(OutputStream out)
Implements a callback to write content to the provided output stream for sending to the database server.
|
getByteLength, getFormat, getMimetype, getServerTimestamp, setByteLength, setMimetype, setServerTimestamppublic SourceHandle()
Zero-argument constructor.
public SourceHandle(Source content)
Initializes the handle with a transform source for the content.
content - a transform sourcepublic static ContentHandleFactory newFactory()
Creates a factory to create a SourceHandle instance for a Transformer Source.
public Transformer getTransformer()
Returns a transformer for modifying the content.
public void setTransformer(Transformer transformer)
Specifies a transformer for modifying the content.
transformer - the transformerpublic SourceHandle withTransformer(Transformer transformer)
Specifies a transformer for modifying the content and returns the handle as a fluent convenience.
transformer - the transformerpublic Source get()
Returns the transform source that produces the content.
get in interface ContentHandle<Source>public void set(Source content)
Assigns a transform source that produces the content.
set in interface ContentHandle<Source>content - the transform sourcepublic SourceHandle with(Source content)
Assigns a transform source that produces the content and returns the handle as a fluent convenience.
content - the transform sourcepublic void transform(Result result)
Transforms the source for the content output to the result. If the transformer is not specified, an identity transform sends the source to the result. When writing, the result is stored in the database
result - the receiver of the transform outputpublic void setFormat(Format format)
Restricts the format to XML.
setFormat in interface ContentDescriptorsetFormat in class BaseHandle<InputStream,OutputStreamSender>format - the format of the contentpublic SourceHandle 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 transform source and returns the buffer as a string.
public void write(OutputStream out) throws IOException
OutputStreamSenderImplements a callback to write content to the provided output stream for sending to the database server.
write in interface OutputStreamSenderout - the output stream receiving the contentIOException - if io problems arisepublic void close()
Always call close() when finished with this handle – it closes the underlying InputStream.
close in interface Closeableclose in interface AutoCloseableCopyright © 2013-2017 MarkLogic Corporation.