private synchronized long flushBuffer() throws IOException {
  long pos=channel.position();
  int len=(int)buffer.getFilePointer();
  byte[] bytes=new byte[len];
  buffer.writeTo(bytes,0);
  buffer.reset();
  intBuffer[0]=(byte)(len >> 24);
  intBuffer[1]=(byte)(len >> 16);
  intBuffer[2]=(byte)(len >> 8);
  intBuffer[3]=(byte)len;
  intByteBuffer.limit(4);
  intByteBuffer.position(0);
  writeBytesToChannel(intByteBuffer);
  writeBytesToChannel(ByteBuffer.wrap(bytes));
  return pos;
}

private synchronized long flushBuffer ( ) throws IOException { long pos = channel . position ( ) ; int len = ( int ) buffer . getFilePointer ( ) ; byte [ ] bytes = new byte [ len ] ; buffer . writeTo ( bytes , 0 ) ; buffer . reset ( ) ; intBuffer [ 0 ] = ( byte ) ( len > > 24 ) ; intBuffer [ 1 ] = ( byte ) ( len > > 16 ) ; intBuffer [ 2 ] = ( byte ) ( len > > 8 ) ; intBuffer [ 3 ] = ( byte ) len ; intByteBuffer . limit ( 4 ) ; intByteBuffer . position ( 0 ) ; writeBytesToChannel ( intByteBuffer ) ; writeBytesToChannel ( ByteBuffer . wrap ( bytes ) ) ; return pos ; }
writes buffer to the file and returns the start position .
