com.marklogic.xcc.examples

## Class OutputStreamContent

- java.lang.Object
- - com.marklogic.xcc.examples.OutputStreamContent

- All Implemented Interfaces:
    Content

      public class OutputStreamContent
      extends java.lang.Object
      implements Content

  This is a specialized implementation of the `Content` interface which allows you to write your content to an `OutputStream`.

  Click here for the source code for this class

  This class creates a piped pair of streams. The source (`InputStream`) is passed to the standard factory method `ContentFactory.newUnBufferedContent(String, java.io.InputStream, com.marklogic.xcc.ContentCreateOptions)` . The sink (`OutputStream`) can be retrieved with the `getOutputStream()` method.

  NOTE: You must write to the `OutputStream` in a different thread than the one in which you invoke `Session.insertContent(com.marklogic.xcc.Content)` or your program may deadlock. The `OutputStreamInserter` class shows an example of how to use this class.

  See Also:
    `OutputStreamInserter`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `OutputStreamContent(java.lang.String uri, ContentCreateOptions options)` Construct an instance with the usual URI and options parameters, the actual content will be read from the other end of the pipe provided by `getOutputStream()`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` This method will be called after successfully consuming the content from the InputStream returned by `Content.openDataStream()`.
    `ContentCreateOptions` | `getCreateOptions()` Return the `ContentCreateOptions` object which should be applied to this object.
    `java.io.OutputStream` | `getOutputStream()` Return the end of the pipe to which you will write your content (the sink).
    `java.lang.String` | `getUri()` The URI with which this content should be inserted.
    `boolean` | `isRewindable()` The answer is "no".
    `java.io.InputStream` | `openDataStream()` Passes the read end (source) of the pipe to the content insertion framework.
    `void` | `rewind()` This streaming-only implementation is not rewindable.
    `long` | `size()` Unknown size.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### OutputStreamContent

          public OutputStreamContent(java.lang.String uri,
                                     ContentCreateOptions options)
                              throws java.io.IOException

      Construct an instance with the usual URI and options parameters, the actual content will be read from the other end of the pipe provided by `getOutputStream()`.
      Parameters:
        `uri` - The URI by which the content (document) will be known in the contentbase.
        `options` - An instance of `ContentCreateOptions`.
      Throws:
        `java.io.IOException` - If there is a problem creating the pipe (unlikely).

  - ### Method Detail

    - #### getOutputStream

          public java.io.OutputStream getOutputStream()

      Return the end of the pipe to which you will write your content (the sink).
      Returns:
        An instance of `OutputStream`. Be sure to close this object when you've written all the data.

    - #### getUri

          public java.lang.String getUri()

      Description copied from interface: `Content`
      The URI with which this content should be inserted.
      Specified by:
        `getUri` in interface `Content`
      Returns:
        A URI as a String.

    - #### openDataStream

          public java.io.InputStream openDataStream()
                                             throws java.io.IOException

      Passes the read end (source) of the pipe to the content insertion framework.
      Specified by:
        `openDataStream` in interface `Content`
      Returns:
        An instance of `InputStream`.
      Throws:
        `java.io.IOException` - Will never happen in this implementation.

    - #### getCreateOptions

          public ContentCreateOptions getCreateOptions()

      Description copied from interface: `Content`
      Return the `ContentCreateOptions` object which should be applied to this object. Note that if none was provided to the factory method that created this Content instance, one may have been created with appropriate defaults for the content provided.
      Specified by:
        `getCreateOptions` in interface `Content`
      Returns:
        An instance of `ContentCreateOptions`.

    - #### isRewindable

          public boolean isRewindable()

      The answer is "no".
      Specified by:
        `isRewindable` in interface `Content`
      Returns:
        Always returns false, this implementation is non-rewindable.

    - #### rewind

          public void rewind()
                      throws java.io.IOException

      This streaming-only implementation is not rewindable.
      Specified by:
        `rewind` in interface `Content`
      Throws:
        `java.io.IOException` - Will always be thrown if called.

    - #### size

          public long size()

      Unknown size.
      Specified by:
        `size` in interface `Content`
      Returns:
        Always returns -1 to indicate that the size is unknown.

    - #### close

          public void close()

      Description copied from interface: `Content`
      This method will be called after successfully consuming the content from the InputStream returned by `Content.openDataStream()`. This method need not close the stream, that is the responsibility of the client, but it may invalidate the stream. This method is to inform the implementation that any resources it may be holding can be released.
      Specified by:
        `close` in interface `Content`

Copyright © 2025 MarkLogic Corporation

Complete online documentation for MarkLogic Server, XQuery and related components may be found at docs.progress.com