Here you can find the source of copyToStream(ByteBuffer byteBuffer, OutputStream os)
public static void copyToStream(ByteBuffer byteBuffer, OutputStream os) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; public class Main { public static void copyToStream(ByteBuffer byteBuffer, OutputStream os) throws IOException { byte[] buffer = new byte[32768]; while (true) { int byteCount = Math.min(byteBuffer.remaining(), buffer.length); if (byteCount == 0) { break; }// www.j a va2 s. c o m byteBuffer.get(buffer, 0, byteCount); os.write(buffer, 0, byteCount); } } }