Methods Summary |
---|
public int | available()Return the number of bytes that can be read.
long avail = size - position;
if (avail <= 0) {
return 0;
} else if (avail > Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
} else {
return (int)avail;
}
|
public void | close()Close this input stream - resets the internal state to
the initial values.
eof = false;
position = 0;
mark = -1;
|
private int | doEndOfFile()Handle End of File.
eof = true;
if (throwEofException) {
throw new EOFException();
}
return -1;
|
public long | getPosition()Return the current position.
return position;
|
public long | getSize()Return the size this {@link InputStream} emulates.
return size;
|
public synchronized void | mark(int readlimit)Mark the current position.
if (!markSupported) {
throw new UnsupportedOperationException("Mark not supported");
}
mark = position;
this.readlimit = readlimit;
|
public boolean | markSupported()Indicates whether mark is supported.
return markSupported;
|
protected int | processByte()Return a byte value for the read() method.
This implementation returns zero.
// do nothing - overridable by subclass
return 0;
|
protected void | processBytes(byte[] bytes, int offset, int length)Process the bytes for the read(byte[], offset, length)
method.
This implementation leaves the byte array unchanged.
// do nothing - overridable by subclass
|
public int | read(byte[] bytes)Read some bytes into the specified array.
return read(bytes, 0, bytes.length);
|
public int | read(byte[] bytes, int offset, int length)Read the specified number bytes into an array.
if (eof) {
throw new IOException("Read after end of file");
}
if (position == size) {
return doEndOfFile();
}
position += length;
int returnLength = length;
if (position > size) {
returnLength = length - (int)(position - size);
position = size;
}
processBytes(bytes, offset, returnLength);
return returnLength;
|
public int | read()Read a byte.
if (eof) {
throw new IOException("Read after end of file");
}
if (position == size) {
return doEndOfFile();
}
position++;
return processByte();
|
public synchronized void | reset()Reset the stream to the point when mark was last called.
if (!markSupported) {
throw new UnsupportedOperationException("Mark not supported");
}
if (mark < 0) {
throw new IOException("No position has been marked");
}
if (position > (mark + readlimit)) {
throw new IOException("Marked position [" + mark +
"] is no longer valid - passed the read limit [" +
readlimit + "]");
}
position = mark;
eof = false;
|
public long | skip(long numberOfBytes)Skip a specified number of bytes.
if (eof) {
throw new IOException("Skip after end of file");
}
if (position == size) {
return doEndOfFile();
}
position += numberOfBytes;
long returnLength = numberOfBytes;
if (position > size) {
returnLength = numberOfBytes - (position - size);
position = size;
}
return returnLength;
|