end should never be greater than buffer.length, since end correspondes to the number of bytes read to that buffer.
also end is set to 0 just before this.