author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 45467 | jdk/test/java/nio/file/Files/CopyAndMove.java@99c87a16a8e4 |
child 50447 | 3111982511ee |
permissions | -rw-r--r-- |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1 |
/* |
45288
58be10a068c2
8180805: move RandomFactory to the top level testlibrary
iignatyev
parents:
31245
diff
changeset
|
2 |
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
4 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
8 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
13 |
* accompanied this code). |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
14 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
18 |
* |
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
22 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
23 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
24 |
/* @test |
16048
e8891a5d639f
8006645: TEST_BUG: java/nio/file/Files/CopyAndMove.java failing intermittently (sol)
dxu
parents:
14011
diff
changeset
|
25 |
* @bug 4313887 6838333 6917021 7006126 6950237 8006645 |
31245
898c2ccf13d0
8081293: java/nio/file/Files/CopyAndMove.java failed with java.nio.file.FileAlreadyExistsException intermittently
bpb
parents:
30046
diff
changeset
|
26 |
* @summary Unit test for java.nio.file.Files copy and move methods (use -Dseed=X to set PRNG seed) |
45288
58be10a068c2
8180805: move RandomFactory to the top level testlibrary
iignatyev
parents:
31245
diff
changeset
|
27 |
* @library .. /test/lib |
45467
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45288
diff
changeset
|
28 |
* @build jdk.test.lib.RandomFactory |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45288
diff
changeset
|
29 |
* CopyAndMove PassThroughFileSystem |
4234
d9720475ab15
6900234: Several NIO tests should be removed from test/ProblemList.txt
alanb
parents:
4057
diff
changeset
|
30 |
* @run main/othervm CopyAndMove |
30046 | 31 |
* @key randomness |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
32 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
33 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
34 |
import java.nio.ByteBuffer; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
35 |
import java.nio.file.*; |
8158 | 36 |
import static java.nio.file.Files.*; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
37 |
import static java.nio.file.StandardCopyOption.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
38 |
import static java.nio.file.LinkOption.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
39 |
import java.nio.file.attribute.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
40 |
import java.io.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
41 |
import java.util.*; |
16048
e8891a5d639f
8006645: TEST_BUG: java/nio/file/Files/CopyAndMove.java failing intermittently (sol)
dxu
parents:
14011
diff
changeset
|
42 |
import java.util.concurrent.TimeUnit; |
45288
58be10a068c2
8180805: move RandomFactory to the top level testlibrary
iignatyev
parents:
31245
diff
changeset
|
43 |
import jdk.test.lib.RandomFactory; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
44 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
45 |
public class CopyAndMove { |
31245
898c2ccf13d0
8081293: java/nio/file/Files/CopyAndMove.java failed with java.nio.file.FileAlreadyExistsException intermittently
bpb
parents:
30046
diff
changeset
|
46 |
static final Random rand = RandomFactory.getRandom(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
47 |
static boolean heads() { return rand.nextBoolean(); } |
14011
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
48 |
private static boolean testPosixAttributes = false; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
49 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
50 |
public static void main(String[] args) throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
51 |
Path dir1 = TestUtil.createTemporaryDirectory(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
52 |
try { |
8158 | 53 |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
54 |
// Same directory |
14011
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
55 |
testPosixAttributes = getFileStore(dir1).supportsFileAttributeView("posix"); |
8158 | 56 |
testCopyFileToFile(dir1, dir1, TestUtil.supportsLinks(dir1)); |
57 |
testMove(dir1, dir1, TestUtil.supportsLinks(dir1)); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
58 |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
59 |
// Different directories. Use test.dir if possible as it might be |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
60 |
// a different volume/file system and so improve test coverage. |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
61 |
String testDir = System.getProperty("test.dir", "."); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
62 |
Path dir2 = TestUtil.createTemporaryDirectory(testDir); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
63 |
try { |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
64 |
boolean testSymbolicLinks = |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
65 |
TestUtil.supportsLinks(dir1) && TestUtil.supportsLinks(dir2); |
14011
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
66 |
testPosixAttributes = getFileStore(dir1).supportsFileAttributeView("posix") && |
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
67 |
getFileStore(dir2).supportsFileAttributeView("posix"); |
8158 | 68 |
testCopyFileToFile(dir1, dir2, testSymbolicLinks); |
69 |
testMove(dir1, dir2, testSymbolicLinks); |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
70 |
} finally { |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
71 |
TestUtil.removeAll(dir2); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
72 |
} |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
73 |
|
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
74 |
// Target is location associated with custom provider |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
75 |
Path dir3 = PassThroughFileSystem.create().getPath(dir1.toString()); |
14011
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
76 |
testPosixAttributes = getFileStore(dir1).supportsFileAttributeView("posix") && |
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
77 |
getFileStore(dir3).supportsFileAttributeView("posix"); |
8158 | 78 |
testCopyFileToFile(dir1, dir3, false); |
79 |
testMove(dir1, dir3, false); |
|
80 |
||
81 |
// Test copy(InputStream,Path) and copy(Path,OutputStream) |
|
82 |
testCopyInputStreamToFile(); |
|
83 |
testCopyFileToOuputStream(); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
84 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
85 |
} finally { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
86 |
TestUtil.removeAll(dir1); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
87 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
88 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
89 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
90 |
static void checkBasicAttributes(BasicFileAttributes attrs1, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
91 |
BasicFileAttributes attrs2) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
92 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
93 |
// check file type |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
94 |
assertTrue(attrs1.isRegularFile() == attrs2.isRegularFile()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
95 |
assertTrue(attrs1.isDirectory() == attrs2.isDirectory()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
96 |
assertTrue(attrs1.isSymbolicLink() == attrs2.isSymbolicLink()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
97 |
assertTrue(attrs1.isOther() == attrs2.isOther()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
98 |
|
13667
a7901d690bde
7033824: TEST_BUG: java/nio/file/Files/CopyAndMove.java fails intermittently
alanb
parents:
12047
diff
changeset
|
99 |
// check last modified time if not a symbolic link |
a7901d690bde
7033824: TEST_BUG: java/nio/file/Files/CopyAndMove.java fails intermittently
alanb
parents:
12047
diff
changeset
|
100 |
if (!attrs1.isSymbolicLink()) { |
16048
e8891a5d639f
8006645: TEST_BUG: java/nio/file/Files/CopyAndMove.java failing intermittently (sol)
dxu
parents:
14011
diff
changeset
|
101 |
long time1 = attrs1.lastModifiedTime().to(TimeUnit.SECONDS); |
e8891a5d639f
8006645: TEST_BUG: java/nio/file/Files/CopyAndMove.java failing intermittently (sol)
dxu
parents:
14011
diff
changeset
|
102 |
long time2 = attrs2.lastModifiedTime().to(TimeUnit.SECONDS); |
14011
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
103 |
|
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
104 |
if (time1 != time2) { |
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
105 |
System.err.format("File time for %s is %s\n", attrs1.fileKey(), attrs1.lastModifiedTime()); |
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
106 |
System.err.format("File time for %s is %s\n", attrs2.fileKey(), attrs2.lastModifiedTime()); |
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
107 |
assertTrue(false); |
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
108 |
} |
13667
a7901d690bde
7033824: TEST_BUG: java/nio/file/Files/CopyAndMove.java fails intermittently
alanb
parents:
12047
diff
changeset
|
109 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
110 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
111 |
// check size |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
112 |
if (attrs1.isRegularFile()) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
113 |
assertTrue(attrs1.size() == attrs2.size()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
114 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
115 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
116 |
static void checkPosixAttributes(PosixFileAttributes attrs1, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
117 |
PosixFileAttributes attrs2) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
118 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
119 |
assertTrue(attrs1.permissions().equals(attrs2.permissions())); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
120 |
assertTrue(attrs1.owner().equals(attrs2.owner())); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
121 |
assertTrue(attrs1.group().equals(attrs2.group())); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
122 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
123 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
124 |
static void checkDosAttributes(DosFileAttributes attrs1, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
125 |
DosFileAttributes attrs2) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
126 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
127 |
assertTrue(attrs1.isReadOnly() == attrs2.isReadOnly()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
128 |
assertTrue(attrs1.isHidden() == attrs2.isHidden()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
129 |
assertTrue(attrs1.isSystem() == attrs2.isSystem()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
130 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
131 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
132 |
static void checkUserDefinedFileAttributes(Map<String,ByteBuffer> attrs1, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
133 |
Map<String,ByteBuffer> attrs2) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
134 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
135 |
assert attrs1.size() == attrs2.size(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
136 |
for (String name: attrs1.keySet()) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
137 |
ByteBuffer bb1 = attrs1.get(name); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
138 |
ByteBuffer bb2 = attrs2.get(name); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
139 |
assertTrue(bb2 != null); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
140 |
assertTrue(bb1.equals(bb2)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
141 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
142 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
143 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
144 |
static Map<String,ByteBuffer> readUserDefinedFileAttributes(Path file) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
145 |
throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
146 |
{ |
8158 | 147 |
UserDefinedFileAttributeView view = |
148 |
getFileAttributeView(file, UserDefinedFileAttributeView.class); |
|
149 |
Map<String,ByteBuffer> result = new HashMap<>(); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
150 |
for (String name: view.list()) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
151 |
int size = view.size(name); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
152 |
ByteBuffer bb = ByteBuffer.allocate(size); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
153 |
int n = view.read(name, bb); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
154 |
assertTrue(n == size); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
155 |
bb.flip(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
156 |
result.put(name, bb); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
157 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
158 |
return result; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
159 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
160 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
161 |
// move source to target with verification |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
162 |
static void moveAndVerify(Path source, Path target, CopyOption... options) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
163 |
throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
164 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
165 |
// read attributes before file is moved |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
166 |
BasicFileAttributes basicAttributes = null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
167 |
PosixFileAttributes posixAttributes = null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
168 |
DosFileAttributes dosAttributes = null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
169 |
Map<String,ByteBuffer> namedAttributes = null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
170 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
171 |
// get file attributes of source file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
172 |
String os = System.getProperty("os.name"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
173 |
if (os.startsWith("Windows")) { |
8158 | 174 |
dosAttributes = readAttributes(source, DosFileAttributes.class, NOFOLLOW_LINKS); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
175 |
basicAttributes = dosAttributes; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
176 |
} else { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
177 |
posixAttributes = readAttributes(source, PosixFileAttributes.class, NOFOLLOW_LINKS); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
178 |
basicAttributes = posixAttributes; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
179 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
180 |
if (basicAttributes == null) |
8158 | 181 |
basicAttributes = readAttributes(source, BasicFileAttributes.class, NOFOLLOW_LINKS); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
182 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
183 |
// hash file contents if regular file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
184 |
int hash = (basicAttributes.isRegularFile()) ? computeHash(source) : 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
185 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
186 |
// record link target if symbolic link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
187 |
Path linkTarget = null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
188 |
if (basicAttributes.isSymbolicLink()) |
8158 | 189 |
linkTarget = readSymbolicLink(source); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
190 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
191 |
// read named attributes if available (and file is not a sym link) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
192 |
if (!basicAttributes.isSymbolicLink() && |
8158 | 193 |
getFileStore(source).supportsFileAttributeView("xattr")) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
194 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
195 |
namedAttributes = readUserDefinedFileAttributes(source); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
196 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
197 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
198 |
// move file |
8158 | 199 |
Path result = move(source, target, options); |
200 |
assertTrue(result == target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
201 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
202 |
// verify source does not exist |
8158 | 203 |
assertTrue(notExists(source)); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
204 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
205 |
// verify file contents |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
206 |
if (basicAttributes.isRegularFile()) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
207 |
if (computeHash(target) != hash) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
208 |
throw new RuntimeException("Failed to verify move of regular file"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
209 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
210 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
211 |
// verify link target |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
212 |
if (basicAttributes.isSymbolicLink()) { |
8158 | 213 |
if (!readSymbolicLink(target).equals(linkTarget)) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
214 |
throw new RuntimeException("Failed to verify move of symbolic link"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
215 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
216 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
217 |
// verify basic attributes |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
218 |
checkBasicAttributes(basicAttributes, |
8158 | 219 |
readAttributes(target, BasicFileAttributes.class, NOFOLLOW_LINKS)); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
220 |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
221 |
// verify other attributes when same provider |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
222 |
if (source.getFileSystem().provider() == target.getFileSystem().provider()) { |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
223 |
|
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
224 |
// verify POSIX attributes |
14011
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
225 |
if (posixAttributes != null && |
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
226 |
!basicAttributes.isSymbolicLink() && |
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
227 |
testPosixAttributes) |
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
228 |
{ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
229 |
checkPosixAttributes(posixAttributes, |
8158 | 230 |
readAttributes(target, PosixFileAttributes.class, NOFOLLOW_LINKS)); |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
231 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
232 |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
233 |
// verify DOS attributes |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
234 |
if (dosAttributes != null && !basicAttributes.isSymbolicLink()) { |
8158 | 235 |
DosFileAttributes attrs = |
236 |
readAttributes(target, DosFileAttributes.class, NOFOLLOW_LINKS); |
|
237 |
checkDosAttributes(dosAttributes, attrs); |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
238 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
239 |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
240 |
// verify named attributes |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
241 |
if (namedAttributes != null && |
8158 | 242 |
getFileStore(target).supportsFileAttributeView("xattr")) |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
243 |
{ |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
244 |
checkUserDefinedFileAttributes(namedAttributes, |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
245 |
readUserDefinedFileAttributes(target)); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
246 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
247 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
248 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
249 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
250 |
/** |
8158 | 251 |
* Tests all possible ways to invoke move |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
252 |
*/ |
8158 | 253 |
static void testMove(Path dir1, Path dir2, boolean supportsLinks) |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
254 |
throws IOException |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
255 |
{ |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
256 |
Path source, target, entry; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
257 |
|
8158 | 258 |
boolean sameDevice = getFileStore(dir1).equals(getFileStore(dir2)); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
259 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
260 |
// -- regular file -- |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
261 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
262 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
263 |
* Test: move regular file, target does not exist |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
264 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
265 |
source = createSourceFile(dir1); |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
266 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
267 |
moveAndVerify(source, target); |
8158 | 268 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
269 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
270 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
271 |
* Test: move regular file, target exists |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
272 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
273 |
source = createSourceFile(dir1); |
8158 | 274 |
target = getTargetFile(dir2); |
275 |
createFile(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
276 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
277 |
moveAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
278 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
279 |
} catch (FileAlreadyExistsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
280 |
} |
8158 | 281 |
delete(target); |
282 |
createDirectory(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
283 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
284 |
moveAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
285 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
286 |
} catch (FileAlreadyExistsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
287 |
} |
8158 | 288 |
delete(source); |
289 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
290 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
291 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
292 |
* Test: move regular file, target does not exist |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
293 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
294 |
source = createSourceFile(dir1); |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
295 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
296 |
moveAndVerify(source, target, REPLACE_EXISTING); |
8158 | 297 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
298 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
299 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
300 |
* Test: move regular file, target exists |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
301 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
302 |
source = createSourceFile(dir1); |
8158 | 303 |
target = getTargetFile(dir2); |
304 |
createFile(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
305 |
moveAndVerify(source, target, REPLACE_EXISTING); |
8158 | 306 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
307 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
308 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
309 |
* Test: move regular file, target exists and is empty directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
310 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
311 |
source = createSourceFile(dir1); |
8158 | 312 |
target = getTargetFile(dir2); |
313 |
createDirectory(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
314 |
moveAndVerify(source, target, REPLACE_EXISTING); |
8158 | 315 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
316 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
317 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
318 |
* Test: move regular file, target exists and is non-empty directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
319 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
320 |
source = createSourceFile(dir1); |
8158 | 321 |
target = getTargetFile(dir2); |
322 |
createDirectory(target); |
|
323 |
entry = target.resolve("foo"); |
|
324 |
createFile(entry); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
325 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
326 |
moveAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
327 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
328 |
} catch (FileAlreadyExistsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
329 |
} |
8158 | 330 |
delete(entry); |
331 |
delete(source); |
|
332 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
333 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
334 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
335 |
* Test atomic move of regular file (same file store) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
336 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
337 |
source = createSourceFile(dir1); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
338 |
target = getTargetFile(dir1); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
339 |
moveAndVerify(source, target, ATOMIC_MOVE); |
8158 | 340 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
341 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
342 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
343 |
* Test atomic move of regular file (different file store) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
344 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
345 |
if (!sameDevice) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
346 |
source = createSourceFile(dir1); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
347 |
target = getTargetFile(dir2); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
348 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
349 |
moveAndVerify(source, target, ATOMIC_MOVE); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
350 |
throw new RuntimeException("AtomicMoveNotSupportedException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
351 |
} catch (AtomicMoveNotSupportedException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
352 |
} |
8158 | 353 |
delete(source); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
354 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
355 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
356 |
// -- directories -- |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
357 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
358 |
/* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
359 |
* Test: move empty directory, target does not exist |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
360 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
361 |
source = createSourceDirectory(dir1); |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
362 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
363 |
moveAndVerify(source, target); |
8158 | 364 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
365 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
366 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
367 |
* Test: move empty directory, target exists |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
368 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
369 |
source = createSourceDirectory(dir1); |
8158 | 370 |
target = getTargetFile(dir2); |
371 |
createFile(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
372 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
373 |
moveAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
374 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
375 |
} catch (FileAlreadyExistsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
376 |
} |
8158 | 377 |
delete(target); |
378 |
createDirectory(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
379 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
380 |
moveAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
381 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
382 |
} catch (FileAlreadyExistsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
383 |
} |
8158 | 384 |
delete(source); |
385 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
386 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
387 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
388 |
* Test: move empty directory, target does not exist |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
389 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
390 |
source = createSourceDirectory(dir1); |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
391 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
392 |
moveAndVerify(source, target, REPLACE_EXISTING); |
8158 | 393 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
394 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
395 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
396 |
* Test: move empty directory, target exists |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
397 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
398 |
source = createSourceDirectory(dir1); |
8158 | 399 |
target = getTargetFile(dir2); |
400 |
createFile(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
401 |
moveAndVerify(source, target, REPLACE_EXISTING); |
8158 | 402 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
403 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
404 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
405 |
* Test: move empty, target exists and is empty directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
406 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
407 |
source = createSourceDirectory(dir1); |
8158 | 408 |
target = getTargetFile(dir2); |
409 |
createDirectory(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
410 |
moveAndVerify(source, target, REPLACE_EXISTING); |
8158 | 411 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
412 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
413 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
414 |
* Test: move empty directory, target exists and is non-empty directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
415 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
416 |
source = createSourceDirectory(dir1); |
8158 | 417 |
target = getTargetFile(dir2); |
418 |
createDirectory(target); |
|
419 |
entry = target.resolve("foo"); |
|
420 |
createFile(entry); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
421 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
422 |
moveAndVerify(source, target, REPLACE_EXISTING); |
8158 | 423 |
throw new RuntimeException("DirectoryNotEmptyException expected"); |
424 |
} catch (DirectoryNotEmptyException x) { |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
425 |
} |
8158 | 426 |
delete(entry); |
427 |
delete(source); |
|
428 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
429 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
430 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
431 |
* Test: move non-empty directory (same file system) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
432 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
433 |
source = createSourceDirectory(dir1); |
8158 | 434 |
createFile(source.resolve("foo")); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
435 |
target = getTargetFile(dir1); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
436 |
moveAndVerify(source, target); |
8158 | 437 |
delete(target.resolve("foo")); |
438 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
439 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
440 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
441 |
* Test: move non-empty directory (different file store) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
442 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
443 |
if (!sameDevice) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
444 |
source = createSourceDirectory(dir1); |
8158 | 445 |
createFile(source.resolve("foo")); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
446 |
target = getTargetFile(dir2); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
447 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
448 |
moveAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
449 |
throw new RuntimeException("IOException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
450 |
} catch (IOException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
451 |
} |
8158 | 452 |
delete(source.resolve("foo")); |
453 |
delete(source); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
454 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
455 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
456 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
457 |
* Test atomic move of directory (same file store) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
458 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
459 |
source = createSourceDirectory(dir1); |
8158 | 460 |
createFile(source.resolve("foo")); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
461 |
target = getTargetFile(dir1); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
462 |
moveAndVerify(source, target, ATOMIC_MOVE); |
8158 | 463 |
delete(target.resolve("foo")); |
464 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
465 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
466 |
// -- symbolic links -- |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
467 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
468 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
469 |
* Test: Move symbolic link to file, target does not exist |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
470 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
471 |
if (supportsLinks) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
472 |
Path tmp = createSourceFile(dir1); |
8158 | 473 |
source = dir1.resolve("link"); |
474 |
createSymbolicLink(source, tmp); |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
475 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
476 |
moveAndVerify(source, target); |
8158 | 477 |
delete(target); |
478 |
delete(tmp); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
479 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
480 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
481 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
482 |
* Test: Move symbolic link to directory, target does not exist |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
483 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
484 |
if (supportsLinks) { |
8158 | 485 |
source = dir1.resolve("link"); |
486 |
createSymbolicLink(source, dir2); |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
487 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
488 |
moveAndVerify(source, target); |
8158 | 489 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
490 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
491 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
492 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
493 |
* Test: Move broken symbolic link, target does not exists |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
494 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
495 |
if (supportsLinks) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
496 |
Path tmp = Paths.get("doesnotexist"); |
8158 | 497 |
source = dir1.resolve("link"); |
498 |
createSymbolicLink(source, tmp); |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
499 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
500 |
moveAndVerify(source, target); |
8158 | 501 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
502 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
503 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
504 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
505 |
* Test: Move symbolic link, target exists |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
506 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
507 |
if (supportsLinks) { |
8158 | 508 |
source = dir1.resolve("link"); |
509 |
createSymbolicLink(source, dir2); |
|
510 |
target = getTargetFile(dir2); |
|
511 |
createFile(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
512 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
513 |
moveAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
514 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
515 |
} catch (FileAlreadyExistsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
516 |
} |
8158 | 517 |
delete(source); |
518 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
519 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
520 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
521 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
522 |
* Test: Move regular file, target exists |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
523 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
524 |
if (supportsLinks) { |
8158 | 525 |
source = dir1.resolve("link"); |
526 |
createSymbolicLink(source, dir2); |
|
527 |
target = getTargetFile(dir2); |
|
528 |
createFile(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
529 |
moveAndVerify(source, target, REPLACE_EXISTING); |
8158 | 530 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
531 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
532 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
533 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
534 |
* Test: move symbolic link, target exists and is empty directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
535 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
536 |
if (supportsLinks) { |
8158 | 537 |
source = dir1.resolve("link"); |
538 |
createSymbolicLink(source, dir2); |
|
539 |
target = getTargetFile(dir2); |
|
540 |
createDirectory(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
541 |
moveAndVerify(source, target, REPLACE_EXISTING); |
8158 | 542 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
543 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
544 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
545 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
546 |
* Test: symbolic link, target exists and is non-empty directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
547 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
548 |
if (supportsLinks) { |
8158 | 549 |
source = dir1.resolve("link"); |
550 |
createSymbolicLink(source, dir2); |
|
551 |
target = getTargetFile(dir2); |
|
552 |
createDirectory(target); |
|
553 |
entry = target.resolve("foo"); |
|
554 |
createFile(entry); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
555 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
556 |
moveAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
557 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
558 |
} catch (FileAlreadyExistsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
559 |
} |
8158 | 560 |
delete(entry); |
561 |
delete(source); |
|
562 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
563 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
564 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
565 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
566 |
* Test atomic move of symbolic link (same file store) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
567 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
568 |
if (supportsLinks) { |
8158 | 569 |
source = dir1.resolve("link"); |
570 |
createSymbolicLink(source, dir1); |
|
571 |
target = getTargetFile(dir2); |
|
572 |
createFile(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
573 |
moveAndVerify(source, target, REPLACE_EXISTING); |
8158 | 574 |
delete(target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
575 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
576 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
577 |
// -- misc. tests -- |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
578 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
579 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
580 |
* Test nulls |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
581 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
582 |
source = createSourceFile(dir1); |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
583 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
584 |
try { |
8158 | 585 |
move(null, target); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
586 |
throw new RuntimeException("NullPointerException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
587 |
} catch (NullPointerException x) { } |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
588 |
try { |
8158 | 589 |
move(source, null); |
590 |
throw new RuntimeException("NullPointerException expected"); |
|
591 |
} catch (NullPointerException x) { } |
|
592 |
try { |
|
593 |
move(source, target, (CopyOption[])null); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
594 |
throw new RuntimeException("NullPointerException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
595 |
} catch (NullPointerException x) { } |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
596 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
597 |
CopyOption[] opts = { REPLACE_EXISTING, null }; |
8158 | 598 |
move(source, target, opts); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
599 |
throw new RuntimeException("NullPointerException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
600 |
} catch (NullPointerException x) { } |
8158 | 601 |
delete(source); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
602 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
603 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
604 |
* Test UOE |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
605 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
606 |
source = createSourceFile(dir1); |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
607 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
608 |
try { |
8158 | 609 |
move(source, target, new CopyOption() { }); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
610 |
} catch (UnsupportedOperationException x) { } |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
611 |
try { |
8158 | 612 |
move(source, target, REPLACE_EXISTING, new CopyOption() { }); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
613 |
} catch (UnsupportedOperationException x) { } |
8158 | 614 |
delete(source); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
615 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
616 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
617 |
// copy source to target with verification |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
618 |
static void copyAndVerify(Path source, Path target, CopyOption... options) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
619 |
throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
620 |
{ |
8158 | 621 |
Path result = copy(source, target, options); |
622 |
assertTrue(result == target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
623 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
624 |
// get attributes of source and target file to verify copy |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
625 |
boolean followLinks = true; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
626 |
LinkOption[] linkOptions = new LinkOption[0]; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
627 |
boolean copyAttributes = false; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
628 |
for (CopyOption opt : options) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
629 |
if (opt == NOFOLLOW_LINKS) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
630 |
followLinks = false; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
631 |
linkOptions = new LinkOption[] { NOFOLLOW_LINKS }; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
632 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
633 |
if (opt == COPY_ATTRIBUTES) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
634 |
copyAttributes = true; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
635 |
} |
8158 | 636 |
BasicFileAttributes basicAttributes = |
637 |
readAttributes(source, BasicFileAttributes.class, linkOptions); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
638 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
639 |
// check hash if regular file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
640 |
if (basicAttributes.isRegularFile()) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
641 |
assertTrue(computeHash(source) == computeHash(target)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
642 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
643 |
// check link target if symbolic link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
644 |
if (basicAttributes.isSymbolicLink()) |
8158 | 645 |
assert(readSymbolicLink(source).equals(readSymbolicLink(target))); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
646 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
647 |
// check that attributes are copied |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
648 |
if (copyAttributes && followLinks) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
649 |
checkBasicAttributes(basicAttributes, |
8158 | 650 |
readAttributes(source, BasicFileAttributes.class, linkOptions)); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
651 |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
652 |
// verify other attributes when same provider |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
653 |
if (source.getFileSystem().provider() == target.getFileSystem().provider()) { |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
654 |
|
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
655 |
// check POSIX attributes are copied |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
656 |
String os = System.getProperty("os.name"); |
14011
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
657 |
if ((os.equals("SunOS") || os.equals("Linux")) && |
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
658 |
testPosixAttributes) |
3d24d5dcf602
6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents:
13667
diff
changeset
|
659 |
{ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
660 |
checkPosixAttributes( |
8158 | 661 |
readAttributes(source, PosixFileAttributes.class, linkOptions), |
662 |
readAttributes(target, PosixFileAttributes.class, linkOptions)); |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
663 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
664 |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
665 |
// check DOS attributes are copied |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
666 |
if (os.startsWith("Windows")) { |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
667 |
checkDosAttributes( |
8158 | 668 |
readAttributes(source, DosFileAttributes.class, linkOptions), |
669 |
readAttributes(target, DosFileAttributes.class, linkOptions)); |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
670 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
671 |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
672 |
// check named attributes are copied |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
673 |
if (followLinks && |
8158 | 674 |
getFileStore(source).supportsFileAttributeView("xattr") && |
675 |
getFileStore(target).supportsFileAttributeView("xattr")) |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
676 |
{ |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
677 |
checkUserDefinedFileAttributes(readUserDefinedFileAttributes(source), |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
678 |
readUserDefinedFileAttributes(target)); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
679 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
680 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
681 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
682 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
683 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
684 |
/** |
8158 | 685 |
* Tests all possible ways to invoke copy to copy a file to a file |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
686 |
*/ |
8158 | 687 |
static void testCopyFileToFile(Path dir1, Path dir2, boolean supportsLinks) |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
688 |
throws IOException |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
689 |
{ |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
690 |
Path source, target, link, entry; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
691 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
692 |
// -- regular file -- |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
693 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
694 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
695 |
* Test: move regular file, target does not exist |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
696 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
697 |
source = createSourceFile(dir1); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
698 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
699 |
copyAndVerify(source, target); |
8158 | 700 |
delete(source); |
701 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
702 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
703 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
704 |
* Test: copy regular file, target exists |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
705 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
706 |
source = createSourceFile(dir1); |
8158 | 707 |
target = getTargetFile(dir2); |
708 |
createFile(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
709 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
710 |
copyAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
711 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
712 |
} catch (FileAlreadyExistsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
713 |
} |
8158 | 714 |
delete(target); |
715 |
createDirectory(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
716 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
717 |
copyAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
718 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
719 |
} catch (FileAlreadyExistsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
720 |
} |
8158 | 721 |
delete(source); |
722 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
723 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
724 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
725 |
* Test: copy regular file, target does not exist |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
726 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
727 |
source = createSourceFile(dir1); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
728 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
729 |
copyAndVerify(source, target, REPLACE_EXISTING); |
8158 | 730 |
delete(source); |
731 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
732 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
733 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
734 |
* Test: copy regular file, target exists |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
735 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
736 |
source = createSourceFile(dir1); |
8158 | 737 |
target = getTargetFile(dir2); |
738 |
createFile(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
739 |
copyAndVerify(source, target, REPLACE_EXISTING); |
8158 | 740 |
delete(source); |
741 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
742 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
743 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
744 |
* Test: copy regular file, target exists and is empty directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
745 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
746 |
source = createSourceFile(dir1); |
8158 | 747 |
target = getTargetFile(dir2); |
748 |
createDirectory(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
749 |
copyAndVerify(source, target, REPLACE_EXISTING); |
8158 | 750 |
delete(source); |
751 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
752 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
753 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
754 |
* Test: copy regular file, target exists and is non-empty directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
755 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
756 |
source = createSourceFile(dir1); |
8158 | 757 |
target = getTargetFile(dir2); |
758 |
createDirectory(target); |
|
759 |
entry = target.resolve("foo"); |
|
760 |
createFile(entry); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
761 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
762 |
copyAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
763 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
764 |
} catch (FileAlreadyExistsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
765 |
} |
8158 | 766 |
delete(entry); |
767 |
delete(source); |
|
768 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
769 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
770 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
771 |
* Test: copy regular file + attributes |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
772 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
773 |
source = createSourceFile(dir1); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
774 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
775 |
copyAndVerify(source, target, COPY_ATTRIBUTES); |
8158 | 776 |
delete(source); |
777 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
778 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
779 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
780 |
// -- directory -- |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
781 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
782 |
/* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
783 |
* Test: copy directory, target does not exist |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
784 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
785 |
source = createSourceDirectory(dir1); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
786 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
787 |
copyAndVerify(source, target); |
8158 | 788 |
delete(source); |
789 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
790 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
791 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
792 |
* Test: copy directory, target exists |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
793 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
794 |
source = createSourceDirectory(dir1); |
8158 | 795 |
target = getTargetFile(dir2); |
796 |
createFile(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
797 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
798 |
copyAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
799 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
800 |
} catch (FileAlreadyExistsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
801 |
} |
8158 | 802 |
delete(target); |
803 |
createDirectory(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
804 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
805 |
copyAndVerify(source, target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
806 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
807 |
} catch (FileAlreadyExistsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
808 |
} |
8158 | 809 |
delete(source); |
810 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
811 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
812 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
813 |
* Test: copy directory, target does not exist |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
814 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
815 |
source = createSourceDirectory(dir1); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
816 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
817 |
copyAndVerify(source, target, REPLACE_EXISTING); |
8158 | 818 |
delete(source); |
819 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
820 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
821 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
822 |
* Test: copy directory, target exists |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
823 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
824 |
source = createSourceDirectory(dir1); |
8158 | 825 |
target = getTargetFile(dir2); |
826 |
createFile(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
827 |
copyAndVerify(source, target, REPLACE_EXISTING); |
8158 | 828 |
delete(source); |
829 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
830 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
831 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
832 |
* Test: copy directory, target exists and is empty directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
833 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
834 |
source = createSourceDirectory(dir1); |
8158 | 835 |
target = getTargetFile(dir2); |
836 |
createDirectory(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
837 |
copyAndVerify(source, target, REPLACE_EXISTING); |
8158 | 838 |
delete(source); |
839 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
840 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
841 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
842 |
* Test: copy directory, target exists and is non-empty directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
843 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
844 |
source = createSourceDirectory(dir1); |
8158 | 845 |
target = getTargetFile(dir2); |
846 |
createDirectory(target); |
|
847 |
entry = target.resolve("foo"); |
|
848 |
createFile(entry); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
849 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
850 |
copyAndVerify(source, target, REPLACE_EXISTING); |
8158 | 851 |
throw new RuntimeException("DirectoryNotEmptyException expected"); |
852 |
} catch (DirectoryNotEmptyException x) { |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
853 |
} |
8158 | 854 |
delete(entry); |
855 |
delete(source); |
|
856 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
857 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
858 |
/* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
859 |
* Test: copy directory + attributes |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
860 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
861 |
source = createSourceDirectory(dir1); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
862 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
863 |
copyAndVerify(source, target, COPY_ATTRIBUTES); |
8158 | 864 |
delete(source); |
865 |
delete(target); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
866 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
867 |
// -- symbolic links -- |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
868 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
869 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
870 |
* Test: Follow link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
871 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
872 |
if (supportsLinks) { |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
873 |
source = createSourceFile(dir1); |
8158 | 874 |
link = dir1.resolve("link"); |
875 |
createSymbolicLink(link, source); |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
876 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
877 |
copyAndVerify(link, target); |
8158 | 878 |
delete(link); |
879 |
delete(source); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
880 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
881 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
882 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
883 |
* Test: Copy link (to file) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
884 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
885 |
if (supportsLinks) { |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
886 |
source = createSourceFile(dir1); |
8158 | 887 |
link = dir1.resolve("link"); |
888 |
createSymbolicLink(link, source); |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
889 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
890 |
copyAndVerify(link, target, NOFOLLOW_LINKS); |
8158 | 891 |
delete(link); |
892 |
delete(source); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
893 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
894 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
895 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
896 |
* Test: Copy link (to directory) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
897 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
898 |
if (supportsLinks) { |
8158 | 899 |
source = dir1.resolve("mydir"); |
900 |
createDirectory(source); |
|
901 |
link = dir1.resolve("link"); |
|
902 |
createSymbolicLink(link, source); |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
903 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
904 |
copyAndVerify(link, target, NOFOLLOW_LINKS); |
8158 | 905 |
delete(link); |
906 |
delete(source); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
907 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
908 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
909 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
910 |
* Test: Copy broken link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
911 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
912 |
if (supportsLinks) { |
8158 | 913 |
assertTrue(notExists(source)); |
914 |
link = dir1.resolve("link"); |
|
915 |
createSymbolicLink(link, source); |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
916 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
917 |
copyAndVerify(link, target, NOFOLLOW_LINKS); |
8158 | 918 |
delete(link); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
919 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
920 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
921 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
922 |
* Test: Copy link to UNC (Windows only) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
923 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
924 |
if (supportsLinks && |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
925 |
System.getProperty("os.name").startsWith("Windows")) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
926 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
927 |
Path unc = Paths.get("\\\\rialto\\share\\file"); |
8158 | 928 |
link = dir1.resolve("link"); |
929 |
createSymbolicLink(link, unc); |
|
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
930 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
931 |
copyAndVerify(link, target, NOFOLLOW_LINKS); |
8158 | 932 |
delete(link); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
933 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
934 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
935 |
// -- misc. tests -- |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
936 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
937 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
938 |
* Test nulls |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
939 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
940 |
source = createSourceFile(dir1); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
941 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
942 |
try { |
8158 | 943 |
copy(source, null); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
944 |
throw new RuntimeException("NullPointerException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
945 |
} catch (NullPointerException x) { } |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
946 |
try { |
8158 | 947 |
copy(source, target, (CopyOption[])null); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
948 |
throw new RuntimeException("NullPointerException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
949 |
} catch (NullPointerException x) { } |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
950 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
951 |
CopyOption[] opts = { REPLACE_EXISTING, null }; |
8158 | 952 |
copy(source, target, opts); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
953 |
throw new RuntimeException("NullPointerException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
954 |
} catch (NullPointerException x) { } |
8158 | 955 |
delete(source); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
956 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
957 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
958 |
* Test UOE |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
959 |
*/ |
4679
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
960 |
source = createSourceFile(dir1); |
5feae448a41f
6917021: (file) copyTo/moveTo can overrwrite existing file when target associated with custom provider
alanb
parents:
4234
diff
changeset
|
961 |
target = getTargetFile(dir2); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
962 |
try { |
8158 | 963 |
copy(source, target, new CopyOption() { }); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
964 |
} catch (UnsupportedOperationException x) { } |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
965 |
try { |
8158 | 966 |
copy(source, target, REPLACE_EXISTING, new CopyOption() { }); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
967 |
} catch (UnsupportedOperationException x) { } |
8158 | 968 |
delete(source); |
969 |
} |
|
970 |
||
971 |
/** |
|
972 |
* Test copy from an input stream to a file |
|
973 |
*/ |
|
974 |
static void testCopyInputStreamToFile() throws IOException { |
|
975 |
testCopyInputStreamToFile(0); |
|
976 |
for (int i=0; i<100; i++) { |
|
977 |
testCopyInputStreamToFile(rand.nextInt(32000)); |
|
978 |
} |
|
979 |
||
980 |
// FileAlreadyExistsException |
|
981 |
Path target = createTempFile("blah", null); |
|
982 |
try { |
|
983 |
InputStream in = new ByteArrayInputStream(new byte[0]); |
|
984 |
try { |
|
985 |
copy(in, target); |
|
986 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
|
987 |
} catch (FileAlreadyExistsException ignore) { } |
|
988 |
} finally { |
|
989 |
delete(target); |
|
990 |
} |
|
991 |
Path tmpdir = createTempDirectory("blah"); |
|
992 |
try { |
|
993 |
if (TestUtil.supportsLinks(tmpdir)) { |
|
994 |
Path link = createSymbolicLink(tmpdir.resolve("link"), |
|
995 |
tmpdir.resolve("target")); |
|
996 |
try { |
|
997 |
InputStream in = new ByteArrayInputStream(new byte[0]); |
|
998 |
try { |
|
999 |
copy(in, link); |
|
1000 |
throw new RuntimeException("FileAlreadyExistsException expected"); |
|
1001 |
} catch (FileAlreadyExistsException ignore) { } |
|
1002 |
} finally { |
|
1003 |
delete(link); |
|
1004 |
} |
|
1005 |
} |
|
1006 |
} finally { |
|
1007 |
delete(tmpdir); |
|
1008 |
} |
|
1009 |
||
1010 |
||
1011 |
// nulls |
|
1012 |
try { |
|
1013 |
copy((InputStream)null, target); |
|
1014 |
throw new RuntimeException("NullPointerException expected"); |
|
1015 |
} catch (NullPointerException ignore) { } |
|
1016 |
try { |
|
1017 |
copy(new ByteArrayInputStream(new byte[0]), (Path)null); |
|
1018 |
throw new RuntimeException("NullPointerException expected"); |
|
1019 |
} catch (NullPointerException ignore) { } |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1020 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1021 |
|
8158 | 1022 |
static void testCopyInputStreamToFile(int size) throws IOException { |
1023 |
Path tmpdir = createTempDirectory("blah"); |
|
1024 |
Path source = tmpdir.resolve("source"); |
|
1025 |
Path target = tmpdir.resolve("target"); |
|
1026 |
try { |
|
1027 |
boolean testReplaceExisting = rand.nextBoolean(); |
|
1028 |
||
1029 |
// create source file |
|
1030 |
byte[] b = new byte[size]; |
|
1031 |
rand.nextBytes(b); |
|
1032 |
write(source, b); |
|
1033 |
||
1034 |
// target file might already exist |
|
1035 |
if (testReplaceExisting && rand.nextBoolean()) { |
|
1036 |
write(target, new byte[rand.nextInt(512)]); |
|
1037 |
} |
|
1038 |
||
1039 |
// copy from stream to file |
|
1040 |
InputStream in = new FileInputStream(source.toFile()); |
|
1041 |
try { |
|
1042 |
long n; |
|
1043 |
if (testReplaceExisting) { |
|
1044 |
n = copy(in, target, StandardCopyOption.REPLACE_EXISTING); |
|
1045 |
} else { |
|
1046 |
n = copy(in, target); |
|
1047 |
} |
|
1048 |
assertTrue(in.read() == -1); // EOF |
|
1049 |
assertTrue(n == size); |
|
1050 |
assertTrue(size(target) == size); |
|
1051 |
} finally { |
|
1052 |
in.close(); |
|
1053 |
} |
|
1054 |
||
1055 |
// check file |
|
1056 |
byte[] read = readAllBytes(target); |
|
1057 |
assertTrue(Arrays.equals(read, b)); |
|
1058 |
||
1059 |
} finally { |
|
1060 |
deleteIfExists(source); |
|
1061 |
deleteIfExists(target); |
|
1062 |
delete(tmpdir); |
|
1063 |
} |
|
1064 |
} |
|
1065 |
||
1066 |
/** |
|
1067 |
* Test copy from file to output stream |
|
1068 |
*/ |
|
1069 |
static void testCopyFileToOuputStream() throws IOException { |
|
1070 |
testCopyFileToOuputStream(0); |
|
1071 |
for (int i=0; i<100; i++) { |
|
1072 |
testCopyFileToOuputStream(rand.nextInt(32000)); |
|
1073 |
} |
|
1074 |
||
1075 |
// nulls |
|
1076 |
try { |
|
1077 |
copy((Path)null, new ByteArrayOutputStream()); |
|
1078 |
throw new RuntimeException("NullPointerException expected"); |
|
1079 |
} catch (NullPointerException ignore) { } |
|
1080 |
try { |
|
1081 |
Path source = createTempFile("blah", null); |
|
1082 |
delete(source); |
|
1083 |
copy(source, (OutputStream)null); |
|
1084 |
throw new RuntimeException("NullPointerException expected"); |
|
1085 |
} catch (NullPointerException ignore) { } |
|
1086 |
} |
|
1087 |
||
1088 |
static void testCopyFileToOuputStream(int size) throws IOException { |
|
1089 |
Path source = createTempFile("blah", null); |
|
1090 |
try { |
|
1091 |
byte[] b = new byte[size]; |
|
1092 |
rand.nextBytes(b); |
|
1093 |
write(source, b); |
|
1094 |
||
1095 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
1096 |
||
1097 |
long n = copy(source, out); |
|
1098 |
assertTrue(n == size); |
|
1099 |
assertTrue(out.size() == size); |
|
1100 |
||
1101 |
byte[] read = out.toByteArray(); |
|
1102 |
assertTrue(Arrays.equals(read, b)); |
|
1103 |
||
1104 |
// check output stream is open |
|
1105 |
out.write(0); |
|
1106 |
assertTrue(out.size() == size+1); |
|
1107 |
} finally { |
|
1108 |
delete(source); |
|
1109 |
} |
|
1110 |
} |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1111 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1112 |
static void assertTrue(boolean value) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1113 |
if (!value) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1114 |
throw new RuntimeException("Assertion failed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1115 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1116 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1117 |
// computes simple hash of the given file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1118 |
static int computeHash(Path file) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1119 |
int h = 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1120 |
|
8158 | 1121 |
try (InputStream in = newInputStream(file)) { |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1122 |
byte[] buf = new byte[1024]; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1123 |
int n; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1124 |
do { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1125 |
n = in.read(buf); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1126 |
for (int i=0; i<n; i++) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1127 |
h = 31*h + (buf[i] & 0xff); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1128 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1129 |
} while (n > 0); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1130 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1131 |
return h; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1132 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1133 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1134 |
// create file of random size in given directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1135 |
static Path createSourceFile(Path dir) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1136 |
String name = "source" + Integer.toString(rand.nextInt()); |
8158 | 1137 |
Path file = dir.resolve(name); |
1138 |
createFile(file); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1139 |
byte[] bytes = new byte[rand.nextInt(128*1024)]; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1140 |
rand.nextBytes(bytes); |
8158 | 1141 |
try (OutputStream out = newOutputStream(file)) { |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1142 |
out.write(bytes); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1143 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1144 |
randomizeAttributes(file); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1145 |
return file; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1146 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1147 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1148 |
// create directory in the given directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1149 |
static Path createSourceDirectory(Path dir) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1150 |
String name = "sourcedir" + Integer.toString(rand.nextInt()); |
8158 | 1151 |
Path subdir = dir.resolve(name); |
1152 |
createDirectory(subdir); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1153 |
randomizeAttributes(subdir); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1154 |
return subdir; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1155 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1156 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1157 |
// "randomize" the file attributes of the given file. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1158 |
static void randomizeAttributes(Path file) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1159 |
String os = System.getProperty("os.name"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1160 |
boolean isWindows = os.startsWith("Windows"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1161 |
boolean isUnix = os.equals("SunOS") || os.equals("Linux"); |
8158 | 1162 |
boolean isDirectory = isDirectory(file, NOFOLLOW_LINKS); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1163 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1164 |
if (isUnix) { |
8158 | 1165 |
Set<PosixFilePermission> perms = |
1166 |
getPosixFilePermissions(file, NOFOLLOW_LINKS); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1167 |
PosixFilePermission[] toChange = { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1168 |
PosixFilePermission.GROUP_READ, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1169 |
PosixFilePermission.GROUP_WRITE, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1170 |
PosixFilePermission.GROUP_EXECUTE, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1171 |
PosixFilePermission.OTHERS_READ, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1172 |
PosixFilePermission.OTHERS_WRITE, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1173 |
PosixFilePermission.OTHERS_EXECUTE |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1174 |
}; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1175 |
for (PosixFilePermission perm: toChange) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1176 |
if (heads()) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1177 |
perms.add(perm); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1178 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1179 |
perms.remove(perm); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1180 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1181 |
} |
8158 | 1182 |
setPosixFilePermissions(file, perms); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1183 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1184 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1185 |
if (isWindows) { |
8158 | 1186 |
DosFileAttributeView view = |
1187 |
getFileAttributeView(file, DosFileAttributeView.class, NOFOLLOW_LINKS); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1188 |
// only set or unset the hidden attribute |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1189 |
view.setHidden(heads()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1190 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1191 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1192 |
boolean addUserDefinedFileAttributes = heads() && |
8158 | 1193 |
getFileStore(file).supportsFileAttributeView("xattr"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1194 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1195 |
// remove this when copying a direcory copies its named streams |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1196 |
if (isWindows && isDirectory) addUserDefinedFileAttributes = false; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1197 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1198 |
if (addUserDefinedFileAttributes) { |
8158 | 1199 |
UserDefinedFileAttributeView view = |
1200 |
getFileAttributeView(file, UserDefinedFileAttributeView.class); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1201 |
int n = rand.nextInt(16); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1202 |
while (n > 0) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1203 |
byte[] value = new byte[1 + rand.nextInt(100)]; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1204 |
view.write("user." + Integer.toString(n), ByteBuffer.wrap(value)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1205 |
n--; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1206 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1207 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1208 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1209 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1210 |
// create name for file in given directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1211 |
static Path getTargetFile(Path dir) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1212 |
String name = "target" + Integer.toString(rand.nextInt()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1213 |
return dir.resolve(name); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1214 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1215 |
} |