|
XCC/J 3.2-9 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.InputStream
com.marklogic.xcc.examples.DynamicContentStream
This class, which extends InputStream,
is an example of producing dynamic, on-the-fly content
that can be used with
ContentFactory.newUnBufferedContent(String, java.io.InputStream, com.marklogic.xcc.ContentCreateOptions).
Click here for the source code for this class
Like OutputStreamInserter, this is an example of
inserting dynamically generated or transformed on-the-fly
content. The OutputStreamInserter example uses
OutputStreamContent and spawns a thread which then
loops and writes to an OutputStream.
By contrast, this example illustrates how to insert
dynamic content without creating a new thread. Here,
a custom InputStream is passed to the standard
factory ContentFactory.newUnBufferedContent(String, java.io.InputStream, com.marklogic.xcc.ContentCreateOptions).
When Session.insertContent(com.marklogic.xcc.Content) is
invoked, it will repeatedly call back into this class to obtain
chunks of data to send to the server.
If your data generation can be expressed this way, multiple calls to obtain the data in chunks, it is preferrable to spawning a new thread.
Note that if your content is potentially large, you
should use the above unbuffered factory method. If
you call
ContentFactory.newContent(String, java.io.InputStream, com.marklogic.xcc.ContentCreateOptions),
XCC will first consume and buffer the entire stream
before attempting the insert. If the content is unbuffered,
then automatic error recovery cannot be performed.
| Constructor Summary | |
DynamicContentStream(int lines)
Constructor for the example, which takes the number of lines to generate in the dummy document. |
|
| Method Summary | |
int |
fillBuffer(byte[] buffer)
This method will be called repeatedly as XCC reads data from the InputStream (this object). |
static void |
main(String[] args)
Example invocation that uses an instance of this class to insert dynamically-generated content, without spawning a separate thread. |
int |
read()
Read a single byte. |
int |
read(byte[] userBuffer,
int off,
int len)
Read "len" bytes into "userBuffer", starting at "off". |
| Methods inherited from class java.io.InputStream |
available, close, mark, markSupported, read, reset, skip |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public DynamicContentStream(int lines)
lines - Number of lines to put in the programmatically
generated document.| Method Detail |
public int read()
throws IOException
IOException - If there is a problem.
public int read(byte[] userBuffer,
int off,
int len)
throws IOException
userBuffer - The buffer to place data in.off - Index into userBuffer where data should be placed.len - The maximum number of bytes to transfer.
IOException - Will not happen in this sample implementation
but could conceivably be thrown by fillBUffer().public int fillBuffer(byte[] buffer)
InputStream (this object). In a real
app, this method would do something more useful, such as
reading data from some other source and transforming it.
This dummy implementation uses a simple state machine
to produce the beginning of a document, then the variable
length body, then the end and finally indicates EOS.
buffer - The byte array to which data should be copied.
public static void main(String[] args)
throws Exception
args - Server URI: xcc://user:password@host:port/contentbase,
Doc URI: any valid URI string to assign to the new content.
Exception - If anything bad happens.
|
XCC/J 3.2-9 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Complete online documentation for MarkLogic Server, XQuery and related components may be found at developer.marklogic.com