|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.cdc.io.ConnectionBaseAdapter
com.sun.cdc.io.BufferedConnectionAdapter
public abstract class BufferedConnectionAdapter
This class adds read buffering to the
ConnectionBaseAdapter.
Implements InputStream.available(), however a subclass must
specify a buffer size greater than 0 and override
readBytesNonBlocking(byte[], int, int) in order to for available
to work properly.
| Field Summary | |
|---|---|
protected byte[] |
buf
The internal buffer array where the data is stored. |
protected int |
count
The index one greater than the index of the last valid byte in the buffer. |
protected boolean |
eof
The end of file flag. |
protected int |
pos
The current position in the buffer. |
| Fields inherited from class com.sun.cdc.io.ConnectionBaseAdapter |
|---|
connectionOpen, iStreams, maxIStreams, maxOStreams, oStreams |
| Constructor Summary | |
|---|---|
protected |
BufferedConnectionAdapter(int sizeOfBuffer)
Initializes the connection. |
| Method Summary | |
|---|---|
int |
available()
Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. |
protected abstract int |
nonBufferedRead(byte[] b,
int off,
int len)
Reads up to len bytes of data from the input stream into
an array of bytes, blocks until at least one byte is available. |
int |
readBytes(byte[] b,
int off,
int len)
Reads up to len bytes of data from the input stream into
an array of bytes, blocks until at least one byte is available. |
protected int |
readBytesNonBlocking(byte[] b,
int off,
int len)
Reads up to len bytes of data from the input stream into
an array of bytes, but does not block if no bytes available. |
| Methods inherited from class com.sun.cdc.io.ConnectionBaseAdapter |
|---|
checkForPermission, close, closeInputStream, closeOutputStream, connect, disconnect, ensureNoStreamsOpen, ensureOpen, flush, mark, markSupported, openDataInputStream, openDataOutputStream, openInputStream, openOutputStream, openPrim, openPrim, reset, writeBytes |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected boolean eof
protected byte[] buf
protected int count
0 through buf.length;
elements buf[0] through buf[count-1]
contain buffered input data obtained
from the underlying input stream.
protected int pos
buf array.
This value is always in the range 0
through count. If it is less
than count, then buf[pos]
is the next byte to be supplied as input;
if it is equal to count, then
the next read or skip
operation will require more bytes to be
read from the contained input stream.
| Constructor Detail |
|---|
protected BufferedConnectionAdapter(int sizeOfBuffer)
sizeOfBuffer - size of the internal buffer or 0 for no buffer| Method Detail |
|---|
public int readBytes(byte[] b,
int off,
int len)
throws IOException
len bytes of data from the input stream into
an array of bytes, blocks until at least one byte is available.
Do not use this method if openInputStream has been called
since the input stream may be buffering data.
readBytes in class ConnectionBaseAdapterb - the buffer into which the data is read.off - the start offset in array b
at which the data is written.len - the maximum number of bytes to read.
-1 if there is no more data because the end of
the stream has been reached.
IOException - if an I/O error occurs.
protected int readBytesNonBlocking(byte[] b,
int off,
int len)
throws IOException
len bytes of data from the input stream into
an array of bytes, but does not block if no bytes available. A subclass
should implement this to so the available method on the InputStream
will be useful.
Sets the eof field of the connection when the native read
returns -1.
The readBytesNonBlocking method of
ConnectionBaseAdapter does nothing and returns 0.
b - the buffer into which the data is read.off - the start offset in array b
at which the data is written.len - the maximum number of bytes to read.
-1 if there is no more data because the end of
the stream has been reached.
IOException - if an I/O error occurs.
public int available()
throws IOException
The available method always returns 0 if
readBytesNonBlocking(byte[], int, int) is
not overridden by the subclass or there is not buffer.
available in class ConnectionBaseAdapterIOException - if an I/O error occurs.
protected abstract int nonBufferedRead(byte[] b,
int off,
int len)
throws IOException
len bytes of data from the input stream into
an array of bytes, blocks until at least one byte is available.
Sets the eof field of the connection when there is
no more data in the stream to read.
b - the buffer into which the data is read.off - the start offset in array b
at which the data is written.len - the maximum number of bytes to read.
-1 if there is no more data because the end of
the stream has been reached.
IOException - if an I/O error occurs.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||