Here you can find the source of newOutputStream(final ByteBuffer buf)
public static OutputStream newOutputStream(final ByteBuffer buf)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.OutputStream; import java.nio.BufferOverflowException; import java.nio.ByteBuffer; public class Main { public static OutputStream newOutputStream(final ByteBuffer buf) { return new OutputStream() { public synchronized void write(int b) throws IOException { try { buf.put((byte) b); } catch (BufferOverflowException e) { throw new IOException(e); }//w ww. j av a2s .c om } public synchronized void write(byte[] bytes, int off, int len) throws IOException { try { buf.put(bytes, off, len); } catch (BufferOverflowException e) { throw new IOException(e); } } }; } }