]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/io/FileIO.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.scl.runtime / src / org / simantics / scl / runtime / io / FileIO.java
1 package org.simantics.scl.runtime.io;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.io.RandomAccessFile;
6 import java.nio.file.Files;
7 import java.nio.file.StandardCopyOption;
8
9 public class FileIO {
10
11         public static void moveFile(File source, File target) throws IOException {
12                 Files.move(source.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);
13         }
14         
15     public static void copyFile(File source, File target) throws IOException {
16                 Files.copy(source.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);
17     }
18
19     public static void syncFile(File file) throws IOException {
20         try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
21                         raf.getFD().sync();
22                 }
23     }
24     
25     public static File createTempDirectory(String prefix, File parent) throws IOException {
26         if (parent != null) {
27                 return Files.createTempDirectory(parent.toPath(), prefix).toFile();
28         } else {
29                 return Files.createTempDirectory(prefix).toFile();
30         }
31     }
32 }