public class InputSourceHandle extends BaseHandle<InputStream,OutputStreamSender> implements OutputStreamSender, BufferableHandle, ContentHandle<InputSource>, XMLReadHandle, XMLWriteHandle, StructureReadHandle, StructureWriteHandle, Closeable
An Input Source Handle represents XML content as an input source for reading or writing. When reading, the XML may be processed by a SAX content handler.
Always call close() when finished with this handle to release the resources.
| Modifier and Type | Class and Description |
|---|---|
static class |
InputSourceHandle.DraconianErrorHandler
DraconianErrorHandler treats SAX parse errors as exceptions but ignores warnings (based on the JavaDoc for the javax.xml.validation package).
|
UNKNOWN_LENGTH| Constructor and Description |
|---|
InputSourceHandle()
Zero-argument constructor.
|
InputSourceHandle(InputSource content)
Initializes the handle with a SAX input 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.
|
InputSource |
get()
Returns the input source for the content.
|
Schema |
getDefaultWriteSchema()
Returns the default schema for validating the input source while writing to the database.
|
ErrorHandler |
getErrorHandler()
Returns the error handler for errors discovered while parsing the input source.
|
SAXParserFactory |
getFactory()
Returns the factory for parsing SAX events.
|
EntityResolver |
getResolver()
Returns the resolver for resolving references while parsing the input source.
|
static ContentHandleFactory |
newFactory()
Creates a factory to create a InputSourceHandle instance for a SAX InputSource.
|
void |
process(ContentHandler handler)
Reads the input source, sending SAX events to the supplied content handler.
|
void |
set(InputSource content)
Assigns an input source as the content.
|
void |
setDefaultWriteSchema(Schema schema)
Specifies the default schema for validating the input source.
|
void |
setErrorHandler(ErrorHandler errorHandler)
Specifies the error handler for errors discovered while parsing the input source.
|
void |
setFactory(SAXParserFactory factory)
Specifies the factory for parsing SAX events.
|
void |
setFormat(Format format)
Restricts the format to XML.
|
void |
setResolver(EntityResolver resolver)
Specifies the resolver for resolving references while parsing the input source.
|
byte[] |
toBuffer()
Copies the content of the handle to a byte array buffer encoded in UTF-8.
|
String |
toString()
Buffers the SAX input source and returns the buffer as an XML string.
|
InputSourceHandle |
with(InputSource content)
Assigns an input source as the content and returns the handle as a fluent convenience.
|
InputSourceHandle |
withMimetype(String mimetype)
Specifies the mime type of 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 InputSourceHandle()
Zero-argument constructor.
public InputSourceHandle(InputSource content)
Initializes the handle with a SAX input source for the content.
content - a SAX input sourcepublic static ContentHandleFactory newFactory()
Creates a factory to create a InputSourceHandle instance for a SAX InputSource.
public EntityResolver getResolver()
Returns the resolver for resolving references while parsing the input source.
public void setResolver(EntityResolver resolver)
Specifies the resolver for resolving references while parsing the input source.
resolver - the reference resolverpublic ErrorHandler getErrorHandler()
Returns the error handler for errors discovered while parsing the input source.
public void setErrorHandler(ErrorHandler errorHandler)
Specifies the error handler for errors discovered while parsing the input source.
errorHandler - the error handlerpublic InputSource get()
Returns the input source for the content.
get in interface ContentHandle<InputSource>public void set(InputSource content)
Assigns an input source as the content.
set in interface ContentHandle<InputSource>content - an input sourcepublic InputSourceHandle with(InputSource content)
Assigns an input source as the content and returns the handle as a fluent convenience.
content - an input sourcepublic void process(ContentHandler handler)
Reads the input source, sending SAX events to the supplied content handler.
handler - the SAX content handlerpublic void setFormat(Format format)
Restricts the format to XML.
setFormat in interface ContentDescriptorsetFormat in class BaseHandle<InputStream,OutputStreamSender>format - the format of the contentpublic InputSourceHandle 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 SAX input source and returns the buffer as an XML string.
public SAXParserFactory getFactory() throws SAXException, ParserConfigurationException
Returns the factory for parsing SAX events.
SAXException - if such an error occurs while initializing the new factoryParserConfigurationException - if such an error occurs while initializing the new factorypublic void setFactory(SAXParserFactory factory)
Specifies the factory for parsing SAX events.
factory - the SAX factorypublic Schema getDefaultWriteSchema()
Returns the default schema for validating the input source while writing to the database.
public void setDefaultWriteSchema(Schema schema)
Specifies the default schema for validating the input source. The default schema is used only while writing to the database and only when no schema has been set directly on the factory. To minimize creation of partial documents while writing an input source to the database, set the error handler on the InputSourceHandle to InputSourceHandle.DraconianErrorHandler and set the repair policy to NONE on the XMLDocumentManager. An error on the root element can still result in an empty document.
schema - the default schema for writing documentspublic 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.