Added a toByteBuffer method and toArray method to avoid the extra mem copy in trim().