FileDocCategorySizeDatePackage
ChannelIO.javaAPI DocSun JDK 1.5.0 Example5716Sat Jan 08 15:08:43 GMT 2005None

ChannelIO

public class ChannelIO extends Object
A helper class for properly sizing inbound byte buffers and redirecting I/O calls to the proper SocketChannel call.

Many of these calls may seem unnecessary until you consider that they are placeholders for the secure variant, which is much more involved. See ChannelIOSecure for more information.

author
Brad R. Wetmore
author
Mark Reinhold
version
1.2, 04/07/26

Fields Summary
protected SocketChannel
sc
protected ByteBuffer
requestBB
private static int
requestBBSize
Constructors Summary
protected ChannelIO(SocketChannel sc, boolean blocking)


        
	      
	this.sc = sc;
	sc.configureBlocking(blocking);
    
Methods Summary
voidclose()

	sc.close();
    
booleandataFlush()

	return true;
    
booleandoHandshake()

	return true;
    
booleandoHandshake(java.nio.channels.SelectionKey sk)

	return true;
    
static ChannelIOgetInstance(java.nio.channels.SocketChannel sc, boolean blocking)

	ChannelIO cio = new ChannelIO(sc, blocking);
	cio.requestBB = ByteBuffer.allocate(requestBBSize);

	return cio;
    
java.nio.ByteBuffergetReadBuf()

	return requestBB;
    
java.nio.channels.SocketChannelgetSocketChannel()

	return sc;
    
intread()

	/*
	 * Allocate more space if less than 5% remains
	 */
	resizeRequestBB(requestBBSize/20);
	return sc.read(requestBB);
    
protected voidresizeRequestBB(int remaining)

	if (requestBB.remaining() < remaining) {
	    // Expand buffer for large request
	    ByteBuffer bb = ByteBuffer.allocate(requestBB.capacity() * 2);
	    requestBB.flip();
	    bb.put(requestBB);
	    requestBB = bb;
	}
    
booleanshutdown()

	return true;
    
longtransferTo(java.nio.channels.FileChannel fc, long pos, long len)

	return fc.transferTo(pos, len, sc);
    
intwrite(java.nio.ByteBuffer src)

	return sc.write(src);