Skip to content

Commit ae8cd97

Browse files
committed
Settings migration - use java.nio.file.Files.copy()
1 parent 35ded1c commit ae8cd97

File tree

1 file changed

+5
-31
lines changed
  • visualvm/startup/src/org/graalvm/visualvm/modules/startup

1 file changed

+5
-31
lines changed

visualvm/startup/src/org/graalvm/visualvm/modules/startup/CopyFiles.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import java.io.InputStreamReader;
3535
import java.io.OutputStream;
3636
import java.io.Reader;
37+
import java.nio.file.Files;
38+
import java.nio.file.LinkOption;
3739
import java.util.HashMap;
3840
import java.util.HashSet;
3941
import java.util.Map.Entry;
@@ -47,9 +49,11 @@
4749
import org.openide.util.EditableProperties;
4850

4951
// Copied from org.netbeans.upgrade.CopyFiles
52+
// Modified to not display UI and use java.nio.file.Files.copy()
5053
/** Does copy of files according to include/exclude patterns.
5154
*
5255
* @author Jiri Skrivanek
56+
* @author Jiri Sedlacek
5357
*/
5458
final class CopyFiles extends Object {
5559

@@ -123,39 +127,9 @@ private static String getRelativePath(File root, File file) {
123127
*/
124128
private static void copyFile(File sourceFile, File targetFile) throws IOException {
125129
ensureParent(targetFile);
126-
InputStream ins = null;
127-
OutputStream out = null;
128-
try {
129-
ins = new FileInputStream(sourceFile);
130-
out = new FileOutputStream(targetFile);
131-
copy(ins, out);
132-
} finally {
133-
if (ins != null) {
134-
ins.close();
135-
}
136-
if (out != null) {
137-
out.close();
138-
}
139-
}
130+
Files.copy(sourceFile.toPath(), targetFile.toPath(), LinkOption.NOFOLLOW_LINKS);
140131
}
141132

142-
143-
// --- Copied from org.openide.filesystems.FileUtil ------------------------
144-
private static void copy(InputStream is, OutputStream os) throws IOException {
145-
final byte[] BUFFER = new byte[65536];
146-
int len;
147-
148-
for (;;) {
149-
len = is.read(BUFFER);
150-
151-
if (len == -1) {
152-
return;
153-
}
154-
155-
os.write(BUFFER, 0, len);
156-
}
157-
}
158-
// -------------------------------------------------------------------------
159133

160134
/** Copy given file to target root dir if matches include/exclude patterns.
161135
* If properties pattern is applicable, it copies only matching keys.

0 commit comments

Comments
 (0)