code: public synchronized int write(int plane, byte data[], int offset, int length) {
  		if (offset < 0 || length < 0 || length > data.length - offset) {
  			throw new IndexOutOfBoundsException();
  		}
  
  		if (bytesToWrite[plane] == 0)
  			return 0;
  
  		if (bytesToWrite[plane] < length)
  			length = bytesToWrite[plane];
  
  		buffer[plane].position(writePointer[plane]);
  		int partLength = buffer[plane].capacity() - writePointer[plane];
  
  		if (partLength > length) {
  			buffer[plane].put(data, offset, length);
  			writePointer[plane] += length;
  		}
  		else {
  			buffer[plane].put(data, offset, partLength);
  			buffer[plane].position(0);
  			buffer[plane].put(data, offset + partLength, length - partLength);
  			writePointer[plane] = length - partLength;
  		}
  
  		bytesToRead[plane] += length;
  		bytesToWrite[plane] -= length;
  
  		return length;
  	}
docs: Write as much data as possible to this buffer.
  
  @param plane  the audio channel.
  @param data   array holding data to be written
  @param offset offset of data in array
  @param length amount of data to write, starting from off.
  
  @return amount of data actually written