private void writeBufferToFile ( ) throws IOException { if ( _bufferOffset > 0 ) { List < ByteBuffer > payload = new ArrayList < ByteBuffer > ( 1 ) ; payload . add ( ByteBuffer . wrap ( _buffer , 0 , _bufferOffset ) ) ; NfsWriteResponse response = _nfsFile . write ( _currentOffset , payload , _syncType ) ; int bytesWritten = response . getCount ( ) ; _currentOffset += bytesWritten ; _bufferOffset -= bytesWritten ; if ( 0 != _bufferOffset ) { // Everything was not written. // _bufferOffset should be the number of unwritten bytes. // Copy the unwritten bytes to the beginning of the buffer. System . arraycopy ( _buffer , bytesWritten , _buffer , 0 , _bufferOffset ) ; } } }
Write the buffer contents to the file and reset the buffer afterwards .