public class InputSourceHandle extends BaseHandle<java.io.InputStream,OutputStreamSender> implements OutputStreamSender, StreamingContentHandle<org.xml.sax.InputSource,java.io.InputStream>, XMLReadHandle, XMLWriteHandle, StructureReadHandle, StructureWriteHandle, CtsQueryWriteHandle, java.io.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(org.xml.sax.InputSource content)
Initializes the handle with a SAX input source for the content.
|
Modifier and Type | Method and Description |
---|---|
org.xml.sax.InputSource |
bytesToContent(byte[] buffer)
Converts a byte serialization to the content representation.
|
void |
close()
Always call close() when finished with this handle -- it closes the underlying InputStream.
|
byte[] |
contentToBytes(org.xml.sax.InputSource content)
Converts the content representation to bytes.
|
void |
fromBuffer(byte[] buffer)
Sets the content of the handle by copying from a byte array buffer
encoded in UTF-8.
|
org.xml.sax.InputSource |
get()
Returns the input source for the content.
|
java.lang.Class<org.xml.sax.InputSource> |
getContentClass()
Returns the class of the handled content, which may be a base
class of the actual class of a content object.
|
javax.xml.validation.Schema |
getDefaultWriteSchema()
Returns the default schema for validating the input source
while writing to the database.
|
org.xml.sax.ErrorHandler |
getErrorHandler()
Returns the error handler for errors discovered while parsing
the input source.
|
javax.xml.parsers.SAXParserFactory |
getFactory()
Returns the factory for parsing SAX events.
|
org.xml.sax.EntityResolver |
getResolver()
Returns the resolver for resolving references while parsing
the input source.
|
protected org.xml.sax.XMLReader |
makeReader(boolean isForWrite) |
protected javax.xml.parsers.SAXParserFactory |
makeSAXParserFactory() |
org.xml.sax.InputSource[] |
newArray(int length)
Constructs an array for the handled content representation
|
static ContentHandleFactory |
newFactory()
Creates a factory to create a InputSourceHandle instance for a SAX InputSource.
|
InputSourceHandle |
newHandle()
Constructs a new handle for the same content representation,
initializing the new handle with the same format and mime type.
|
InputSourceHandle[] |
newHandleArray(int length)
Constructs an uninitialized array with the specified length with items
of the same content representation.
|
void |
process(org.xml.sax.ContentHandler handler)
Reads the input source, sending SAX events to the supplied content handler.
|
protected java.lang.Class<java.io.InputStream> |
receiveAs() |
protected void |
receiveContent(java.io.InputStream content) |
protected OutputStreamSender |
sendContent() |
protected OutputStreamSender |
sendContent(org.xml.sax.InputSource content) |
void |
set(org.xml.sax.InputSource content)
Assigns an input source as the content.
|
void |
setDefaultWriteSchema(javax.xml.validation.Schema schema)
Specifies the default schema for validating the input source.
|
void |
setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Specifies the error handler for errors discovered while parsing
the input source.
|
void |
setFactory(javax.xml.parsers.SAXParserFactory factory)
Specifies the factory for parsing SAX events.
|
void |
setFormat(Format format)
Restricts the format to XML.
|
void |
setResolver(org.xml.sax.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.
|
org.xml.sax.InputSource |
toContent(java.io.InputStream serialization)
Converts the serialization to the content representation.
|
java.lang.String |
toString()
Buffers the SAX input source and returns the buffer
as an XML string.
|
InputSourceHandle |
with(org.xml.sax.InputSource content)
Assigns an input source as the content and returns the handle
as a fluent convenience.
|
InputSourceHandle |
withMimetype(java.lang.String mimetype)
Specifies the mime type of the content and returns the handle
as a fluent convenience.
|
void |
write(java.io.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, setServerTimestamp
getPointInTimeQueryTimestamp, isResendable, setPointInTimeQueryTimestamp, setResendable, setResponseServerTimestamp
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
resendableHandleFor
newHandle, resendableHandleFor
public InputSourceHandle()
public InputSourceHandle(org.xml.sax.InputSource content)
content
- a SAX input sourcepublic static ContentHandleFactory newFactory()
public org.xml.sax.EntityResolver getResolver()
public void setResolver(org.xml.sax.EntityResolver resolver)
resolver
- the reference resolverpublic org.xml.sax.ErrorHandler getErrorHandler()
public void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
errorHandler
- the error handlerpublic org.xml.sax.InputSource get()
get
in interface ContentHandle<org.xml.sax.InputSource>
public void set(org.xml.sax.InputSource content)
set
in interface ContentHandle<org.xml.sax.InputSource>
content
- an input sourcepublic InputSourceHandle with(org.xml.sax.InputSource content)
content
- an input sourcepublic java.lang.Class<org.xml.sax.InputSource> getContentClass()
ContentHandle
getContentClass
in interface ContentHandle<org.xml.sax.InputSource>
public InputSourceHandle newHandle()
ContentHandle
newHandle
in interface BufferableContentHandle<org.xml.sax.InputSource,java.io.InputStream>
newHandle
in interface ContentHandle<org.xml.sax.InputSource>
public InputSourceHandle[] newHandleArray(int length)
BufferableContentHandle
newHandleArray
in interface BufferableContentHandle<org.xml.sax.InputSource,java.io.InputStream>
length
- the number of positions in the arraypublic org.xml.sax.InputSource[] newArray(int length)
ContentHandle
newArray
in interface ContentHandle<org.xml.sax.InputSource>
length
- the size of the array (zero or more)public void process(org.xml.sax.ContentHandler handler)
handler
- the SAX content handlerpublic void setFormat(Format format)
setFormat
in interface ContentDescriptor
setFormat
in class BaseHandle<java.io.InputStream,OutputStreamSender>
format
- the format of the contentpublic InputSourceHandle withMimetype(java.lang.String mimetype)
mimetype
- the mime type of the contentpublic void fromBuffer(byte[] buffer)
BufferableHandle
fromBuffer
in interface BufferableHandle
buffer
- the byte arraypublic byte[] toBuffer()
BufferableHandle
toBuffer
in interface BufferableHandle
public org.xml.sax.InputSource toContent(java.io.InputStream serialization)
BufferableContentHandle
toContent
in interface BufferableContentHandle<org.xml.sax.InputSource,java.io.InputStream>
serialization
- a serialization of the contentpublic org.xml.sax.InputSource bytesToContent(byte[] buffer)
BufferableContentHandle
bytesToContent
in interface BufferableContentHandle<org.xml.sax.InputSource,java.io.InputStream>
buffer
- the byte serializationpublic byte[] contentToBytes(org.xml.sax.InputSource content)
BufferableContentHandle
contentToBytes
in interface BufferableContentHandle<org.xml.sax.InputSource,java.io.InputStream>
content
- the contentpublic java.lang.String toString()
toString
in class java.lang.Object
public javax.xml.parsers.SAXParserFactory getFactory() throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
- if such an error occurs while initializing the
new factoryjavax.xml.parsers.ParserConfigurationException
- if such an error occurs while
initializing the new factorypublic void setFactory(javax.xml.parsers.SAXParserFactory factory)
factory
- the SAX factoryprotected javax.xml.parsers.SAXParserFactory makeSAXParserFactory() throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
public javax.xml.validation.Schema getDefaultWriteSchema()
public void setDefaultWriteSchema(javax.xml.validation.Schema schema)
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 documentsprotected org.xml.sax.XMLReader makeReader(boolean isForWrite)
protected java.lang.Class<java.io.InputStream> receiveAs()
receiveAs
in class com.marklogic.client.impl.HandleImplementation<java.io.InputStream,OutputStreamSender>
protected void receiveContent(java.io.InputStream content)
receiveContent
in class com.marklogic.client.impl.HandleImplementation<java.io.InputStream,OutputStreamSender>
protected OutputStreamSender sendContent()
sendContent
in class com.marklogic.client.impl.HandleImplementation<java.io.InputStream,OutputStreamSender>
protected OutputStreamSender sendContent(org.xml.sax.InputSource content)
public void write(java.io.OutputStream out) throws java.io.IOException
OutputStreamSender
write
in interface OutputStreamSender
out
- the output stream receiving the contentjava.io.IOException
- if io problems arisepublic void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
Copyright © 2013-2021 MarkLogic Corporation.