Added test to ensure all bytes are transferred during backupSessionFile
[vamsas.git] / src / uk / ac / vamsas / client / simpleclient / SessionFile.java
index e2d1db7..aa5e779 100644 (file)
@@ -118,11 +118,23 @@ public class SessionFile {
     if (lockFile(extantLock)) {
       try {
         tempfile = File.createTempFile(backupPrefix, backupSuffix, backupDir);
-        if (fileLock.length()>0) {
+        long sourceln = fileLock.length();
+        if (sourceln>0) {
           FileOutputStream tos = new FileOutputStream(tempfile);
           ReadableByteChannel channel;
-          tos.getChannel().transferFrom(channel=fileLock.getRaChannel(), 0,
-              fileLock.length());
+          channel = fileLock.getRaChannel().position(0);
+          long ntrans = 0;
+          while (ntrans<sourceln)
+          {
+            long tlen;
+            ntrans+= tlen = tos.getChannel().transferFrom(channel, ntrans,
+              sourceln);
+            if (log.isDebugEnabled())
+            {
+              log.debug
+              ("Transferred "+tlen+" out of "+sourceln+" bytes");
+            }
+          }
           tos.close();
           if (!channel.isOpen())
             throw new Error("LIBRARY PORTABILITY ISSUE: "+tos.getChannel().getClass()+".transferFrom closes source channel!");