|
TopoWeb Commons API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.InputStream | +--org.topoweb.io.StreamFragmenter
Fragments an underlying stream according to a delimiter sequence. This end-of-stream sequence is described by an array of integers with each integer standing in for a byte value. The EOS sequence of bytes is not filtered out. This allows the implementation to avoid reading ahead from the underlying stream. That is, this class does not buffer the underlying stream.
<xyz ..> .. <!-- other elements but no nested xyz sub-elements --> </xyz>Suppose furthur (in order to make the example simpler), that you know that the stream contains 10,000
xyz
elements. In order to
process each of these xyz
elements one at a time, you can
set up an instance of this class that will break your stream into a
series of XML fragments, as follows:
InputStream base = .. // get the base stream StreamFragmenter frag = StreamFragmenter.newUtfInstance("</xyz>"); for (int i = 0; i < 10000; ++i) { // read and process the next fragment // e.g. .. javax.xml.transform.Source src = new javax.xml.transform.stream.StreamSource(frag); .. frag.enableNext(); }
Constructor Summary | |
StreamFragmenter(java.io.InputStream base,
int[] eos)
Construct an instance with the given underlying stream and the given end-of-stream sequence. |
Method Summary | |
int |
available()
Returns the available bytes. |
void |
enableNext()
Enables the next fragment for reading. |
int[] |
getEosSequence()
Returns the end-of-stream sequence passed in at instantiation. |
boolean |
isEndOfBase()
Tests whether the end of the base stream was reached in the last read . |
static StreamFragmenter |
newUtfInstance(java.io.InputStream base,
java.lang.String eos)
Creates and returns a new instance using the given end-of-stream ( eos ) sequence. |
int |
read()
Reads and returns the next byte in the current fragment. |
Methods inherited from class java.io.InputStream |
close, mark, markSupported, read, read, reset, skip |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public StreamFragmenter(java.io.InputStream base, int[] eos) throws java.lang.IllegalArgumentException
base
- the base input streameos
- the end-of-stream sequence
java.lang.IllegalArgumentException
- if either of the parameters is null
;
if eos.length
is zeroMethod Detail |
public static StreamFragmenter newUtfInstance(java.io.InputStream base, java.lang.String eos)
eos
) sequence. The EOS sequence is the UTF-8
representation of the given eos
string.
base
- the base input streameos
- the EOS sequence expressed as a UTF-8 string
StreamFragmenter
instance over the
given base
input streampublic int[] getEosSequence()
public int available()
available
in class java.io.InputStream
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public boolean isEndOfBase()
read
.
true
, if the end of the base
stream has been reached; false
, o.w.public void enableNext() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the current fragment is not yet finished
|
TopoWeb Commons API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |