private void sendLargeFile(AbstractJournalStorageManager.JournalContent content,SimpleString pageStore,final long id,SequentialFile file,long maxBytesToSend) throws Exception {
  if (!enabled)   return;
  if (!file.isOpen()) {
    file.open();
  }
  try {
    try (final FileInputStream fis=new FileInputStream(file.getJavaFile());final FileChannel channel=fis.getChannel()){
      final ByteBuffer buffer=ByteBuffer.allocate(1 << 17);
      while (true) {
        buffer.clear();
        final int bytesRead=channel.read(buffer);
        int toSend=bytesRead;
        if (bytesRead > 0) {
          if (bytesRead >= maxBytesToSend) {
            toSend=(int)maxBytesToSend;
            maxBytesToSend=0;
          }
 else {
            maxBytesToSend=maxBytesToSend - bytesRead;
          }
          buffer.limit(toSend);
        }
        buffer.rewind();
        sendReplicatePacket(new ReplicationSyncFileMessage(content,pageStore,id,toSend,buffer));
        if (bytesRead == -1 || bytesRead == 0 || maxBytesToSend == 0)         break;
      }
    }
   }
  finally {
    if (file.isOpen())     file.close();
  }
}

private void sendLargeFile ( AbstractJournalStorageManager . JournalContent content , SimpleString pageStore , final long id , SequentialFile file , long maxBytesToSend ) throws Exception { if ( ! enabled ) return ; if ( ! file . isOpen ( ) ) { file . open ( ) ; } try { try ( final FileInputStream fis = new FileInputStream ( file . getJavaFile ( ) ) ; final FileChannel channel = fis . getChannel ( ) ) { final ByteBuffer buffer = ByteBuffer . allocate ( 1 << 17 ) ; while ( true ) { buffer . clear ( ) ; final int bytesRead = channel . read ( buffer ) ; int toSend = bytesRead ; if ( bytesRead > 0 ) { if ( bytesRead >= maxBytesToSend ) { toSend = ( int ) maxBytesToSend ; maxBytesToSend = 0 ; } else { maxBytesToSend = maxBytesToSend - bytesRead ; } buffer . limit ( toSend ) ; } buffer . rewind ( ) ; sendReplicatePacket ( new ReplicationSyncFileMessage ( content , pageStore , id , toSend , buffer ) ) ; if ( bytesRead == - 1 || bytesRead == 0 || maxBytesToSend == 0 ) break ; } } } finally { if ( file . isOpen ( ) ) file . close ( ) ; } }
sends large files in reasonably sized chunks to the backup during replication synchronization .
