Here you can find the source of writeOutputStream(OutputStream output, ByteBuffer data)
public static void writeOutputStream(OutputStream output, ByteBuffer data) 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 final int BUFFER_SIZE = 16384; public static void writeOutputStream(OutputStream output, ByteBuffer data) throws IOException { byte[] buf = new byte[BUFFER_SIZE]; for (;;) { int rem = data.remaining(); if (rem == 0) break; if (rem > buf.length) rem = buf.length;//w ww . j a v a 2 s. c o m data.get(buf, 0, rem); output.write(buf, 0, rem); } } }