Java examples for java.nio.channels:SocketChannel
read SocketChannel and return Object
import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; public class Main{ /* w ww . j a v a 2 s . c o m*/ public static Object read(SocketChannel channel) { try { ByteBuffer buffer = ByteBuffer.allocate(102400); channel.read(buffer); buffer.flip(); byte[] data = buffer.array(); return ByteUtil.getObject(data); } catch (Exception e) { e.printStackTrace(); } return null; } }