Methods Summary |
---|
public int | available()Returns the number of bytes that are available before this stream will
block.
Note: The source stream may just be a sequence of {@code "\r\n"} bytes
which are converted into {@code '\n'} by this stream. Therefore,
{@code available} returns only {@code in.available() / 2} bytes as
result.
return in.available() / 2 + (lastChar == -1 ? 0 : 1);
|
public int | getLineNumber()Returns the current line number for this stream. Numbering starts at 0.
return lineNumber;
|
public void | mark(int readlimit)Sets a mark position in this stream. The parameter {@code readlimit}
indicates how many bytes can be read before the mark is invalidated.
Sending {@code reset()} will reposition this stream back to the marked
position, provided that {@code readlimit} has not been surpassed.
The line number count will also be reset to the last marked
line number count.
This implementation sets a mark in the filtered stream.
in.mark(readlimit);
markedLineNumber = lineNumber;
markedLastChar = lastChar;
|
public int | read()Reads a single byte from the filtered stream and returns it as an integer
in the range from 0 to 255. Returns -1 if the end of this stream has been
reached.
The line number count is incremented if a line terminator is encountered.
Recognized line terminator sequences are {@code '\r'}, {@code '\n'} and
{@code "\r\n"}. Line terminator sequences are always translated into
{@code '\n'}.
int currentChar = lastChar;
if (currentChar == -1) {
currentChar = in.read();
} else {
lastChar = -1;
}
switch (currentChar) {
case '\r":
currentChar = '\n";
lastChar = in.read();
if (lastChar == '\n") {
lastChar = -1;
}
// fall through
case '\n":
lineNumber++;
}
return currentChar;
|
public int | read(byte[] buffer, int offset, int length)Reads at most {@code length} bytes from the filtered stream and stores
them in the byte array {@code buffer} starting at {@code offset}.
Returns the number of bytes actually read or -1 if no bytes have been
read and the end of this stream has been reached.
The line number count is incremented if a line terminator is encountered.
Recognized line terminator sequences are {@code '\r'}, {@code '\n'} and
{@code "\r\n"}. Line terminator sequences are always translated into
{@code '\n'}.
// BEGIN android-changed
if (buffer == null) {
throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
}
// avoid int overflow
// Exception priorities (in case of multiple errors) differ from
// RI, but are spec-compliant.
// removed redundant check, used (offset | length) < 0
// instead of (offset < 0) || (length < 0) to safe one operation
if ((offset | length) < 0 || length > buffer.length - offset) {
throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
}
// END android-changed
for (int i = 0; i < length; i++) {
int currentChar;
try {
currentChar = read();
} catch (IOException e) {
if (i != 0) {
return i;
}
throw e;
}
if (currentChar == -1) {
return i == 0 ? -1 : i;
}
buffer[offset + i] = (byte) currentChar;
}
return length;
|
public void | reset()Resets this stream to the last marked location. It also resets the line
count to what is was when this stream was marked.
in.reset();
lineNumber = markedLineNumber;
lastChar = markedLastChar;
|
public void | setLineNumber(int lineNumber)Sets the line number of this stream to the specified
{@code lineNumber}. Note that this may have side effects on the
line number associated with the last marked position.
this.lineNumber = lineNumber;
|
public long | skip(long count)Skips {@code count} number of bytes in this stream. Subsequent
{@code read()}'s will not return these bytes unless {@code reset()} is
used. This implementation skips {@code count} number of bytes in the
filtered stream and increments the line number count whenever line
terminator sequences are skipped.
if (count <= 0) {
return 0;
}
for (int i = 0; i < count; i++) {
int currentChar = read();
if (currentChar == -1) {
return i;
}
}
return count;
|