public class XMLStreamWriterUtils extends Object
XMLStreamWriter
objects.Constructor and Description |
---|
XMLStreamWriterUtils() |
Modifier and Type | Method and Description |
---|---|
static DataHandlerWriter |
getDataHandlerWriter(javax.xml.stream.XMLStreamWriter writer)
Get the
DataHandlerWriter extension for a given XMLStreamWriter . |
static void |
writeBase64(javax.xml.stream.XMLStreamWriter writer,
javax.activation.DataHandler dh)
Write base64 encoded data to a stream writer.
|
static void |
writeDataHandler(javax.xml.stream.XMLStreamWriter writer,
DataHandlerProvider dataHandlerProvider,
String contentID,
boolean optimize)
Write binary content to the stream.
|
static void |
writeDataHandler(javax.xml.stream.XMLStreamWriter writer,
javax.activation.DataHandler dataHandler,
String contentID,
boolean optimize)
Write binary content to the stream.
|
public static void writeBase64(javax.xml.stream.XMLStreamWriter writer, javax.activation.DataHandler dh) throws IOException, javax.xml.stream.XMLStreamException
XMLStreamConstants.CHARACTERS
events 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
writeDataHandler(XMLStreamWriter, DataHandler, String, boolean)
or
writeDataHandler(XMLStreamWriter, DataHandlerProvider, String, boolean)
to
enable optimization (if supported by the XMLStreamWriter
).
writer
- the stream writer to write the data todh
- the data handler containing the data to encodeIOException
- if an error occurs when reading the data from the data handlerjavax.xml.stream.XMLStreamException
- if an error occurs when writing the base64 encoded data to
the streampublic static DataHandlerWriter getDataHandlerWriter(javax.xml.stream.XMLStreamWriter writer)
DataHandlerWriter
extension for a given XMLStreamWriter
. If the
writer expose 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).writer
- the stream for which the method should return the DataHandlerWriter
extensionnull
public static void writeDataHandler(javax.xml.stream.XMLStreamWriter writer, javax.activation.DataHandler dataHandler, String contentID, boolean optimize) throws IOException, javax.xml.stream.XMLStreamException
XMLStreamWriter
,
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 the
DataHandlerWriter
extension. If the writer doesn't expose this extension,
the method will fall back to writeBase64(XMLStreamWriter, DataHandler)
.
Please refer to the documentation of DataHandlerWriter
for a more
detailed description of the semantics of the different arguments.
writer
- the stream writer to write the data todataHandler
- the binary content to writecontentID
- an existing content ID for the binary dataoptimize
- indicates whether the content is eligible for optimizationIOException
- if an error occurs while reading from the data handlerjavax.xml.stream.XMLStreamException
- if an error occurs while writing to the underlying streampublic static void writeDataHandler(javax.xml.stream.XMLStreamWriter writer, DataHandlerProvider dataHandlerProvider, String contentID, boolean optimize) throws IOException, javax.xml.stream.XMLStreamException
writeDataHandler(XMLStreamWriter, DataHandler, String, boolean)
,
but supports deferred loading of the data handler.writer
- the stream writer to write the data todataHandlerProvider
- the binary content to writecontentID
- an existing content ID for the binary dataoptimize
- indicates whether the content is eligible for optimizationIOException
- if an error occurs while reading from the data handlerjavax.xml.stream.XMLStreamException
- if an error occurs while writing to the underlying streamCopyright © 2004-2013 The Apache Software Foundation. All Rights Reserved.