Package org.apache.jasper.xmlparser
Class XMLEncodingDetector.RewindableInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.jasper.xmlparser.XMLEncodingDetector.RewindableInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Enclosing class:
- XMLEncodingDetector
private final class XMLEncodingDetector.RewindableInputStream extends java.io.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!
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
fData
private int
fEndOffset
private java.io.InputStream
fInputStream
private int
fLength
private int
fMark
private int
fOffset
private int
fStartOffset
-
Constructor Summary
Constructors Constructor Description RewindableInputStream(java.io.InputStream is)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
void
mark(int howMuch)
boolean
markSupported()
int
read()
int
read(byte[] b, int off, int len)
void
reset()
void
rewind()
void
setStartOffset(int offset)
long
skip(long n)
-
-
-
Method Detail
-
setStartOffset
public void setStartOffset(int offset)
-
rewind
public void rewind()
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException
- Overrides:
skip
in classjava.io.InputStream
- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException
- Overrides:
available
in classjava.io.InputStream
- Throws:
java.io.IOException
-
mark
public void mark(int howMuch)
- Overrides:
mark
in classjava.io.InputStream
-
reset
public void reset()
- Overrides:
reset
in classjava.io.InputStream
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classjava.io.InputStream
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
-
-