code: public int readPacket(@NonNull byte[] buffer) throws IOException {
  		int i = 0;
  		while (i < buffer.length) {
  			if (localPos < size) {
  				buffer[i++] = localBuf[localPos++];
  				continue;
  			}
  
  			bytesRead += size = readLine();
  			if (size == 0)
  				break; // end of file reached
  		}
  		return i;
  	}
docs: Fills the buffer with next bytes from the stream.
  
  @param buffer buffer to be filled
  @return the size of the buffer