Skip to content

Commit e0c1ede

Browse files
committed
Switch DownloadChemCompProvider to use NIO for moving
Files.move seems to be more robust than File.renameTo. This fixed a bug on my system.
1 parent 93297eb commit e0c1ede

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/DownloadChemCompProvider.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
import java.io.StringWriter;
3232
import java.net.HttpURLConnection;
3333
import java.net.URL;
34+
import java.nio.file.Files;
35+
import java.nio.file.Paths;
36+
import java.nio.file.StandardCopyOption;
3437
import java.util.ArrayList;
3538
import java.util.List;
3639
import java.util.concurrent.atomic.AtomicBoolean;
@@ -376,16 +379,11 @@ private static boolean downloadChemCompRecord(String recordName) {
376379
}
377380

378381
pw.flush();
379-
// Now we move this across to where it actually wants to be
380-
boolean couldRename = newFile.renameTo(new File(localName));
381-
382-
if (!couldRename) {
383-
384-
throw new IOException("Could not rename temp file "+newFile.toString()+" to file " + localName);
385-
}
386-
387-
return true;
388382
}
383+
// Now we move this across to where it actually wants to be
384+
Files.move(newFile.toPath(), Paths.get(localName), StandardCopyOption.REPLACE_EXISTING);
385+
386+
return true;
389387
} catch (IOException e){
390388
logger.error("Could not download "+url.toString()+" OR store locally to "+localName+" Error ="+e.getMessage());
391389
newFile.delete();

0 commit comments

Comments
 (0)