com.marklogic.xcc.examples

## Class OutputStreamInserter

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

-     public class OutputStreamInserter
      extends java.lang.Object

  This class illustrates a sample usage of the `OutputStreamContent` class.

  Click here for the source code for this class

  A simple inner class is defined here which generates some content programmatically and writes it to an `OutputStream`. It makes use of `OutputStreamContent` to obtain an `OutputStream` instance tied to a `Content` object.

  The way this works is that `OutputStreamContent` creates a pipe (double-ended stream). A thread is spawned which writes data to the sink end of the pipe. The `OutputStreamContent` object is passed to `Session.insertContent(com.marklogic.xcc.Content)` which will ultimately read data from the source end of the pipe. It's therefore important that the writer thread be started before doing the insert.

  To make use of `OutputStreamContent`, you simply need to implement the standard `Runnable` interface and put your data transfer logic in the `Runnable.run()` method.

  See the source code for the main() method.

  See Also:
    `OutputStreamContent`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `OutputStreamInserter.DocBuilder` A simple dummy content generator which writes to an `OutputStream`.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `main(java.lang.String[] args)` Looks for a server URI and a document URI on the command line, then spawns a thread to generate and insert some content there.
    `static java.lang.Thread` | `spawnThread(java.lang.Runnable runnable)` Create and start a new `Thread` for the given `Runnable`.

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

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

- - ### Method Detail

    - #### main

          public static void main(java.lang.String[] args)
                           throws java.lang.Exception

      Looks for a server URI and a document URI on the command line, then spawns a thread to generate and insert some content there.
      Parameters:
        `args` - Server URI: xcc://user:password@host:port/contentbase, Doc URI: any valid URI string to assign to the new content.
      Throws:
        `java.lang.Exception` - If anything bad happens.

    - #### spawnThread

          public static java.lang.Thread spawnThread(java.lang.Runnable runnable)

      Create and start a new `Thread` for the given `Runnable`. The run() method of this object will be invoked in a new thread and should write the desired content to the `OutputStream`.
      Parameters:
        `runnable` - An instance of `Runnable`.
      Returns:
        A reference to the newly created `Thread`. The new thread may or may not have begun executing upon return from this method.

Copyright © 2025 MarkLogic Corporation

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