greenstone.org greenstone wiki greenstone trac planet greenstone

Ticket #214 (new defect)

Opened 11 months ago

test java.nio as as alternative file copy mechanism

Reported by: anonymous Assigned to: nobody
Priority: moderate Milestone:
Component: Collection Building Severity:
Keywords: Cc:

Description

public void copyFile(File source, File destination, boolean overwrite)

in FileQueue?.java

uses a buffer to copy files.

We should test whether this solution is quicker (it is probably more likely to be correct as well):

http://www.javalobby.org/java/forums/t17036.html

public static void copyFile(File sourceFile, File destFile) throws IOException {
 if(!destFile.exists()) {
  destFile.createNewFile();
 }
 
 FileChannel source = null;
 FileChannel destination = null;
 try {
  source = new FileInputStream(sourceFile).getChannel();
  destination = new FileOutputStream(destFile).getChannel();
  destination.transferFrom(source, 0, source.size());
 }
 finally {
  if(source != null) {
   source.close();
  }
  if(destination != null) {
   destination.close();
  }
}