Here you can find the source of streamRead(SocketChannel in)
public static byte[] streamRead(SocketChannel in) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; public class Main { public static byte[] streamRead(InputStream in) throws IOException { byte buf[] = new byte[4096]; int len = in.read(buf); if (len == -1) return null; byte ret[] = new byte[len]; System.arraycopy(buf, 0, ret, 0, len); return (ret); }/*from w ww .j a v a 2 s. co m*/ public static byte[] streamRead(SocketChannel in) throws IOException { ByteBuffer buf = ByteBuffer.allocate(4096); //byte buf[] = new byte[4096]; int len = in.read(buf); if (len == -1) return null; byte ret[] = new byte[len]; buf.get(ret); //System.arraycopy(buf, 0, ret, 0, len); return (ret); } }