Overview | Package | Class | Tree | Deprecated | Index | Help
| XCC/J 4.2-9
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.marklogic.xcc.examples
Class OutputStreamContent

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

All Implemented Interfaces:
  Content

    public class OutputStreamContent

extends 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
`OutputStreamContent(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
`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.
`OutputStream` | `getOutputStream()` Return the end of the pipe to which you will write your content (the sink).
`String` | `getUri()` The URI with which this content should be inserted.
`boolean` | `isRewindable()` The answer is "no".
`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(String uri,
                               ContentCreateOptions options)
                        throws 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:
    `IOException` - If there is a problem creating the pipe (unlikely).

Method Detail

### getOutputStream

    public 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 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 InputStream openDataStream()
                               throws 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:
    `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 IOException

  This streaming-only implementation is not rewindable.

  Specified by:
    `rewind` in interface `Content`
  Throws:
    `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`

Overview | Package | Class | Tree | Deprecated | Index | Help
| XCC/J 4.2-9
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2012 MarkLogic Corporation, All Rights Reserved.

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