Package org.apache.axiom.ext.stax

# Interface BlobWriter

public interface BlobWriter
Extension interface for `XMLStreamWriter` implementations that can receive base64 encoded binary content as `Blob` objects. A stream writer implementing this extension may write the binary data as base64 encoded character data or using some optimization such as XOP/MTOM.

All the requirements specified in `org.apache.axiom.ext.stax` apply to this extension interface. In particular, a consumer MUST use `XMLStreamWriter.getProperty(String)` with the property name defined by `PROPERTY` to get a reference to this extension interface.

The interface defines two methods to write binary content, one that takes a `Blob` argument and one with a `BlobProvider` argument. The first should be used when the content is immediately available, while the second supports deferred loading of the data handler. The meaning of the `contentID` and `optimize` arguments is the same for both methods:

`contentID`
  A content ID of the binary content, if available. The semantics of this argument are similar to those defined for the return value of the `BlobReader.getContentID()` method:
  - This argument should only be set if a content ID has been used previously in an interaction with another component or system. The caller SHOULD NOT generate a new content ID solely for the purpose of invoking the extension.
  - The argument must be a raw content ID.
  - The implementation MUST NOT make any assumption about the uniqueness or validity of the content ID. It MAY ignore the supplied value.
`optimize`
  Specifies if binary content is eligible for optimization (e.g. using XOP) or if it should be serialized as base64. This is only an indication and the implementation MAY choose to override this value or ignore it entirely.

Instead of interacting directly with this extension interface, the consumer may use the `XMLStreamWriterUtils.writeBlob(javax.xml.stream.XMLStreamWriter, Blob, String, boolean)` or `XMLStreamWriterUtils.writeBlob(javax.xml.stream.XMLStreamWriter, BlobProvider, String, boolean)` utility methods. These methods make the processing of binary data entirely transparent for the caller.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `PROPERTY`
  The name of the property used to look up this extension interface from a `XMLStreamWriter` implementation.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `writeBlob(Blob blob, String contentID, boolean optimize)`
  Write binary content to the stream.
  `void`
  `writeBlob(BlobProvider blobProvider, String contentID, boolean optimize)`
  Write binary content to the stream.

- ## Field Details

  - ### PROPERTY

    static final String PROPERTY
    The name of the property used to look up this extension interface from a `XMLStreamWriter` implementation.

- ## Method Details

  - ### writeBlob

    void writeBlob(Blob blob, String contentID, boolean optimize) throws IOException, XMLStreamException
    Write binary content to the stream. The implementation may choose to write the data as base64 encoded character data or using an optimization protocol such as XOP/MTOM.
    Parameters:
      `blob` - the binary content to write
      `contentID` - an existing content ID for the binary data (see above)
      `optimize` - indicates whether the content is eligible for optimization (see above)
    Throws:
      `IOException` - if an error occurs while reading from the data handler
      `XMLStreamException` - if an error occurs while writing to the underlying stream

  - ### writeBlob

    void writeBlob(BlobProvider blobProvider, String contentID, boolean optimize) throws IOException, XMLStreamException
    Write binary content to the stream. This method allows the implementation to defer loading of the content. More precisely, if the implementation decides to use an optimization scheme such as XOP, then the content will not be written immediately to the underlying stream, but only after the XML infoset is complete. If the caller uses this method, the implementation can defer the actual loading of the binary content.
    Parameters:
      `blobProvider` - the binary content to write
      `contentID` - an existing content ID for the binary data (see above)
      `optimize` - indicates whether the content is eligible for optimization (see above)
    Throws:
      `IOException` - If an error occurs while reading from the data handler. Since the implementation is free to override the supplied `optimize` argument, it may attempt to load the binary data immediately. Because this operation may fail, the method must declare this exception.
      `XMLStreamException` - if an error occurs while writing to the underlying stream