Methods Summary |
---|
public int | available()Return the available bytes
return (byteBuffer.remaining());
|
public void | close()Close this stream.
|
protected int | doRead()Read bytes using the read ReadSelector
if ( key == null ) return -1;
byteBuffer.clear();
int count = 1;
int byteRead = 0;
Selector readSelector = null;
SelectionKey tmpKey = null;
try{
SocketChannel socketChannel = (SocketChannel)key.channel();
while (count > 0){
count = socketChannel.read(byteBuffer);
if ( count > -1 )
byteRead += count;
else
byteRead = count;
}
if ( byteRead == 0 ){
readSelector = SelectorFactory.getSelector();
if ( readSelector == null ){
return 0;
}
count = 1;
tmpKey = socketChannel
.register(readSelector,SelectionKey.OP_READ);
tmpKey.interestOps(tmpKey.interestOps() | SelectionKey.OP_READ);
int code = readSelector.select(readTimeout);
tmpKey.interestOps(
tmpKey.interestOps() & (~SelectionKey.OP_READ));
if ( code == 0 ){
return 0; // Return on the main Selector and try again.
}
while (count > 0){
count = socketChannel.read(byteBuffer);
if ( count > -1 )
byteRead += count;
else
byteRead = count;
}
}
} finally {
if (tmpKey != null)
tmpKey.cancel();
if ( readSelector != null){
// Bug 6403933
try{
readSelector.selectNow();
} catch (IOException ex){
;
}
SelectorFactory.returnSelector(readSelector);
}
byteBuffer.flip();
}
return byteRead;
|
public java.nio.ByteBuffer | getByteBuffer()Get the wrapped ByteBuffer
return byteBuffer;
|
public static int | getDefaultReadTimeout()
return defaultReadTimeout;
|
public int | getReadTimeout()Return the timeout between two consecutives Selector.select() when a
temporary Selector is used.
return readTimeout;
|
public boolean | markSupported()Return true if mark is supported.
return false;
|
public int | read(byte[] b, int offset, int length)Read the first byte of the wrapped ByteBuffer .
if (!byteBuffer.hasRemaining()) {
int eof = 0;
for (int i=0; i < readTry; i++) {
eof = doRead();
if ( eof != 0 ){
break;
}
}
if (eof <= 0){
return -1;
}
}
if (length > byteBuffer.remaining()) {
length = byteBuffer.remaining();
}
byteBuffer.get(b, offset, length);
return (length);
|
public int | read(java.nio.ByteBuffer bb)Read the first byte of the wrapped ByteBuffer .
if (!byteBuffer.hasRemaining()) {
int eof = 0;
for (int i=0; i < readTry; i++) {
eof = doRead();
if ( eof != 0 ){
break;
}
}
if (eof <= 0){
return -1;
}
}
bb.put(byteBuffer);
return bb.position();
|
public int | read()Read the first byte from the wrapped ByteBuffer .
if (!byteBuffer.hasRemaining()){
int eof = 0;
for (int i=0; i < readTry; i++) {
eof = doRead();
if ( eof != 0 ){
break;
}
}
}
return (byteBuffer.hasRemaining() ? (byteBuffer.get() & 0xff): -1);
|
public int | read(byte[] b)Read the bytes from the wrapped ByteBuffer .
return (read(b, 0, b.length));
|
public void | recycle()Recycle this object.
byteBuffer = null;
key = null;
readTimeout = defaultReadTimeout;
|
public void | setByteBuffer(java.nio.ByteBuffer byteBuffer)Set the wrapped ByteBuffer
this.byteBuffer = byteBuffer;
|
public static void | setDefaultReadTimeout(int aDefaultReadTimeout)
defaultReadTimeout = aDefaultReadTimeout;
|
public void | setReadTimeout(int rt)Set the timeout between two consecutives Selector.select() when a
temporary Selector is used.
readTimeout = rt;
|
public void | setSelectionKey(java.nio.channels.SelectionKey key)Set the SelectionKey used to reads bytes.
this.key = key;
|