Java examples for java.nio:ByteBuffer Stream
ByteBuffer from Input Stream
import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.util.logging.Level; import java.util.logging.Logger; public class Main{ static public ByteBuffer fromInputStream(InputStream strm) { try {/* ww w. j a v a 2 s . com*/ byte[] bytes = new byte[strm.available()]; strm.read(bytes); return ByteBuffer.wrap(bytes); } catch (IOException ex) { Logger.getLogger(ByteBufferUtils.class.getName()).log( Level.SEVERE, null, ex); } return null; } }