public class LookAheadStream extends InputStream
LookAheadStream allows the encoding to be changed between markers. Handy for collections of webpages, which may use different encodings. However, the end marker must be obtainable using the default encoding.
LookAheadReader| Modifier and Type | Field and Description |
|---|---|
protected int[] |
Buffer
The read ahead buffer
|
protected int |
BufIndex
index of the first entry in the buffer
|
protected int |
BufLen
How many bytes are in the read ahead buffer
|
protected byte[] |
EndMarker
the end marker that it is pre-scanning the stream for
|
protected boolean |
EOF
have we reached the end of the file
|
protected int |
MarkerLen
How long is the end marker
|
protected InputStream |
ParentStream
the parent stream that this object is looking ahead in
|
| Constructor and Description |
|---|
LookAheadStream(InputStream parent,
byte[] endMarker)
Creates an instance of a LookAheadStream that will read from the
given stream until the end marker byte pattern is found.
|
LookAheadStream(InputStream parent,
String endMarker)
Creates an instance of a LookAheadStream that will read from the
given stream until the end marker is found.
|
LookAheadStream(InputStream parent,
String endMarker,
String charSet)
Creates an instance of a LookAheadStream that will read from the
given stream until the end marker is found.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the current stream, by setting the end of file
flag equal to true.
|
void |
mark(int x)
This method is not implemented.
|
boolean |
markSupported()
Support for marking is not implemented.
|
int |
read()
Read a byte from the parent stream, first checking that
it doesn't form part of the end marker.
|
int |
read(byte[] cbuf)
Read bytes into an array.
|
int |
read(byte[] cbuf,
int offset,
int len)
Read bytes into a portion of an array.
|
boolean |
ready()
Indicates whether there are more bytes
available to read from the stream.
|
void |
reset()
Reset the stream.
|
long |
skip(long n)
Skips n bytes from the stream.
|
availableprotected final InputStream ParentStream
protected final byte[] EndMarker
protected final int MarkerLen
protected int BufLen
protected int BufIndex
protected final int[] Buffer
protected boolean EOF
public LookAheadStream(InputStream parent, String endMarker)
parent - InputStream the stream used for reading the input.endMarker - String the marker which signifies the end of the stream.
Not deprecated, but recommended to use LookAheadStream(InputStream parent, String endMarker, String charSet) instead.public LookAheadStream(InputStream parent, String endMarker, String charSet) throws UnsupportedEncodingException
parent - InputStream the stream used for reading the input.endMarker - String the marker which signifies the end of the stream.charSet - String the name of the character set to use.UnsupportedEncodingExceptionpublic LookAheadStream(InputStream parent, byte[] endMarker)
parent - InputStream the stream used for reading the input.endMarker - String the marker which signifies the end of the stream.public int read()
throws IOException
read in class InputStreamIOException - if there is any error while reading from the stream.public int read(byte[] cbuf)
throws IOException
read in class InputStreamcbuf - cbuf - Destination bufferIOException - If an I/O error occurspublic int read(byte[] cbuf,
int offset,
int len)
throws IOException
read in class InputStreamcbuf - Destination bufferoffset - Offset at which to start storing byteslen - Maximum number of bytes to readIOException - If an I/O error occurspublic void reset()
throws IOException
reset in class InputStreamIOException - thrown if ParentStream.reset();public long skip(long n)
throws IOException
skip in class InputStreamn - long the number of bytes to skip.IOException - if there is any error while
reading from the stream.public boolean ready()
throws IOException
IOException - if there is any error while
reading from the stream.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionpublic boolean markSupported()
markSupported in class InputStreampublic void mark(int x)
mark in class InputStreamTerrier Information Retrieval Platform 5.1. Copyright © 2004-2019, University of Glasgow