code: public InputStream newInputStream() {
          return new InputStream() {
              private int pos = 0;
              public int read() throws IOException {
                  synchronized(ByteBuffer.this) {
                      if(pos>=size)   return -1;
                      return buf[pos++];
                  }
              }
  
              public int read(byte[] b, int off, int len) throws IOException {
                  synchronized(ByteBuffer.this) {
                      if(size==pos)
                          return -1;
  
                      int sz = Math.min(len,size-pos);
                      System.arraycopy(buf,pos,b,off,sz);
                      pos+=sz;
                      return sz;
                  }
              }
  
  
              public int available() throws IOException {
                  synchronized(ByteBuffer.this) {
                      return size-pos;
                  }
              }
  
              public long skip(long n) throws IOException {
                  synchronized(ByteBuffer.this) {
                      int diff = (int) Math.min(n,size-pos);
                      pos+=diff;
                      return diff;
                  }
              }
          };
      }
docs: Creates an {@link InputStream} that reads from the underlying buffer.