public static byte[] toBytes(ByteBuffer bb){
  int length=bb.remaining();
  byte[] result=new byte[length];
  System.arraycopy(bb.array(),bb.arrayOffset() + bb.position(),result,0,length);
  return result;
}

public static byte [ ] toBytes ( ByteBuffer bb ) { int length = bb . remaining ( ) ; byte [ ] result = new byte [ length ] ; System . arraycopy ( bb . array ( ) , bb . arrayOffset ( ) + bb . position ( ) , result , 0 , length ) ; return result ; }
returns a new byte array , copied from the passed bytebuffer .
