// Creating a ByteBuffer out from scratch

ByteBuffer bb = ByteBuffer.allocate( 10000  /* max capacity */ );

bb.put( (byte) 0xff );

bb.put( anArrayOfBytes );

// finished writing, now flip over to reading
bb.flip();

int limit = bb.limit();  // how many chars in buffer

byte b = bb.get(); // read first byte