Methods Summary |
---|
public void | close()Closes the input stream.
in.close();
baos.close();
baos = null;
buffer = null;
|
public void | mark(int lookahead)This implementation of mark() supports infinite lookahead.
baos = new ByteArrayOutputStream();
|
public boolean | markSupported()Checks if mark is supported.
return true;
|
public int | read(byte[] b)Reads next block of bytes from the stream.
return read(b, 0, b.length);
|
public int | read()Reads a byte from the stream.
if (buffer != null) {
return readFromBuffer();
} else {
return readFromStream();
}
|
public int | read(byte[] b, int offset, int length)Reads next block of bytes from the stream.
if (buffer != null) {
return readFromBuffer(b, offset, length);
} else {
return readFromStream(b, offset, length);
}
|
private int | readFromBuffer(byte[] b, int offset, int length)Reads next block of bytes from the internal buffer.
int bytesRead = -1;
if (length <= buffer.length - bufferIndex) {
System.arraycopy(buffer, bufferIndex, b, offset, length);
bufferIndex += length;
bytesRead = length;
} else {
int count = buffer.length - bufferIndex;
System.arraycopy(buffer, bufferIndex, b, offset, count);
buffer = null;
bytesRead = count;
}
if (baos != null) {
baos.write(b, offset, bytesRead);
}
return bytesRead;
|
private int | readFromBuffer()Reads a byte from the internal buffer.
int i = buffer[bufferIndex++];
if (baos != null) {
baos.write(i);
}
if (bufferIndex == buffer.length) {
buffer = null;
}
return i;
|
private int | readFromStream(byte[] b, int offset, int length)Reads next block of bytes from the stream.
int i = in.read(b, offset, length);
if (i != -1 && baos != null) {
baos.write(b, offset, i);
}
return i;
|
private int | readFromStream()Reads next value from the input stream.
int i = in.read();
if (i != -1 && baos != null) {
baos.write(i);
}
return i;
|
public void | reset()Reset the line markers.
if (baos == null) {
throw new IOException("Cannot reset an unmarked stream");
}
if (baos.size() == 0) {
// no data was read since the call to mark()
baos = null;
} else {
buffer = baos.toByteArray();
baos = null;
bufferIndex = 0;
}
|