Here you can find the source of toByteBuffer(InputStream inputStream)
public static ByteBuffer toByteBuffer(InputStream inputStream) throws IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; public class Main { public static ByteBuffer toByteBuffer(InputStream inputStream) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int l;/*from ww w.jav a 2s.com*/ while ((l = inputStream.read(buffer)) != -1) { baos.write(buffer, 0, l); } return ByteBuffer.wrap(baos.toByteArray()); } }