Package org.apache.axiom.blob

# Interface Blob

All Known Subinterfaces:
  `MemoryBlob`, `OverflowableBlob`, `PartBlob`, `WritableBlob`

All Known Implementing Classes:
  `AbstractWritableBlob`, `PartDataHandlerBlob`

public interface Blob
Stores binary data.

Blobs are thread safe in the sense that methods defined by this interface may be called concurrently. In addition, two different threads can safely invoke methods on two different `InputStream` instances retrieved by `getInputStream()` concurrently. However some blobs (in particular `WritableBlob` implementations) may define additional methods and invoking these methods concurrently with methods defined by this interface is generally not thread safe.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `InputStream`
  `getInputStream()`
  Get an input stream to read the data in the blob.
  `long`
  `getSize()`
  Get the (approximate) size of the blob.
  `void`
  `writeTo(OutputStream out)`
  Write the data to a given output stream.

- ## Method Details

  - ### getInputStream

    InputStream getInputStream() throws IOException
    Get an input stream to read the data in the blob. A new `InputStream` object is returned each time this method is called, and the stream is positioned at the beginning of the data.
    Returns:
      the input stream to read the data from
    Throws:
      `IOException`

  - ### writeTo

    void writeTo(OutputStream out) throws org.apache.axiom.ext.io.StreamCopyException
    Write the data to a given output stream. This method can be called multiple times, i.e. it doesn't consume the content.
    Parameters:
      `out` - The output stream to write the data to. This method will not close the stream.
    Throws:
      `org.apache.axiom.ext.io.StreamCopyException` - Thrown if there is an I/O when reading the data from the blob or when writing it to the stream. `StreamCopyException.getOperation()` can be used to determine whether the failed operation was a read or a write.

  - ### getSize

    long getSize()
    Get the (approximate) size of the blob. Returns -1 if the size can't be determined without reading the entire blob (in which case the caller may want to use `writeTo(OutputStream)` with an `OutputStream` that counts the number of bytes to determine the size). The method may choose to return a value based on an estimation. This may be the case e.g. if reading the data involves a decoding operation, and the length of the resulting stream can't be determined precisely without performing the decoding operation.

    When reading the actual data, the code should always read until the end of the stream is reached (as indicated by the return value of the `read` methods of the `InputStream` class). It must be prepared to reach the end of the stream after a number of bytes that is lower or higher than the value returned by this method.

    Returns:
      the number of bytes in the blob, or -1 if the size is not known