/** * Get the {@link DataHandlerWriter} extension for a given {@link XMLStreamWriter}. 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). * * @param writer * the stream for which the method should return the {@link DataHandlerWriter} * extension * @return a reference to the extension interface exposed by the writer or an implementation the * emulates the extension; the return value is never <code>null</code> */ public static DataHandlerWriter getDataHandlerWriter(final XMLStreamWriter writer) { DataHandlerWriter dataHandlerWriter = internalGetDataHandlerWriter(writer); if (dataHandlerWriter == null) { return new DataHandlerWriter() { public void writeDataHandler(DataHandler dataHandler, String contentID, boolean optimize) throws IOException, XMLStreamException { writeBase64(writer, dataHandler); } public void writeDataHandler(DataHandlerProvider dataHandlerProvider, String contentID, boolean optimize) throws IOException, XMLStreamException { writeBase64(writer, dataHandlerProvider.getDataHandler()); } }; } else { return dataHandlerWriter; } }
DataHandlerWriter dataHandlerWriter = internalGetDataHandlerWriter(writer); if (dataHandlerWriter != null) { dataHandlerWriter.writeDataHandler(dataHandler, contentID, optimize);
/** * Write binary content to the stream. This method is similar to * {@link #writeDataHandler(XMLStreamWriter, DataHandler, String, boolean)}, * but supports deferred loading of the data handler. * * @param writer * the stream writer to write the data to * @param dataHandlerProvider * the binary content to write * @param contentID * an existing content ID for the binary data * @param optimize * indicates whether the content is eligible for optimization * @throws IOException * if an error occurs while reading from the data handler * @throws XMLStreamException * if an error occurs while writing to the underlying stream */ public static void writeDataHandler(XMLStreamWriter writer, DataHandlerProvider dataHandlerProvider, String contentID, boolean optimize) throws IOException, XMLStreamException { DataHandlerWriter dataHandlerWriter = internalGetDataHandlerWriter(writer); if (dataHandlerWriter != null) { dataHandlerWriter.writeDataHandler(dataHandlerProvider, contentID, optimize); } else { writeBase64(writer, dataHandlerProvider.getDataHandler()); } }