+ private static long waitForLastWrite(File file, int i) throws IOException
+ {
+ long lastSize,stableSize =Files.size(file.toPath());
+ // wait around until we are sure the file has been completely written.
+ do {
+ lastSize = stableSize;
+ try {
+ Thread.sleep(i);
+ } catch (Exception x) {}
+ stableSize=Files.size(file.toPath());
+ } while (stableSize!=lastSize);
+ return stableSize;
+ }
+