class NIO::ByteBuffer

def compact

Sets the position to the end of the moved data, and the limit to the capacity
Move data between the position and limit to the beginning of the buffer
def compact
  @buffer[0...(@limit - @position)] = @buffer[@position...@limit]
  @position = @limit - @position
  @limit = capacity
  self
end