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.
OutputStreamContent
Modifier and Type | Class and Description |
---|---|
static class |
OutputStreamInserter.DocBuilder
A simple dummy content generator which writes to
an
OutputStream . |
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 . |
public static void main(java.lang.String[] args) throws java.lang.Exception
args
- Server URI:
xcc://user:password@host:port/contentbase, Doc URI: any valid URI
string to assign to the new content.java.lang.Exception
- If anything bad
happens.public static java.lang.Thread spawnThread(java.lang.Runnable runnable)
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
.runnable
- An instance of
Runnable
.Thread
. The new
thread may or may not have begun executing upon return from this
method.
Copyright © 2023 MarkLogic
Corporation. All Rights Reserved.
Complete online documentation for MarkLogic Server,
XQuery and related components may
be found at
developer.marklogic.com