biz.c24.io.api
Class RewindableInputStream
java.lang.Object
java.io.InputStream
biz.c24.io.api.RewindableInputStream
- All Implemented Interfaces:
- Closeable
public class RewindableInputStream
- extends InputStream
This class wraps the byte inputstreams we're presented with.
We need it because java.io.InputStreams don't provide
functionality to reread processed bytes, and they have a habit
of reading more than one character when you call their read()
methods. This means that, once we discover the true (declared)
encoding of a document, we can neither backtrack to read the
whole doc again nor start reading where we are with a new
reader.
This class allows rewinding an inputStream by allowing a mark
to be set, and the stream reset to that position. The
class assumes that it needs to read one character per
invocation when it's read() method is inovked, but uses the
underlying InputStream's read(char[], offset length) method--it
won't buffer data read this way!
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RewindableInputStream
public RewindableInputStream(InputStream is)
- Constructs a new instance, wrapping the supplied stream.
- Parameters:
is
- The stream to be wrapped.
setStartOffset
public void setStartOffset(int offset)
- Sets the offset at which parsing should start.
- Parameters:
offset
- The offset.
rewind
public void rewind()
- Rewinds the stream back to the begining.
read
public int read()
throws IOException
- Specified by:
read
in class InputStream
- Throws:
IOException
read
public int read(byte[] b,
int off,
int len)
throws IOException
- Overrides:
read
in class InputStream
- Throws:
IOException
skip
public long skip(long n)
throws IOException
- Overrides:
skip
in class InputStream
- Throws:
IOException
available
public int available()
throws IOException
- Overrides:
available
in class InputStream
- Throws:
IOException
mark
public void mark(int howMuch)
- Overrides:
mark
in class InputStream
reset
public void reset()
- Overrides:
reset
in class InputStream
markSupported
public boolean markSupported()
- Overrides:
markSupported
in class InputStream
close
public void close()
throws IOException
- Specified by:
close
in interface Closeable
- Overrides:
close
in class InputStream
- Throws:
IOException
C24 Technologies © 2002-2012: All Rights Reserved.