|
XCC/J 4.0-9 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.marklogic.xcc.examples.SemiBufferedContent
public class SemiBufferedContent
This is a specialized Content implementation
that takes an InputStream and will either buffer the
content of the stream if it's small enough, or copy the content to
a temporary disk file otherwise.
Click here for the source code for this class
Use this class rather than
ContentFactory.newContent(String, java.io.InputStream, com.marklogic.xcc.ContentCreateOptions)
when the size of the input stream may be too large to buffer in memory
and you need to assure that retries are supported when calling
Session.insertContent(com.marklogic.xcc.Content).
A buffer will be allocated of the size you specify. The
InputStream will be read into that buffer until either the
stream is fully read or the buffer fills up. If all the content fits into
the buffer, then this class will be equivalent to
ContentFactory.newContent(String, byte[], com.marklogic.xcc.ContentCreateOptions).
If the internal buffer fills up, then a temp file is created and all the
content is written to it. This class will then be equivalent to
ContentFactory.newContent(String, java.io.File, com.marklogic.xcc.ContentCreateOptions).
If you provide a File object as the fifth argument to the
constructor, then it is passed to
File.createTempFile(String, String, java.io.File) to specify the
directory in which to create the temporary file. If null, then the
system-default temp directory is used.
| Constructor Summary | |
|---|---|
SemiBufferedContent(String uri,
ContentCreateOptions options,
InputStream input,
int bufferSize)
Instantiate a Content object that
will either buffer the InputStream or copy
it to disk, depending on whether the size exceeds the provided
buffer size. |
|
SemiBufferedContent(String uri,
ContentCreateOptions options,
InputStream input,
int bufferSize,
File directory)
Instantiate a Content object that
will either buffer the InputStream or copy
it to disk, depending on whether the stream size exceeds the provided
buffer size. |
|
| 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. |
String |
getUri()
The URI with which this content should be inserted. |
boolean |
isRewindable()
Indicates whether this Content instance is rewindable and therefore automatically retryable. |
InputStream |
openDataStream()
Return the byte stream that makes up this document. |
void |
rewind()
This method tells the implementation that the content should be rewound to start again. |
long |
size()
The size of the content, if known. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SemiBufferedContent(String uri,
ContentCreateOptions options,
InputStream input,
int bufferSize,
File directory)
throws IOException
Content object that
will either buffer the InputStream or copy
it to disk, depending on whether the stream size exceeds the provided
buffer size.
uri - The URI to use when the content is inserted.options - The ContentCreateOptions
object to use when the content is inserted.input - An InputStream object, which will
be consumed when this object is created.bufferSize - The maximum number of bytes to buffer in memory
before spilling the content to a temporary disk file.directory - A File object that specifies a
directory where the temporary file, if needed, will be created.
This parameter may be null.
IOException - If there is a problem reading the
InputStream or creating the temporary file.
public SemiBufferedContent(String uri,
ContentCreateOptions options,
InputStream input,
int bufferSize)
throws IOException
Content object that
will either buffer the InputStream or copy
it to disk, depending on whether the size exceeds the provided
buffer size. This constructor defaults to using the system-specific
temporary file directory.
uri - The URI to use when the content is inserted.options - The ContentCreateOptions
object to use when the content is inserted.input - An InputStream object, which will
be consumed when this object is created.bufferSize - The maximum number of bytes to buffer in memory
before spilling the content to a temporary disk file.
IOException - If there is a problem reading the
InputStream or creating the temporary file.| Method Detail |
|---|
public String getUri()
Content
getUri in interface Content
public InputStream openDataStream()
throws IOException
ContentReturn the byte stream that makes up this document. If the content is character data, as opposed to a binary BLOB, this should be a UTF-8 encoding of the characters.
Each call to this method returns a stream
positioned at the beginning of the content. The
InputStream object should be closed by the client.
The returned InputStream is not intended to be shared.
Each call to this method implies that any prior state
should be discarded and a new stream created that
is positioned at the beginning of the content.
openDataStream in interface ContentIOExceptionpublic ContentCreateOptions getCreateOptions()
ContentContentCreateOptions 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.
getCreateOptions in interface ContentContentCreateOptions.public boolean isRewindable()
ContentSession.insertContent(Content)) is
interrupted and this method returns true, then the
operation will automatically be restarted. If this
method returns false, then an exception will be thrown
immediately. If multiple Content objects are being
inserted at once (Session.insertContent(Content[]))
and any non-rewindable (Content object has already
been even partially sent, the insert will fail immediately.
isRewindable in interface ContentContent.openDataStream() may
be called repeatedly), false otherwise.
public void rewind()
throws IOException
ContentContent.isRewindable() returns true
and in that case only after Content.openDataStream()
has been called.
rewind in interface ContentIOException - If there is a problem rewinding.public long size()
Content
size in interface Contentpublic void close()
ContentContent.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.
close in interface Content
|
XCC/J 4.0-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