public void write(ByteBuffer buffer) throws IOException {
  buffer.position(0);
  if (mFileChannel.size() + buffer.capacity() < mMaxSize) {
    while (buffer.hasRemaining()) {
      mFileChannel.write(buffer);
    }
    updateWaveFileSize();
  }
 else {
    int remaining=(int)(mMaxSize - mFileChannel.size());
    remaining-=(int)(remaining % mAudioFormat.getFrameSize());
    byte[] bytes=buffer.array();
    ByteBuffer current=ByteBuffer.wrap(Arrays.copyOf(bytes,remaining));
    ByteBuffer next=ByteBuffer.wrap(Arrays.copyOfRange(bytes,remaining,bytes.length));
    while (current.hasRemaining()) {
      mFileChannel.write(current);
    }
    updateWaveFileSize();
    rollover();
    while (next.hasRemaining()) {
      mFileChannel.write(next);
    }
    updateWaveFileSize();
  }
}

public void write ( ByteBuffer buffer ) throws IOException { buffer . position ( 0 ) ; if ( mFileChannel . size ( ) + buffer . capacity ( ) < mMaxSize ) { while ( buffer . hasRemaining ( ) ) { mFileChannel . write ( buffer ) ; } updateWaveFileSize ( ) ; } else { int remaining = ( int ) ( mMaxSize - mFileChannel . size ( ) ) ; remaining -= ( int ) ( remaining % mAudioFormat . getFrameSize ( ) ) ; byte [ ] bytes = buffer . array ( ) ; ByteBuffer current = ByteBuffer . wrap ( Arrays . copyOf ( bytes , remaining ) ) ; ByteBuffer next = ByteBuffer . wrap ( Arrays . copyOfRange ( bytes , remaining , bytes . length ) ) ; while ( current . hasRemaining ( ) ) { mFileChannel . write ( current ) ; } updateWaveFileSize ( ) ; rollover ( ) ; while ( next . hasRemaining ( ) ) { mFileChannel . write ( next ) ; } updateWaveFileSize ( ) ; } }
writes the buffer contents to the file . assumes that the buffer is full and the first byte of data is at position 0 .
