posted 21 years ago
ByteBuffers and channels deal only with arrays of bytes, they have no conception of things like ObjectStreams.
Sending a serialized object graph over an NIO channel is no different than sending any other chunk of bytes. You just need to obtain the bytes representing your serialized object and write it to the channel. Here are two ways to do so:
or
In the first case, you've got the encoded object graph in a ByteBuffer instance and could do other things with it if you like. The second uses a utility adapter class which will handle the conversion from stream to channel for you.
Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0596002882/ref=jranch-20" target="_blank" rel="nofollow">Java NIO</a> (<a href="http://javanio.info" target="_blank" rel="nofollow">javanio.info</a>)