mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
6980847: (fs) Files.copy needs to be "tuned"
Reviewed-by: alanb
This commit is contained in:
parent
d579916a6b
commit
b8db0c383b
4 changed files with 176 additions and 32 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -132,6 +132,7 @@ class WindowsConstants {
|
|||
// copy flags
|
||||
public static final int COPY_FILE_FAIL_IF_EXISTS = 0x00000001;
|
||||
public static final int COPY_FILE_COPY_SYMLINK = 0x00000800;
|
||||
public static final int COPY_FILE_NO_BUFFERING = 0x00001000;
|
||||
|
||||
// move flags
|
||||
public static final int MOVEFILE_REPLACE_EXISTING = 0x00000001;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -25,8 +25,14 @@
|
|||
|
||||
package sun.nio.fs;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.AtomicMoveNotSupportedException;
|
||||
import java.nio.file.CopyOption;
|
||||
import java.nio.file.DirectoryNotEmptyException;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.LinkPermission;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static sun.nio.fs.WindowsNativeDispatcher.*;
|
||||
|
@ -37,6 +43,9 @@ import static sun.nio.fs.WindowsConstants.*;
|
|||
*/
|
||||
|
||||
class WindowsFileCopy {
|
||||
// file size above which copying uses unbuffered I/O
|
||||
private static final long UNBUFFERED_IO_THRESHOLD = 314572800; // 300 MiB
|
||||
|
||||
private WindowsFileCopy() {
|
||||
}
|
||||
|
||||
|
@ -174,7 +183,9 @@ class WindowsFileCopy {
|
|||
|
||||
// Use CopyFileEx if the file is not a directory or junction
|
||||
if (!sourceAttrs.isDirectory() && !sourceAttrs.isDirectoryLink()) {
|
||||
final int flags = (!followLinks) ? COPY_FILE_COPY_SYMLINK : 0;
|
||||
boolean isBuffering = sourceAttrs.size() <= UNBUFFERED_IO_THRESHOLD;
|
||||
final int flags = (followLinks ? 0 : COPY_FILE_COPY_SYMLINK) |
|
||||
(isBuffering ? 0 : COPY_FILE_NO_BUFFERING);
|
||||
|
||||
if (interruptible) {
|
||||
// interruptible copy
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue