XCC/J 3.2-9

com.marklogic.xcc.examples
Class OutputStreamInserter

java.lang.Object
  extended bycom.marklogic.xcc.examples.OutputStreamInserter

public class OutputStreamInserter
extends 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
static class OutputStreamInserter.DocBuilder
          A simple dummy content generator which writes to an OutputStream.
 
Method Summary
static void main(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 Thread spawnThread(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(String[] args)
                 throws 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:
Exception - If anything bad happens.

spawnThread

public static Thread spawnThread(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.

XCC/J 3.2-9

Copyright © 2003-2008 Mark Logic Corporation, All Rights Reserved.

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