fixed problem when packet length is greater than buffer size.

also, I rewrote the copying of arrays using the System.arraycopy function. This is not a needed change, but it may be a faster implementation than the for loop.