Package org.apache.axiom.util.stax
Class XMLStreamWriterUtils
java.lang.Object
org.apache.axiom.util.stax.XMLStreamWriterUtils
Contains utility methods to work with
XMLStreamWriter objects.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BlobWritergetBlobWriter(XMLStreamWriter writer) Get theBlobWriterextension for a givenXMLStreamWriter.static voidwriteBase64(XMLStreamWriter writer, Blob blob) Write base64 encoded data to a stream writer.static voidwriteBlob(XMLStreamWriter writer, Blob blob, String contentID, boolean optimize) Write binary content to the stream.static voidwriteBlob(XMLStreamWriter writer, BlobProvider blobProvider, String contentID, boolean optimize) Write binary content to the stream.static voidwriteDTD(XMLStreamWriter writer, String rootName, String publicId, String systemId, String internalSubset) Prepare theDOCTYPEdeclaration using the provided information and output it usingXMLStreamWriter.writeDTD(String).
-
Constructor Details
-
XMLStreamWriterUtils
public XMLStreamWriterUtils()
-
-
Method Details
-
writeBase64
public static void writeBase64(XMLStreamWriter writer, Blob blob) throws IOException, XMLStreamException Write base64 encoded data to a stream writer. This will result in one or moreXMLStreamConstants.CHARACTERSevents to be written to the stream (or zero events if the data handler produces an empty byte sequence), i.e. the data is streamed from the data handler directly to the stream writer. Since no in-memory base64 representation of the entire binary data is built, this method is suitable for very large amounts of data.Note that this method will always serialize the data as base64 encoded character data. Serialization code should prefer using
writeBlob(XMLStreamWriter, Blob, String, boolean)orwriteBlob(XMLStreamWriter, BlobProvider, String, boolean)to enable optimization (if supported by theXMLStreamWriter).- Parameters:
writer- the stream writer to write the data toblob- the blob containing the data to encode- Throws:
IOException- if an error occurs when reading the data from the data handlerXMLStreamException- if an error occurs when writing the base64 encoded data to the stream
-
getBlobWriter
Get theBlobWriterextension for a givenXMLStreamWriter. If the writer exposes the extension, a reference to the extension interface implementation is returned. If the writer doesn't expose the extension, this method returns an instance of the extension interface that emulates the extension (by writing the binary data as base64 character data to the stream).- Parameters:
writer- the stream for which the method should return theBlobWriterextension- Returns:
- a reference to the extension interface exposed by the writer or an implementation the
emulates the extension; the return value is never
null
-
writeBlob
public static void writeBlob(XMLStreamWriter writer, Blob blob, String contentID, boolean optimize) throws IOException, XMLStreamException Write binary content to the stream. Depending on the suppliedXMLStreamWriter, the content will be written as base64 encoded character data or using an optimization scheme such as XOP/MTOM. The method attempts to submit the binary content using theBlobWriterextension. If the writer doesn't expose this extension, the method will fall back towriteBase64(XMLStreamWriter, Blob).Please refer to the documentation of
BlobWriterfor a more detailed description of the semantics of the different arguments.- Parameters:
writer- the stream writer to write the data toblob- the binary content to writecontentID- an existing content ID for the binary dataoptimize- indicates whether the content is eligible for optimization- Throws:
IOException- if an error occurs while reading from the data handlerXMLStreamException- if an error occurs while writing to the underlying stream
-
writeBlob
public static void writeBlob(XMLStreamWriter writer, BlobProvider blobProvider, String contentID, boolean optimize) throws IOException, XMLStreamException Write binary content to the stream. This method is similar towriteBlob(XMLStreamWriter, Blob, String, boolean), but supports deferred loading of the data handler.- Parameters:
writer- the stream writer to write the data toblobProvider- the binary content to writecontentID- an existing content ID for the binary dataoptimize- indicates whether the content is eligible for optimization- Throws:
IOException- if an error occurs while reading from the data handlerXMLStreamException- if an error occurs while writing to the underlying stream
-
writeDTD
public static void writeDTD(XMLStreamWriter writer, String rootName, String publicId, String systemId, String internalSubset) throws XMLStreamException Prepare theDOCTYPEdeclaration using the provided information and output it usingXMLStreamWriter.writeDTD(String).- Parameters:
writer- the stream writer to write theDOCTYPEdeclaration torootName- the root name, i.e. the name immediately following theDOCTYPEkeywordpublicId- the public ID of the external subset, ornullif there is no external subset or no public ID has been specified for the external subsetsystemId- the system ID of the external subset, ornullif there is no external subsetinternalSubset- the internal subset, ornullif there is none- Throws:
XMLStreamException- if an error occurs while writing to the stream
-