test/java/nio/file/TestUtil.java
Print this page
*** 29,49 ****
public class TestUtil {
private TestUtil() {
}
static Path createTemporaryDirectory(String where) throws IOException {
! Path top = FileSystems.getDefault().getPath(where);
! Random r = new Random();
! Path dir;
! do {
! dir = top.resolve("name" + r.nextInt());
! } while (dir.exists());
! return dir.createDirectory();
}
static Path createTemporaryDirectory() throws IOException {
! return createTemporaryDirectory(System.getProperty("java.io.tmpdir"));
}
static void removeAll(Path dir) throws IOException {
Files.walkFileTree(dir, new FileVisitor<Path>() {
@Override
--- 29,44 ----
public class TestUtil {
private TestUtil() {
}
static Path createTemporaryDirectory(String where) throws IOException {
! Path dir = FileSystems.getDefault().getPath(where);
! return Files.createTempDirectory(dir, "name");
}
static Path createTemporaryDirectory() throws IOException {
! return Files.createTempDirectory("name");
}
static void removeAll(Path dir) throws IOException {
Files.walkFileTree(dir, new FileVisitor<Path>() {
@Override
*** 51,70 ****
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
try {
! file.delete();
} catch (IOException x) {
System.err.format("Unable to delete %s: %s\n", file, x);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
try {
! dir.delete();
} catch (IOException x) {
System.err.format("Unable to delete %s: %s\n", dir, x);
}
return FileVisitResult.CONTINUE;
}
--- 46,65 ----
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
try {
! Files.delete(file);
} catch (IOException x) {
System.err.format("Unable to delete %s: %s\n", file, x);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
try {
! Files.delete(dir);
} catch (IOException x) {
System.err.format("Unable to delete %s: %s\n", dir, x);
}
return FileVisitResult.CONTINUE;
}
*** 76,86 ****
});
}
static void deleteUnchecked(Path file) {
try {
! file.delete();
} catch (IOException exc) {
System.err.format("Unable to delete %s: %s\n", file, exc);
}
}
--- 71,81 ----
});
}
static void deleteUnchecked(Path file) {
try {
! Files.delete(file);
} catch (IOException exc) {
System.err.format("Unable to delete %s: %s\n", file, exc);
}
}
*** 97,107 ****
sb.append('A');
}
String name = sb.toString();
do {
dir = dir.resolve(name).resolve(".");
! dir.createDirectory();
} while (dir.toString().length() < 2048);
return dir;
}
/**
--- 92,102 ----
sb.append('A');
}
String name = sb.toString();
do {
dir = dir.resolve(name).resolve(".");
! Files.createDirectory(dir);
} while (dir.toString().length() < 2048);
return dir;
}
/**
*** 109,120 ****
*/
static boolean supportsLinks(Path dir) {
Path link = dir.resolve("testlink");
Path target = dir.resolve("testtarget");
try {
! link.createSymbolicLink(target);
! link.delete();
return true;
} catch (UnsupportedOperationException x) {
return false;
} catch (IOException x) {
return false;
--- 104,115 ----
*/
static boolean supportsLinks(Path dir) {
Path link = dir.resolve("testlink");
Path target = dir.resolve("testtarget");
try {
! Files.createSymbolicLink(link, target);
! Files.delete(link);
return true;
} catch (UnsupportedOperationException x) {
return false;
} catch (IOException x) {
return false;