Here you can find the source of inputStream(ByteBuffer bytes)
public static InputStream inputStream(ByteBuffer bytes)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; public class Main { public static InputStream inputStream(ByteBuffer bytes) { final ByteBuffer copy = bytes.duplicate(); return new InputStream() { public int read() throws IOException { if (!copy.hasRemaining()) return -1; return copy.get() & 0xFF; }//from w w w . j ava 2 s .c o m @Override public int read(byte[] bytes, int off, int len) throws IOException { if (!copy.hasRemaining()) return -1; len = Math.min(len, copy.remaining()); copy.get(bytes, off, len); return len; } @Override public int available() throws IOException { return copy.remaining(); } }; } }