6838333: New I/O: Update file system API to jsr203/nio2-b101
6844313: New I/O: File timestamps should be represented by a FileTime rather than a long+TimeUnit
Reviewed-by: sherman
diff --git a/test/java/nio/file/DirectoryStream/Basic.java b/test/java/nio/file/DirectoryStream/Basic.java
index b92447d..4b5a5df 100644
--- a/test/java/nio/file/DirectoryStream/Basic.java
+++ b/test/java/nio/file/DirectoryStream/Basic.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.DirectoryStream
* @library ..
*/
@@ -38,20 +38,23 @@
DirectoryStream<Path> stream;
// test that directory is empty
- Files.withDirectory(dir, new FileAction<FileRef>() {
- public void invoke(FileRef entry) {
+ stream = dir.newDirectoryStream();
+ try {
+ if (stream.iterator().hasNext())
throw new RuntimeException("directory not empty");
- }
- });
+ } finally {
+ stream.close();
+ }
// create file in directory
final Path foo = Paths.get("foo");
dir.resolve(foo).createFile();
// iterate over directory and check there is one entry
+ stream = dir.newDirectoryStream();
found = false;
- Files.withDirectory(dir, new FileAction<Path>() {
- public void invoke(Path entry) {
+ try {
+ for (Path entry: stream) {
if (entry.getName().equals(foo)) {
if (found)
throw new RuntimeException("entry already found");
@@ -61,7 +64,9 @@
" not expected");
}
}
- });
+ } finally {
+ stream.close();
+ }
if (!found)
throw new RuntimeException("entry not found");
@@ -73,12 +78,15 @@
return matcher.matches(file);
}
};
- Files.withDirectory(dir, filter, new FileAction<Path>() {
- public void invoke(Path entry) {
+ stream = dir.newDirectoryStream(filter);
+ try {
+ for (Path entry: stream) {
if (!entry.getName().equals(foo))
throw new RuntimeException("entry not expected");
}
- });
+ } finally {
+ stream.close();
+ }
// check filtering: z* should not match any files
filter = new DirectoryStream.Filter<Path>() {
@@ -88,11 +96,31 @@
return matcher.matches(file);
}
};
- Files.withDirectory(dir, filter, new FileAction<FileRef>() {
- public void invoke(FileRef entry) {
+ stream = dir.newDirectoryStream(filter);
+ try {
+ if (stream.iterator().hasNext())
throw new RuntimeException("no matching entries expected");
+ } finally {
+ stream.close();
+ }
+
+ // check that IOExceptions throws by filters are propagated
+ filter = new DirectoryStream.Filter<Path>() {
+ public boolean accept(Path file) throws IOException {
+ throw new IOException();
}
- });
+ };
+ stream = dir.newDirectoryStream(filter);
+ try {
+ stream.iterator().hasNext();
+ throw new RuntimeException("ConcurrentModificationException expected");
+ } catch (ConcurrentModificationException x) {
+ Throwable t = x.getCause();
+ if (!(t instanceof IOException))
+ throw new RuntimeException("Cause is not IOException as expected");
+ } finally {
+ stream.close();
+ }
// check that exception or error thrown by filter is not thrown
// by newDirectoryStream or iterator method.
diff --git a/test/java/nio/file/DirectoryStream/Filters.java b/test/java/nio/file/DirectoryStream/Filters.java
deleted file mode 100644
index ea539c9..0000000
--- a/test/java/nio/file/DirectoryStream/Filters.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-/* @test
- * @bug 4313887
- * @summary Unit test for java.nio.file.DirectoryStreamFilters
- * @library ..
- */
-
-import java.nio.file.*;
-import static java.nio.file.DirectoryStreamFilters.*;
-import java.nio.file.attribute.Attributes;
-import java.io.*;
-import java.util.*;
-
-public class Filters {
- static final Random rand = new Random();
-
- // returns a filter that only accepts files that are larger than a given size
- static DirectoryStream.Filter<FileRef> newMinimumSizeFilter(final long min) {
- return new DirectoryStream.Filter<FileRef>() {
- public boolean accept(FileRef file) {
- try {
- long size = Attributes.readBasicFileAttributes(file).size();
- return size >= min;
- } catch (IOException e) {
- throw new IOError(e);
- }
- }
- };
- }
-
- // returns a filter that only accepts files that are matched by a given glob
- static DirectoryStream.Filter<Path> newGlobFilter(final String glob) {
- return new DirectoryStream.Filter<Path>() {
- PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:"+ glob);
- public boolean accept(Path file) {
- return matcher.matches(file.getName());
- }
- };
- }
-
- static final int BIG_FILE_THRESHOLD = 8192;
-
- static int totalCount;
- static int htmlCount;
- static int bigAndHtmlCount;
- static int bigOrHtmlCount;
-
- // generates random files in the test directory and initializes the counts
- static void setup(Path dir) throws IOException {
- // create 10-26 files.
- totalCount = 10 + rand.nextInt(17);
- char firstChar = 'A';
- for (int i=0; i<totalCount; i++) {
- boolean isHtml = rand.nextBoolean();
- boolean isBig = rand.nextBoolean();
- if (isHtml) {
- htmlCount++;
- if (isBig) bigAndHtmlCount++;
- }
- if (isHtml || isBig)
- bigOrHtmlCount++;
- String name;
- if (isHtml) {
- name = firstChar + ".html";
- } else {
- name = firstChar + ".tmp";
- }
- firstChar++;
- int size = rand.nextInt(BIG_FILE_THRESHOLD);
- if (isBig)
- size += BIG_FILE_THRESHOLD;
- Path file = dir.resolve(name);
- OutputStream out = file.newOutputStream();
- try {
- if (size > 0)
- out.write(new byte[size]);
- } finally {
- out.close();
- }
- System.out.format("Created %s, size %d byte(s)\n", name, size);
- }
- }
-
- static boolean isHtml(Path file) {
- return file.toString().endsWith(".html");
- }
-
- static boolean isBig(Path file) throws IOException {
- long size = Attributes.readBasicFileAttributes(file).size();
- return size >= BIG_FILE_THRESHOLD;
- }
-
- static void checkCount(int expected, int actual) {
- if (actual != expected)
- throw new RuntimeException("'" + expected +
- "' entries expected, actual: " + actual);
- }
-
- static void doTests(Path dir) throws IOException {
- final List<DirectoryStream.Filter<Path>> emptyList = Collections.emptyList();
-
- // list containing two filters
- List<DirectoryStream.Filter<? super Path>> filters =
- new ArrayList<DirectoryStream.Filter<? super Path>>();
- filters.add(newMinimumSizeFilter(BIG_FILE_THRESHOLD));
- filters.add(newGlobFilter("*.html"));
-
- int accepted;
- DirectoryStream<Path> stream;
-
- System.out.println("Test: newContentTypeFilter");
- accepted = 0;
- stream = dir.newDirectoryStream(newContentTypeFilter("text/html"));
- try {
- for (Path entry: stream) {
- if (!isHtml(entry))
- throw new RuntimeException("html file expected");
- accepted++;
- }
- } finally {
- stream.close();
- }
- checkCount(htmlCount, accepted);
-
- System.out.println("Test: allOf with list of filters");
- accepted = 0;
- stream = dir.newDirectoryStream(allOf(filters));
- try {
- for (Path entry: stream) {
- if (!isHtml(entry))
- throw new RuntimeException("html file expected");
- if (!isBig(entry))
- throw new RuntimeException("big file expected");
- accepted++;
- }
- } finally {
- stream.close();
- }
- checkCount(bigAndHtmlCount, accepted);
-
- System.out.println("Test: allOf with empty list");
- accepted = 0;
- stream = dir.newDirectoryStream(allOf(emptyList));
- try {
- for (Path entry: stream) {
- accepted++;
- }
- } finally {
- stream.close();
- }
- checkCount(totalCount, accepted);
-
- System.out.println("Test: anyOf with list of filters");
- accepted = 0;
- stream = dir.newDirectoryStream(anyOf(filters));
- try {
- for (Path entry: stream) {
- if (!isHtml(entry) && !isBig(entry))
- throw new RuntimeException("html or big file expected");
- accepted++;
- }
- } finally {
- stream.close();
- }
- checkCount(bigOrHtmlCount, accepted);
-
- System.out.println("Test: anyOf with empty list");
- accepted = 0;
- stream = dir.newDirectoryStream(anyOf(emptyList));
- try {
- for (Path entry: stream) {
- accepted++;
- }
- } finally {
- stream.close();
- }
- checkCount(0, accepted);
-
- System.out.println("Test: complementOf");
- accepted = 0;
- stream = dir.newDirectoryStream(complementOf(newGlobFilter("*.html")));
- try {
- for (Path entry: stream) {
- accepted++;
- }
- } finally {
- stream.close();
- }
- checkCount(totalCount-htmlCount, accepted);
-
- System.out.println("Test: nulls");
- try {
- newContentTypeFilter(null);
- throw new RuntimeException("NullPointerException expected");
- } catch (NullPointerException npe) { }
- try {
- allOf(null);
- throw new RuntimeException("NullPointerException expected");
- } catch (NullPointerException npe) { }
- try {
- anyOf(null);
- throw new RuntimeException("NullPointerException expected");
- } catch (NullPointerException npe) { }
- try {
- complementOf(null);
- throw new RuntimeException("NullPointerException expected");
- } catch (NullPointerException npe) { }
- }
-
- public static void main(String[] args) throws IOException {
- Path dir = TestUtil.createTemporaryDirectory();
- try {
- setup(dir);
- doTests(dir);
- } finally {
- TestUtil.removeAll(dir);
- }
- }
-}
diff --git a/test/java/nio/file/DirectoryStream/SecureDS.java b/test/java/nio/file/DirectoryStream/SecureDS.java
index 98367d8..3c7799e 100644
--- a/test/java/nio/file/DirectoryStream/SecureDS.java
+++ b/test/java/nio/file/DirectoryStream/SecureDS.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.SecureDirectoryStream
* @library ..
*/
@@ -41,7 +41,7 @@
public static void main(String[] args) throws IOException {
Path dir = TestUtil.createTemporaryDirectory();
try {
- DirectoryStream stream = dir.newDirectoryStream();
+ DirectoryStream<Path> stream = dir.newDirectoryStream();
stream.close();
if (!(stream instanceof SecureDirectoryStream)) {
System.out.println("SecureDirectoryStream not supported.");
@@ -81,8 +81,8 @@
// open directory and then move it so that it is no longer accessible
// via its original path.
- SecureDirectoryStream stream =
- (SecureDirectoryStream)dir1.newDirectoryStream();
+ SecureDirectoryStream<Path> stream =
+ (SecureDirectoryStream<Path>)dir1.newDirectoryStream();
dir1.moveTo(dir2);
// Test: iterate over all entries
@@ -96,18 +96,6 @@
.readAttributes()
.isDirectory());
- // Test: dynamic access to directory's attributes
- BasicFileAttributeView view = stream.
- getFileAttributeView(BasicFileAttributeView.class);
- Map<String,?> attrs = view.readAttributes("*");
- assertTrue((Boolean)attrs.get("isDirectory"));
- attrs = view.readAttributes("isRegularFile", "size");
- assertTrue(!(Boolean)attrs.get("isRegularFile"));
- assertTrue((Long)attrs.get("size") >= 0);
- int linkCount = (Integer)view.getAttribute("linkCount");
- assertTrue(linkCount > 0);
- view.setAttribute("lastModifiedTime", 0L);
-
// Test: getFileAttributeView to access attributes of entries
assertTrue(stream
.getFileAttributeView(fileEntry, BasicFileAttributeView.class)
@@ -144,17 +132,6 @@
.isSymbolicLink());
}
- // Test: dynamic access to entry attributes
- view = stream
- .getFileAttributeView(fileEntry, PosixFileAttributeView.class, NOFOLLOW_LINKS);
- if (view != null) {
- attrs = view.readAttributes("owner", "size");
- UserPrincipal owner = (UserPrincipal)attrs.get("owner");
- assertTrue(owner != null);
- assertTrue((Long)attrs.get("size") >= 0L);
- view.setAttribute("lastAccessTime", 0L);
- }
-
// Test: newByteChannel
Set<StandardOpenOption> opts = Collections.emptySet();
stream.newByteChannel(fileEntry, opts).close();
@@ -170,12 +147,13 @@
}
// Test: newDirectoryStream
- stream.newDirectoryStream(dirEntry, true, null).close();
- stream.newDirectoryStream(dirEntry, false, null).close();
+ stream.newDirectoryStream(dirEntry).close();
+ stream.newDirectoryStream(dirEntry, LinkOption.NOFOLLOW_LINKS).close();
if (supportsLinks) {
- stream.newDirectoryStream(link2Entry, true, null).close();
+ stream.newDirectoryStream(link2Entry).close();
try {
- stream.newDirectoryStream(link2Entry, false, null).close();
+ stream.newDirectoryStream(link2Entry, LinkOption.NOFOLLOW_LINKS)
+ .close();
shouldNotGetHere();
} catch (IOException x) { }
}
@@ -193,7 +171,7 @@
stream.close();
dir2.moveTo(dir1);
dir1.resolve(fileEntry).createFile();
- stream = (SecureDirectoryStream)dir1.newDirectoryStream();
+ stream = (SecureDirectoryStream<Path>)dir1.newDirectoryStream();
dir1.moveTo(dir2);
Iterator<Path> iter = stream.iterator();
int removed = 0;
@@ -227,10 +205,10 @@
Path target = Paths.get("newfile");
// open stream to both directories
- SecureDirectoryStream stream1 =
- (SecureDirectoryStream)dir1.newDirectoryStream();
- SecureDirectoryStream stream2 =
- (SecureDirectoryStream)dir2.newDirectoryStream();
+ SecureDirectoryStream<Path> stream1 =
+ (SecureDirectoryStream<Path>)dir1.newDirectoryStream();
+ SecureDirectoryStream<Path> stream2 =
+ (SecureDirectoryStream<Path>)dir2.newDirectoryStream();
// Test: move dir1/myfile -> dir2/newfile
stream1.move(fileEntry, stream2, target);
@@ -259,8 +237,8 @@
if (testDirAsString != null) {
Path testDir = Paths.get(testDirAsString);
if (!dir1.getFileStore().equals(testDir.getFileStore())) {
- SecureDirectoryStream ts =
- (SecureDirectoryStream)testDir.newDirectoryStream();
+ SecureDirectoryStream<Path> ts =
+ (SecureDirectoryStream<Path>)testDir.newDirectoryStream();
dir1.resolve(fileEntry).createFile();
try {
stream1.move(fileEntry, ts, target);
@@ -281,8 +259,8 @@
Path file = Paths.get("file");
dir.resolve(file).createFile();
- SecureDirectoryStream stream =
- (SecureDirectoryStream)dir.newDirectoryStream();
+ SecureDirectoryStream<Path> stream =
+ (SecureDirectoryStream<Path>)dir.newDirectoryStream();
// NullPointerException
try {
@@ -322,7 +300,7 @@
shouldNotGetHere();
} catch (NullPointerException x) { }
try {
- stream.newDirectoryStream(null, true, null);
+ stream.newDirectoryStream(null);
shouldNotGetHere();
} catch (NullPointerException x) { }
try {
@@ -340,7 +318,7 @@
// ClosedDirectoryStreamException
try {
- stream.newDirectoryStream(file, true, null);
+ stream.newDirectoryStream(file);
shouldNotGetHere();
} catch (ClosedDirectoryStreamException x) { }
try {
diff --git a/test/java/nio/file/FileSystem/Basic.java b/test/java/nio/file/FileSystem/Basic.java
index 8df7c1e..4caf79f 100644
--- a/test/java/nio/file/FileSystem/Basic.java
+++ b/test/java/nio/file/FileSystem/Basic.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.FileSystem
* @library ..
*/
@@ -73,10 +73,10 @@
checkSupported(fs, "basic");
String os = System.getProperty("os.name");
if (os.equals("SunOS"))
- checkSupported(fs, "posix", "unix", "owner", "acl", "xattr");
+ checkSupported(fs, "posix", "unix", "owner", "acl", "user");
if (os.equals("Linux"))
- checkSupported(fs, "posix", "unix", "owner", "dos", "xattr");
+ checkSupported(fs, "posix", "unix", "owner", "dos", "user");
if (os.equals("Windows"))
- checkSupported(fs, "owner", "dos", "acl", "xattr");
+ checkSupported(fs, "owner", "dos", "acl", "user");
}
}
diff --git a/test/java/nio/file/Files/ContentType.java b/test/java/nio/file/Files/ContentType.java
index a0a5afc..8a2267e 100644
--- a/test/java/nio/file/Files/ContentType.java
+++ b/test/java/nio/file/Files/ContentType.java
@@ -21,6 +21,13 @@
* have any questions.
*/
+/* @test
+ * @bug 4313887
+ * @summary Unit test for probeContentType method
+ * @library ..
+ * @build ContentType SimpleFileTypeDetector
+ */
+
import java.nio.file.*;
import java.io.*;
@@ -30,7 +37,7 @@
public class ContentType {
- static FileRef createHtmlFile() throws IOException {
+ static Path createHtmlFile() throws IOException {
Path file = File.createTempFile("foo", ".html").toPath();
OutputStream out = file.newOutputStream();
try {
@@ -42,18 +49,14 @@
return file;
}
- static FileRef createUnknownFile() throws IOException {
- return File.createTempFile("unknown", "unknown-file-type-789").toPath();
- }
-
- static FileRef createGrapeFile() throws IOException {
+ static Path createGrapeFile() throws IOException {
return File.createTempFile("red", ".grape").toPath();
}
public static void main(String[] args) throws IOException {
// exercise default file type detector
- FileRef file = createHtmlFile();
+ Path file = createHtmlFile();
try {
String type = Files.probeContentType(file);
if (type == null) {
@@ -63,16 +66,7 @@
throw new RuntimeException("Unexpected type: " + type);
}
} finally {
- TestUtil.deleteUnchecked(file);
- }
- file = createUnknownFile();
- try {
- String type = Files.probeContentType(file);
- if (type != null)
- throw new RuntimeException(file + " should not be recognized as:" +
- type);
- } finally {
- TestUtil.deleteUnchecked(file);
+ file.delete();
}
// exercise custom file type detector
@@ -84,7 +78,7 @@
if (!type.equals("grape/unknown"))
throw new RuntimeException("Unexpected type: " + type);
} finally {
- TestUtil.deleteUnchecked(file);
+ file.delete();
}
}
diff --git a/test/java/nio/file/Files/Misc.java b/test/java/nio/file/Files/Misc.java
index dde74a4..cd7e17a 100644
--- a/test/java/nio/file/Files/Misc.java
+++ b/test/java/nio/file/Files/Misc.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.Files for miscellenous cases not
* covered by other tests
* @library ..
@@ -39,74 +39,66 @@
}
public static void main(String[] args) throws IOException {
+
+ // -- Files.createDirectories --
+
+ Path dir = TestUtil.createTemporaryDirectory();
+ try {
+ // no-op
+ Files.createDirectories(dir);
+
+ // create one directory
+ Path subdir = dir.resolve("a");
+ Files.createDirectories(subdir);
+ if (!subdir.exists())
+ throw new RuntimeException("directory not created");
+
+ // create parents
+ subdir = subdir.resolve("b/c/d");
+ Files.createDirectories(subdir);
+ if (!subdir.exists())
+ throw new RuntimeException("directory not created");
+
+ // existing file is not a directory
+ Path file = dir.resolve("x").createFile();
+ try {
+ Files.createDirectories(file);
+ throw new RuntimeException("failure expected");
+ } catch (FileAlreadyExistsException x) { }
+ try {
+ Files.createDirectories(file.resolve("y"));
+ throw new RuntimeException("failure expected");
+ } catch (IOException x) { }
+
+ } finally {
+ TestUtil.removeAll(dir);
+ }
+
+ // --- NullPointerException --
+
try {
Files.probeContentType(null);
npeExpected();
} catch (NullPointerException e) {
}
-
- try {
- Files.withDirectory(null, "*", new FileAction<Path>() {
- public void invoke(Path entry) {
- }
- });
- npeExpected();
- } catch (NullPointerException e) {
- }
-
- try {
- Files.withDirectory(Paths.get("."), (String)null, new FileAction<Path>() {
- public void invoke(Path entry) {
- }
- });
- npeExpected();
- } catch (NullPointerException e) {
- }
-
- try {
- Files.withDirectory(Paths.get("."), "*", null);
- npeExpected();
- } catch (NullPointerException e) {
- }
-
- // test propogation of IOException
- Path tmpdir = TestUtil.createTemporaryDirectory();
- try {
- tmpdir.resolve("foo").createFile();
- try {
- Files.withDirectory(tmpdir, new FileAction<Path>() {
- public void invoke(Path entry) throws IOException {
- throw new IOException();
- }
- });
- throw new RuntimeException("IOException expected");
- } catch (IOException e) {
- }
- } finally {
- TestUtil.removeAll(tmpdir);
- }
-
try {
Files.walkFileTree(null, EnumSet.noneOf(FileVisitOption.class),
Integer.MAX_VALUE, new SimpleFileVisitor<Path>(){});
npeExpected();
} catch (NullPointerException e) {
}
-
try {
Files.walkFileTree(Paths.get("."), null, Integer.MAX_VALUE,
new SimpleFileVisitor<Path>(){});
npeExpected();
} catch (NullPointerException e) {
}
-
try {
Files.walkFileTree(Paths.get("."), EnumSet.noneOf(FileVisitOption.class),
-1, new SimpleFileVisitor<Path>(){});
throw new RuntimeException("IllegalArgumentExpected expected");
} catch (IllegalArgumentException e) {
}
-
try {
Set<FileVisitOption> opts = new HashSet<FileVisitOption>(1);
opts.add(null);
@@ -115,7 +107,6 @@
npeExpected();
} catch (NullPointerException e) {
}
-
try {
Files.walkFileTree(Paths.get("."), EnumSet.noneOf(FileVisitOption.class),
Integer.MAX_VALUE, null);
diff --git a/test/java/nio/file/Files/content_type.sh b/test/java/nio/file/Files/content_type.sh
deleted file mode 100644
index 46f4626..0000000
--- a/test/java/nio/file/Files/content_type.sh
+++ /dev/null
@@ -1,71 +0,0 @@
-#
-# Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
-# CA 95054 USA or visit www.sun.com if you need additional information or
-# have any questions.
-#
-
-# @test
-# @bug 4313887
-# @summary Unit test for probeContentType method
-# @library ..
-# @build ContentType SimpleFileTypeDetector
-# @run shell content_type.sh
-
-# if TESTJAVA isn't set then we assume an interactive run.
-
-if [ -z "$TESTJAVA" ]; then
- TESTSRC=.
- TESTCLASSES=.
- JAVA=java
-else
- JAVA="${TESTJAVA}/bin/java"
-fi
-
-OS=`uname -s`
-case "$OS" in
- Windows_* )
- CLASSPATH="${TESTCLASSES};${TESTSRC}"
- ;;
- * )
- CLASSPATH=${TESTCLASSES}:${TESTSRC}
- ;;
-esac
-export CLASSPATH
-
-failures=0
-
-go() {
- echo ''
- $JAVA $1 $2 $3 2>&1
- if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
-}
-
-# Run the test
-
-go ContentType
-
-#
-# Results
-#
-echo ''
-if [ $failures -gt 0 ];
- then echo "$failures test(s) failed";
- else echo "All test(s) passed"; fi
-exit $failures
diff --git a/test/java/nio/file/Path/CopyAndMove.java b/test/java/nio/file/Path/CopyAndMove.java
index 4e4c75f..39ac668 100644
--- a/test/java/nio/file/Path/CopyAndMove.java
+++ b/test/java/nio/file/Path/CopyAndMove.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.Path copyTo/moveTo methods
* @library ..
*/
@@ -69,9 +69,9 @@
assertTrue(attrs1.isSymbolicLink() == attrs2.isSymbolicLink());
assertTrue(attrs1.isOther() == attrs2.isOther());
- // check last modified time (assume millisecond precision)
- long time1 = attrs1.resolution().toMillis(attrs1.lastModifiedTime());
- long time2 = attrs1.resolution().toMillis(attrs2.lastModifiedTime());
+ // check last modified time
+ long time1 = attrs1.lastModifiedTime().toMillis();
+ long time2 = attrs2.lastModifiedTime().toMillis();
assertTrue(time1 == time2);
// check size
diff --git a/test/java/nio/file/Path/FileAttributes.java b/test/java/nio/file/Path/FileAttributes.java
new file mode 100644
index 0000000..d6a09ad
--- /dev/null
+++ b/test/java/nio/file/Path/FileAttributes.java
@@ -0,0 +1,264 @@
+/*
+ * Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 4313887 6838333
+ * @summary Unit test for java.nio.file.Path
+ * @library ..
+ */
+
+import java.nio.file.*;
+import java.nio.file.attribute.*;
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Exercises getAttribute/setAttribute/readAttributes methods.
+ */
+
+public class FileAttributes {
+
+ static void assertTrue(boolean okay) {
+ if (!okay)
+ throw new RuntimeException("Assertion Failed");
+ }
+
+ static void checkEqual(Object o1, Object o2) {
+ if (o1 == null) {
+ assertTrue(o2 == null);
+ } else {
+ assertTrue (o1.equals(o2));
+ }
+ }
+
+ // checks that two time values are within 1s of each other
+ static void checkNearEqual(FileTime t1, FileTime t2) {
+ long diff = Math.abs(t1.toMillis() - t2.toMillis());
+ assertTrue(diff <= 1000);
+ }
+
+ // Exercise getAttribute/setAttribute/readAttributes on basic attributes
+ static void checkBasicAttributes(FileRef file, BasicFileAttributes attrs)
+ throws IOException
+ {
+ // getAttribute
+ checkEqual(attrs.size(), file.getAttribute("size"));
+ checkEqual(attrs.lastModifiedTime(), file.getAttribute("basic:lastModifiedTime"));
+ checkEqual(attrs.lastAccessTime(), file.getAttribute("lastAccessTime"));
+ checkEqual(attrs.creationTime(), file.getAttribute("basic:creationTime"));
+ assertTrue((Boolean)file.getAttribute("isRegularFile"));
+ assertTrue(!(Boolean)file.getAttribute("basic:isDirectory"));
+ assertTrue(!(Boolean)file.getAttribute("isSymbolicLink"));
+ assertTrue(!(Boolean)file.getAttribute("basic:isOther"));
+ checkEqual(attrs.fileKey(), file.getAttribute("basic:fileKey"));
+
+ // setAttribute
+ FileTime modTime = attrs.lastModifiedTime();
+ file.setAttribute("basic:lastModifiedTime", FileTime.fromMillis(0L));
+ checkEqual(Attributes.readBasicFileAttributes(file).lastModifiedTime(),
+ FileTime.fromMillis(0L));
+ file.setAttribute("lastModifiedTime", modTime);
+ checkEqual(Attributes.readBasicFileAttributes(file).lastModifiedTime(), modTime);
+
+ Map<String,?> map;
+ map = file.readAttributes("*");
+ assertTrue(map.size() >= 9);
+ checkEqual(attrs.isRegularFile(), map.get("isRegularFile")); // check one
+
+ map = file.readAttributes("basic:*");
+ assertTrue(map.size() >= 9);
+ checkEqual(attrs.lastAccessTime(), map.get("lastAccessTime")); // check one
+
+ map = file.readAttributes("size,lastModifiedTime");
+ assertTrue(map.size() == 2);
+ checkEqual(attrs.size(), map.get("size"));
+ checkEqual(attrs.lastModifiedTime(), map.get("lastModifiedTime"));
+
+ map = file.readAttributes(
+ "basic:lastModifiedTime,lastAccessTime,ShouldNotExist");
+ assertTrue(map.size() == 2);
+ checkEqual(attrs.lastModifiedTime(), map.get("lastModifiedTime"));
+ checkEqual(attrs.lastAccessTime(), map.get("lastAccessTime"));
+ }
+
+ // Exercise getAttribute/setAttribute/readAttributes on posix attributes
+ static void checkPosixAttributes(FileRef file, PosixFileAttributes attrs)
+ throws IOException
+ {
+ checkBasicAttributes(file, attrs);
+
+ // getAttribute
+ checkEqual(attrs.permissions(), file.getAttribute("posix:permissions"));
+ checkEqual(attrs.owner(), file.getAttribute("posix:owner"));
+ checkEqual(attrs.group(), file.getAttribute("posix:group"));
+
+ // setAttribute
+ Set<PosixFilePermission> orig = attrs.permissions();
+ Set<PosixFilePermission> newPerms = new HashSet<PosixFilePermission>(orig);
+ newPerms.remove(PosixFilePermission.OTHERS_READ);
+ newPerms.remove(PosixFilePermission.OTHERS_WRITE);
+ newPerms.remove(PosixFilePermission.OTHERS_EXECUTE);
+ file.setAttribute("posix:permissions", newPerms);
+ checkEqual(Attributes.readPosixFileAttributes(file).permissions(), newPerms);
+ file.setAttribute("posix:permissions", orig);
+ checkEqual(Attributes.readPosixFileAttributes(file).permissions(), orig);
+ file.setAttribute("posix:owner", attrs.owner());
+ file.setAttribute("posix:group", attrs.group());
+
+ // readAttributes
+ Map<String,?> map;
+ map = file.readAttributes("posix:*");
+ assertTrue(map.size() >= 12);
+ checkEqual(attrs.permissions(), map.get("permissions")); // check one
+
+ map = file.readAttributes("posix:size,owner,ShouldNotExist");
+ assertTrue(map.size() == 2);
+ checkEqual(attrs.size(), map.get("size"));
+ checkEqual(attrs.owner(), map.get("owner"));
+ }
+
+ // Exercise getAttribute/readAttributes on unix attributes
+ static void checkUnixAttributes(FileRef file) throws IOException {
+ // getAttribute
+ int mode = (Integer)file.getAttribute("unix:mode");
+ long ino = (Long)file.getAttribute("unix:ino");
+ long dev = (Long)file.getAttribute("unix:dev");
+ long rdev = (Long)file.getAttribute("unix:rdev");
+ int nlink = (Integer)file.getAttribute("unix:nlink");
+ int uid = (Integer)file.getAttribute("unix:uid");
+ int gid = (Integer)file.getAttribute("unix:gid");
+ FileTime ctime = (FileTime)file.getAttribute("unix:ctime");
+
+ // readAttributes
+ Map<String,?> map;
+ map = file.readAttributes("unix:*");
+ assertTrue(map.size() >= 20);
+
+ map = file.readAttributes("unix:size,uid,gid,ShouldNotExist");
+ assertTrue(map.size() == 3);
+ checkEqual(map.get("size"),
+ Attributes.readBasicFileAttributes(file).size());
+ }
+
+ // Exercise getAttribute/setAttribute on dos attributes
+ static void checkDosAttributes(FileRef file, DosFileAttributes attrs)
+ throws IOException
+ {
+ checkBasicAttributes(file, attrs);
+
+ // getAttribute
+ checkEqual(attrs.isReadOnly(), file.getAttribute("dos:readonly"));
+ checkEqual(attrs.isHidden(), file.getAttribute("dos:hidden"));
+ checkEqual(attrs.isSystem(), file.getAttribute("dos:system"));
+ checkEqual(attrs.isArchive(), file.getAttribute("dos:archive"));
+
+ // setAttribute
+ boolean value;
+
+ value = attrs.isReadOnly();
+ file.setAttribute("dos:readonly", !value);
+ checkEqual(Attributes.readDosFileAttributes(file).isReadOnly(), !value);
+ file.setAttribute("dos:readonly", value);
+ checkEqual(Attributes.readDosFileAttributes(file).isReadOnly(), value);
+
+ value = attrs.isHidden();
+ file.setAttribute("dos:hidden", !value);
+ checkEqual(Attributes.readDosFileAttributes(file).isHidden(), !value);
+ file.setAttribute("dos:hidden", value);
+ checkEqual(Attributes.readDosFileAttributes(file).isHidden(), value);
+
+ value = attrs.isSystem();
+ file.setAttribute("dos:system", !value);
+ checkEqual(Attributes.readDosFileAttributes(file).isSystem(), !value);
+ file.setAttribute("dos:system", value);
+ checkEqual(Attributes.readDosFileAttributes(file).isSystem(), value);
+
+ value = attrs.isArchive();
+ file.setAttribute("dos:archive", !value);
+ checkEqual(Attributes.readDosFileAttributes(file).isArchive(), !value);
+ file.setAttribute("dos:archive", value);
+ checkEqual(Attributes.readDosFileAttributes(file).isArchive(), value);
+
+ // readAttributes
+ Map<String,?> map;
+ map = file.readAttributes("dos:*");
+ assertTrue(map.size() >= 13);
+ checkEqual(attrs.isReadOnly(), map.get("readonly")); // check one
+
+ map = file.readAttributes("dos:size,hidden,ShouldNotExist");
+ assertTrue(map.size() == 2);
+ checkEqual(attrs.size(), map.get("size"));
+ checkEqual(attrs.isHidden(), map.get("hidden"));
+ }
+
+ static void miscTests(Path file) throws IOException {
+ // NPE tests
+ try {
+ file.getAttribute(null);
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException npe) { }
+ try {
+ file.getAttribute("isRegularFile", (LinkOption[])null);
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException npe) { }
+ try {
+ file.setAttribute(null, 0L);
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException npe) { }
+ }
+
+ static void doTests(Path dir) throws IOException {
+ Path file = dir.resolve("foo").createFile();
+ FileStore store = file.getFileStore();
+ try {
+ checkBasicAttributes(file,
+ Attributes.readBasicFileAttributes(file));
+
+ if (store.supportsFileAttributeView("posix"))
+ checkPosixAttributes(file,
+ Attributes.readPosixFileAttributes(file));
+
+ if (store.supportsFileAttributeView("unix"))
+ checkUnixAttributes(file);
+
+ if (store.supportsFileAttributeView("dos"))
+ checkDosAttributes(file,
+ Attributes.readDosFileAttributes(file));
+
+ miscTests(file);
+ } finally {
+ file.delete();
+ }
+ }
+
+
+ public static void main(String[] args) throws IOException {
+ Path dir = TestUtil.createTemporaryDirectory();
+ try {
+ doTests(dir);
+ } finally {
+ TestUtil.removeAll(dir);
+ }
+ }
+}
diff --git a/test/java/nio/file/Path/Links.java b/test/java/nio/file/Path/Links.java
index 3b0d6da..a6f85be 100644
--- a/test/java/nio/file/Path/Links.java
+++ b/test/java/nio/file/Path/Links.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.Path createSymbolicLink,
* readSymbolicLink, and createLink methods
* @library ..
@@ -99,16 +99,6 @@
Object key2 = Attributes
.readBasicFileAttributes(bar).fileKey();
assertTrue((key1 == null) || (key1.equals(key2)));
-
-// Testing of linkCount disabled until linkCount method removed frmo
-// BasicFileAttributes
-/*
- assertTrue(Attributes
- .readBasicFileAttributes(foo).linkCount() >= 2);
- assertTrue(Attributes
- .readBasicFileAttributes(bar).linkCount() >= 2);
-*/
-
} finally {
bar.delete();
}
diff --git a/test/java/nio/file/Path/Misc.java b/test/java/nio/file/Path/Misc.java
index ba6640f..066cf6b 100644
--- a/test/java/nio/file/Path/Misc.java
+++ b/test/java/nio/file/Path/Misc.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.Path for miscellenous methods not
* covered by other tests
* @library ..
@@ -212,12 +212,7 @@
instanceof BasicFileAttributeView);
assertTrue(dir.getFileAttributeView(BasicFileAttributeView.class, NOFOLLOW_LINKS)
instanceof BasicFileAttributeView);
- assertTrue(dir.getFileAttributeView("basic")
- instanceof BasicFileAttributeView);
- assertTrue(dir.getFileAttributeView("basic", NOFOLLOW_LINKS)
- instanceof BasicFileAttributeView);
assertTrue(dir.getFileAttributeView(BogusFileAttributeView.class) == null);
- assertTrue(dir.getFileAttributeView("bogus") == null);
try {
dir.getFileAttributeView((Class<FileAttributeView>)null);
} catch (NullPointerException ignore) { }
@@ -227,15 +222,6 @@
try {
dir.getFileAttributeView(BasicFileAttributeView.class, (LinkOption)null);
} catch (NullPointerException ignore) { }
- try {
- dir.getFileAttributeView((String)null);
- } catch (NullPointerException ignore) { }
- try {
- dir.getFileAttributeView("basic", (LinkOption[])null);
- } catch (NullPointerException ignore) { }
- try {
- dir.getFileAttributeView("basic", (LinkOption)null);
- } catch (NullPointerException ignore) { }
}
interface BogusFileAttributeView extends FileAttributeView { }
@@ -272,6 +258,16 @@
}
/**
+ * Test: toRealPath(false) with broken link
+ */
+ if (supportsLinks) {
+ Path broken = dir.resolve("doesNotExist");
+ link.createSymbolicLink(broken);
+ assertTrue(link.toRealPath(false).getName().equals(link.getName()));
+ link.delete();
+ }
+
+ /**
* Test: toRealPath should eliminate "."
*/
assertTrue(dir.resolve(".").toRealPath(true).equals(dir.toRealPath(true)));
@@ -358,7 +354,7 @@
}
}
} finally {
- thisFile.delete(false);
+ thisFile.delete();
}
}
@@ -372,7 +368,7 @@
if (isWindows) {
file.createFile();
try {
- Attributes.setAttribute(file, "dos:hidden", true);
+ file.setAttribute("dos:hidden", true);
assertTrue(file.isHidden());
} finally {
file.delete();
diff --git a/test/java/nio/file/Path/PathOps.java b/test/java/nio/file/Path/PathOps.java
index 231123c..6482d5e 100644
--- a/test/java/nio/file/Path/PathOps.java
+++ b/test/java/nio/file/Path/PathOps.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.Path path operations
*/
@@ -687,7 +687,17 @@
.normalize("/foo");
// invalid
- test("foo\u0000\bar")
+ test("foo\u0000bar")
+ .invalid();
+ test("\u0000foo")
+ .invalid();
+ test("bar\u0000")
+ .invalid();
+ test("//foo\u0000bar")
+ .invalid();
+ test("//\u0000foo")
+ .invalid();
+ test("//bar\u0000")
.invalid();
// normalization
diff --git a/test/java/nio/file/Path/TemporaryFiles.java b/test/java/nio/file/Path/TemporaryFiles.java
index 6a9d28d..59ac4ec 100644
--- a/test/java/nio/file/Path/TemporaryFiles.java
+++ b/test/java/nio/file/Path/TemporaryFiles.java
@@ -21,21 +21,30 @@
* have any questions.
*/
+/* @test
+ * @bug 4313887 6838333
+ * @summary Unit test for File.createTemporaryXXX (to be be moved to test/java/io/File)
+ * @library ..
+ */
+
import java.nio.file.*;
import static java.nio.file.StandardOpenOption.*;
import java.nio.file.attribute.*;
import java.io.File;
import java.io.IOException;
-import java.io.OutputStream;
import java.util.Set;
public class TemporaryFiles {
- static void checkFile(Path file) throws IOException {
- // check file is in temporary directory
+ static void checkInTempDirectory(Path file) {
Path tmpdir = Paths.get(System.getProperty("java.io.tmpdir"));
if (!file.getParent().equals(tmpdir))
throw new RuntimeException("Not in temporary directory");
+ }
+
+ static void checkFile(Path file) throws IOException {
+ // check file is in temporary directory
+ checkInTempDirectory(file);
// check that file can be opened for reading and writing
file.newByteChannel(READ).close();
@@ -53,24 +62,37 @@
}
}
+ static void checkDirectory(Path dir) throws IOException {
+ // check directory is in temporary directory
+ checkInTempDirectory(dir);
+
+ // check directory is empty
+ DirectoryStream<Path> stream = dir.newDirectoryStream();
+ try {
+ if (stream.iterator().hasNext())
+ throw new RuntimeException("Tempory directory not empty");
+ } finally {
+ stream.close();
+ }
+
+ // check file permissions are 0700 or more secure
+ if (dir.getFileStore().supportsFileAttributeView("posix")) {
+ Set<PosixFilePermission> perms = Attributes
+ .readPosixFileAttributes(dir).permissions();
+ perms.remove(PosixFilePermission.OWNER_READ);
+ perms.remove(PosixFilePermission.OWNER_WRITE);
+ perms.remove(PosixFilePermission.OWNER_EXECUTE);
+ if (!perms.isEmpty())
+ throw new RuntimeException("Temporary directory is not secure");
+ }
+ }
+
public static void main(String[] args) throws IOException {
- Path file = File.createTempFile("blah", null, false).toPath();
+ Path file = File.createTemporaryFile("blah", null).toPath();
try {
checkFile(file);
} finally {
TestUtil.deleteUnchecked(file);
}
-
- // temporary file with deleteOnExit
- file = File.createTempFile("blah", "tmp", true).toPath();
- checkFile(file);
- // write path to temporary file to file so that calling script can
- // check that it is deleted
- OutputStream out = Paths.get(args[0]).newOutputStream();
- try {
- out.write(file.toString().getBytes());
- } finally {
- out.close();
- }
}
}
diff --git a/test/java/nio/file/Path/temporary_files.sh b/test/java/nio/file/Path/temporary_files.sh
deleted file mode 100644
index 552dcfd..0000000
--- a/test/java/nio/file/Path/temporary_files.sh
+++ /dev/null
@@ -1,65 +0,0 @@
-#
-# Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
-# CA 95054 USA or visit www.sun.com if you need additional information or
-# have any questions.
-#
-
-# @test
-# @bug 4313887
-# @summary Unit test for File.createTempFile (to be be moved to test/java/io/File)
-# @library ..
-# @build TemporaryFiles
-# @run shell temporary_files.sh
-
-# if TESTJAVA isn't set then we assume an interactive run.
-
-if [ -z "$TESTJAVA" ]; then
- TESTSRC=.
- TESTCLASSES=.
- JAVA=java
-else
- JAVA="${TESTJAVA}/bin/java"
-fi
-
-OS=`uname -s`
-case "$OS" in
- Windows_* )
- CLASSPATH="${TESTCLASSES};${TESTSRC}"
- ;;
- * )
- CLASSPATH=${TESTCLASSES}:${TESTSRC}
- ;;
-esac
-export CLASSPATH
-
-TMPFILENAME="$$.tmp"
-$JAVA TemporaryFiles $TMPFILENAME 2>&1
-if [ $? != 0 ]; then exit 1; fi
-if [ ! -f $TMPFILENAME ]; then
- echo "$TMPFILENAME not found"
- exit 1
-fi
-TMPFILE=`cat $TMPFILENAME`
-if [ -f $TMPFILE ]; then
- echo "$TMPFILE not deleted"
- exit 1
-fi
-
-exit 0
diff --git a/test/java/nio/file/TestUtil.java b/test/java/nio/file/TestUtil.java
index c19e28f..2436a45 100644
--- a/test/java/nio/file/TestUtil.java
+++ b/test/java/nio/file/TestUtil.java
@@ -55,7 +55,7 @@
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
try {
- file.delete(false);
+ file.delete();
} catch (IOException x) {
System.err.format("Unable to delete %s: %s\n", file, x);
}
@@ -64,7 +64,7 @@
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
try {
- dir.delete(false);
+ dir.delete();
} catch (IOException x) {
System.err.format("Unable to delete %s: %s\n", dir, x);
}
@@ -78,7 +78,7 @@
});
}
- static void deleteUnchecked(FileRef file) {
+ static void deleteUnchecked(Path file) {
try {
file.delete();
} catch (IOException exc) {
@@ -114,7 +114,7 @@
Path target = dir.resolve("testtarget");
try {
link.createSymbolicLink(target);
- target.delete(false);
+ link.delete();
return true;
} catch (UnsupportedOperationException x) {
return false;
diff --git a/test/java/nio/file/WatchService/Basic.java b/test/java/nio/file/WatchService/Basic.java
index 60c18d7..f6a501b 100644
--- a/test/java/nio/file/WatchService/Basic.java
+++ b/test/java/nio/file/WatchService/Basic.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.WatchService
* @library ..
* @run main/timeout=120 Basic
@@ -114,7 +114,7 @@
throw new RuntimeException("register did not return existing key");
System.out.format("delete %s\n", file);
- file.delete(false);
+ file.delete();
takeExpectedKey(watcher, myKey);
checkExpectedEvent(myKey.pollEvents(),
StandardWatchEventKind.ENTRY_DELETE, name);
@@ -137,7 +137,7 @@
throw new RuntimeException("register did not return existing key");
System.out.format("update: %s\n", file);
- OutputStream out = file.newOutputStream(EnumSet.of(StandardOpenOption.APPEND));
+ OutputStream out = file.newOutputStream(StandardOpenOption.APPEND);
try {
out.write("I am a small file".getBytes("UTF-8"));
} finally {
@@ -151,7 +151,7 @@
System.out.println("OKAY");
// done
- file.delete(false);
+ file.delete();
} finally {
watcher.close();
@@ -190,7 +190,7 @@
}
// done
- file.delete(false);
+ file.delete();
System.out.println("OKAY");
@@ -216,7 +216,7 @@
new WatchEvent.Kind<?>[]{ ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY });
System.out.format("delete: %s\n", subdir);
- subdir.delete(false);
+ subdir.delete();
takeExpectedKey(watcher, myKey);
System.out.println("reset key");
@@ -439,7 +439,7 @@
throw new RuntimeException("key not expected");
// delete gus1
- file1.delete(false);
+ file1.delete();
// check that key2 got ENTRY_DELETE
takeExpectedKey(watcher2, key2);
diff --git a/test/java/nio/file/WatchService/FileTreeModifier.java b/test/java/nio/file/WatchService/FileTreeModifier.java
index 741c86d..c47cc34 100644
--- a/test/java/nio/file/WatchService/FileTreeModifier.java
+++ b/test/java/nio/file/WatchService/FileTreeModifier.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Sanity test for Sun-specific FILE_TREE watch event modifier
* @library ..
*/
@@ -85,7 +85,7 @@
throw new RuntimeException("Existing key not returned");
// delete a/b/c/foo and check we get delete event
- file.delete(false);
+ file.delete();
checkExpectedEvent(watcher, ENTRY_DELETE, top.relativize(file));
key.reset();
diff --git a/test/java/nio/file/attribute/AclFileAttributeView/Basic.java b/test/java/nio/file/attribute/AclFileAttributeView/Basic.java
index 3a99607..1456320 100644
--- a/test/java/nio/file/attribute/AclFileAttributeView/Basic.java
+++ b/test/java/nio/file/attribute/AclFileAttributeView/Basic.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.attribute.AclFileAttribueView
* @library ../..
*/
@@ -147,7 +147,10 @@
}
public static void main(String[] args) throws IOException {
- Path dir = TestUtil.createTemporaryDirectory();
+ // use work directory rather than system temporary directory to
+ // improve chances that ACLs are supported
+ Path dir = Paths.get("./work" + new Random().nextInt())
+ .createDirectory();
try {
if (!dir.getFileStore().supportsFileAttributeView("acl")) {
System.out.println("ACLs not supported - test skipped!");
diff --git a/test/java/nio/file/attribute/Attributes/Basic.java b/test/java/nio/file/attribute/Attributes/Basic.java
deleted file mode 100644
index 8dfde80..0000000
--- a/test/java/nio/file/attribute/Attributes/Basic.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-/* @test
- * @bug 4313887
- * @summary Unit test for java.nio.file.attribute.Attributes
- * @library ../..
- */
-
-import java.nio.file.*;
-import java.nio.file.attribute.*;
-import java.io.IOException;
-import java.util.*;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Exercises getAttribute/setAttribute/readAttributes methods.
- */
-
-public class Basic {
-
- static void assertTrue(boolean okay) {
- if (!okay)
- throw new RuntimeException("Assertion Failed");
- }
-
- static void checkEqual(Object o1, Object o2) {
- if (o1 == null) {
- assertTrue(o2 == null);
- } else {
- assertTrue (o1.equals(o2));
- }
- }
-
- // Exercise getAttribute/setAttribute/readAttributes on basic attributes
- static void checkBasicAttributes(FileRef file, BasicFileAttributes attrs)
- throws IOException
- {
- // getAttribute
- checkEqual(attrs.size(), Attributes.getAttribute(file, "size"));
- checkEqual(attrs.lastModifiedTime(),
- Attributes.getAttribute(file, "basic:lastModifiedTime"));
- checkEqual(attrs.lastAccessTime(),
- Attributes.getAttribute(file, "lastAccessTime"));
- checkEqual(attrs.creationTime(),
- Attributes.getAttribute(file, "basic:creationTime"));
- assertTrue((Boolean)Attributes.getAttribute(file, "isRegularFile"));
- assertTrue(!(Boolean)Attributes.getAttribute(file, "basic:isDirectory"));
- assertTrue(!(Boolean)Attributes.getAttribute(file, "isSymbolicLink"));
- assertTrue(!(Boolean)Attributes.getAttribute(file, "basic:isOther"));
- checkEqual(attrs.linkCount(),
- (Integer)Attributes.getAttribute(file, "linkCount"));
- checkEqual(attrs.fileKey(), Attributes.getAttribute(file, "basic:fileKey"));
-
- // setAttribute
- if (attrs.resolution() == TimeUnit.MILLISECONDS) {
- long modTime = attrs.lastModifiedTime();
- Attributes.setAttribute(file, "basic:lastModifiedTime", 0L);
- assertTrue(Attributes.readBasicFileAttributes(file).lastModifiedTime() == 0L);
- Attributes.setAttribute(file, "lastModifiedTime", modTime);
- assertTrue(Attributes.readBasicFileAttributes(file).lastModifiedTime() == modTime);
- }
-
- // readAttributes
- Map<String,?> map;
- map = Attributes.readAttributes(file, "*");
- assertTrue(map.size() >= 11);
- checkEqual(attrs.isRegularFile(), map.get("isRegularFile")); // check one
-
- map = Attributes.readAttributes(file, "basic:*");
- assertTrue(map.size() >= 11);
- checkEqual(attrs.lastAccessTime(), map.get("lastAccessTime")); // check one
-
- map = Attributes.readAttributes(file, "size,lastModifiedTime");
- assertTrue(map.size() == 2);
- checkEqual(attrs.size(), map.get("size"));
- checkEqual(attrs.lastModifiedTime(), map.get("lastModifiedTime"));
-
- map = Attributes.readAttributes(file,
- "basic:lastModifiedTime,lastAccessTime,linkCount,ShouldNotExist");
- assertTrue(map.size() == 3);
- checkEqual(attrs.lastModifiedTime(), map.get("lastModifiedTime"));
- checkEqual(attrs.lastAccessTime(), map.get("lastAccessTime"));
- checkEqual(attrs.lastAccessTime(), map.get("lastAccessTime"));
- }
-
- // Exercise getAttribute/setAttribute/readAttributes on posix attributes
- static void checkPosixAttributes(FileRef file, PosixFileAttributes attrs)
- throws IOException
- {
- checkBasicAttributes(file, attrs);
-
- // getAttribute
- checkEqual(attrs.permissions(),
- Attributes.getAttribute(file, "posix:permissions"));
- checkEqual(attrs.owner(),
- Attributes.getAttribute(file, "posix:owner"));
- checkEqual(attrs.group(),
- Attributes.getAttribute(file, "posix:group"));
-
- // setAttribute
- Set<PosixFilePermission> orig = attrs.permissions();
- Set<PosixFilePermission> newPerms = new HashSet<PosixFilePermission>(orig);
- newPerms.remove(PosixFilePermission.OTHERS_READ);
- newPerms.remove(PosixFilePermission.OTHERS_WRITE);
- newPerms.remove(PosixFilePermission.OTHERS_EXECUTE);
- Attributes.setAttribute(file, "posix:permissions", newPerms);
- checkEqual(Attributes.readPosixFileAttributes(file).permissions(), newPerms);
- Attributes.setAttribute(file, "posix:permissions", orig);
- checkEqual(Attributes.readPosixFileAttributes(file).permissions(), orig);
- Attributes.setAttribute(file, "posix:owner", attrs.owner());
- Attributes.setAttribute(file, "posix:group", attrs.group());
-
- // readAttributes
- Map<String,?> map;
- map = Attributes.readAttributes(file, "posix:*");
- assertTrue(map.size() >= 14);
- checkEqual(attrs.permissions(), map.get("permissions")); // check one
-
- map = Attributes.readAttributes(file, "posix:size,owner,ShouldNotExist");
- assertTrue(map.size() == 2);
- checkEqual(attrs.size(), map.get("size"));
- checkEqual(attrs.owner(), map.get("owner"));
- }
-
- // Exercise getAttribute/setAttribute/readAttributes on unix attributes
- static void checkUnixAttributes(FileRef file) throws IOException {
- // getAttribute
- int mode = (Integer)Attributes.getAttribute(file, "unix:mode");
- long ino = (Long)Attributes.getAttribute(file, "unix:ino");
- long dev = (Long)Attributes.getAttribute(file, "unix:dev");
- long rdev = (Long)Attributes.getAttribute(file, "unix:rdev");
- int uid = (Integer)Attributes.getAttribute(file, "unix:uid");
- int gid = (Integer)Attributes.getAttribute(file, "unix:gid");
- long ctime = (Long)Attributes.getAttribute(file, "unix:ctime");
-
- // readAttributes
- Map<String,?> map;
- map = Attributes.readAttributes(file, "unix:*");
- assertTrue(map.size() >= 21);
-
- map = Attributes.readAttributes(file, "unix:size,uid,gid,ShouldNotExist");
- assertTrue(map.size() == 3);
- checkEqual(map.get("size"),
- Attributes.readBasicFileAttributes(file).size());
- }
-
- // Exercise getAttribute/setAttribute/readAttributes on dos attributes
- static void checkDosAttributes(FileRef file, DosFileAttributes attrs)
- throws IOException
- {
- checkBasicAttributes(file, attrs);
-
- // getAttribute
- checkEqual(attrs.isReadOnly(),
- Attributes.getAttribute(file, "dos:readonly"));
- checkEqual(attrs.isHidden(),
- Attributes.getAttribute(file, "dos:hidden"));
- checkEqual(attrs.isSystem(),
- Attributes.getAttribute(file, "dos:system"));
- checkEqual(attrs.isArchive(),
- Attributes.getAttribute(file, "dos:archive"));
-
- // setAttribute
- boolean value;
-
- value = attrs.isReadOnly();
- Attributes.setAttribute(file, "dos:readonly", !value);
- checkEqual(Attributes.readDosFileAttributes(file).isReadOnly(), !value);
- Attributes.setAttribute(file, "dos:readonly", value);
- checkEqual(Attributes.readDosFileAttributes(file).isReadOnly(), value);
-
- value = attrs.isHidden();
- Attributes.setAttribute(file, "dos:hidden", !value);
- checkEqual(Attributes.readDosFileAttributes(file).isHidden(), !value);
- Attributes.setAttribute(file, "dos:hidden", value);
- checkEqual(Attributes.readDosFileAttributes(file).isHidden(), value);
-
- value = attrs.isSystem();
- Attributes.setAttribute(file, "dos:system", !value);
- checkEqual(Attributes.readDosFileAttributes(file).isSystem(), !value);
- Attributes.setAttribute(file, "dos:system", value);
- checkEqual(Attributes.readDosFileAttributes(file).isSystem(), value);
-
- value = attrs.isArchive();
- Attributes.setAttribute(file, "dos:archive", !value);
- checkEqual(Attributes.readDosFileAttributes(file).isArchive(), !value);
- Attributes.setAttribute(file, "dos:archive", value);
- checkEqual(Attributes.readDosFileAttributes(file).isArchive(), value);
-
- // readAttributes
- Map<String,?> map;
- map = Attributes.readAttributes(file, "dos:*");
- assertTrue(map.size() >= 15);
- checkEqual(attrs.isReadOnly(), map.get("readonly")); // check one
-
- map = Attributes.readAttributes(file, "dos:size,hidden,ShouldNotExist");
- assertTrue(map.size() == 2);
- checkEqual(attrs.size(), map.get("size"));
- checkEqual(attrs.isHidden(), map.get("hidden"));
- }
-
- static void doTests(Path dir) throws IOException {
- Path file = dir.resolve("foo").createFile();
- FileStore store = file.getFileStore();
- try {
- checkBasicAttributes(file,
- Attributes.readBasicFileAttributes(file));
-
- if (store.supportsFileAttributeView("posix"))
- checkPosixAttributes(file,
- Attributes.readPosixFileAttributes(file));
-
- if (store.supportsFileAttributeView("unix"))
- checkUnixAttributes(file);
-
- if (store.supportsFileAttributeView("dos"))
- checkDosAttributes(file,
- Attributes.readDosFileAttributes(file));
- } finally {
- file.delete();
- }
- }
-
-
- public static void main(String[] args) throws IOException {
- Path dir = TestUtil.createTemporaryDirectory();
- try {
- doTests(dir);
- } finally {
- TestUtil.removeAll(dir);
- }
- }
-}
diff --git a/test/java/nio/file/attribute/BasicFileAttributeView/Basic.java b/test/java/nio/file/attribute/BasicFileAttributeView/Basic.java
index 1cc192f..120cda3 100644
--- a/test/java/nio/file/attribute/BasicFileAttributeView/Basic.java
+++ b/test/java/nio/file/attribute/BasicFileAttributeView/Basic.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.attribute.BasicFileAttributeView
* @library ../..
*/
@@ -48,14 +48,11 @@
check(!attrs.isRegularFile(), "is not a regular file");
check(!attrs.isSymbolicLink(), "is not a link");
check(!attrs.isOther(), "is not other");
- check(attrs.linkCount() >= 1, "should be at least 1");
// last-modified-time should match java.io.File
- if (attrs.resolution() == TimeUnit.MILLISECONDS) {
- File f = new File(dir.toString());
- check(f.lastModified() == attrs.lastModifiedTime(),
- "last-modified time should be the same");
- }
+ File f = new File(dir.toString());
+ check(f.lastModified() == attrs.lastModifiedTime().toMillis(),
+ "last-modified time should be the same");
}
static void checkAttributesOfFile(Path dir, Path file)
@@ -66,30 +63,27 @@
check(!attrs.isDirectory(), "is not a directory");
check(!attrs.isSymbolicLink(), "is not a link");
check(!attrs.isOther(), "is not other");
- check(attrs.linkCount() >= 1, "should be at least 1");
// size and last-modified-time should match java.io.File
File f = new File(file.toString());
check(f.length() == attrs.size(), "size should be the same");
- if (attrs.resolution() == TimeUnit.MILLISECONDS) {
- check(f.lastModified() == attrs.lastModifiedTime(),
- "last-modified time should be the same");
- }
+ check(f.lastModified() == attrs.lastModifiedTime().toMillis(),
+ "last-modified time should be the same");
// copy last-modified time and file create time from directory to file,
// re-read attribtues, and check they match
BasicFileAttributeView view =
file.getFileAttributeView(BasicFileAttributeView.class);
BasicFileAttributes dirAttrs = Attributes.readBasicFileAttributes(dir);
- view.setTimes(dirAttrs.lastModifiedTime(), null, null, dirAttrs.resolution());
- if (dirAttrs.creationTime() != -1L) {
- view.setTimes(null, null, dirAttrs.creationTime(), dirAttrs.resolution());
+ view.setTimes(dirAttrs.lastModifiedTime(), null, null);
+ if (dirAttrs.creationTime() != null) {
+ view.setTimes(null, null, dirAttrs.creationTime());
}
attrs = view.readAttributes();
- check(attrs.lastModifiedTime() == dirAttrs.lastModifiedTime(),
+ check(attrs.lastModifiedTime().equals(dirAttrs.lastModifiedTime()),
"last-modified time should be equal");
- if (dirAttrs.creationTime() != -1L) {
- check(attrs.creationTime() == dirAttrs.creationTime(),
+ if (dirAttrs.creationTime() != null) {
+ check(attrs.creationTime().equals(dirAttrs.creationTime()),
"create time should be the same");
}
@@ -107,7 +101,6 @@
check(!attrs.isDirectory(), "is a directory");
check(!attrs.isRegularFile(), "is not a regular file");
check(!attrs.isOther(), "is not other");
- check(attrs.linkCount() >= 1, "should be at least 1");
}
static void attributeReadWriteTests(Path dir)
diff --git a/test/java/nio/file/attribute/DosFileAttributeView/Basic.java b/test/java/nio/file/attribute/DosFileAttributeView/Basic.java
index 3c8a296..28d12c7 100644
--- a/test/java/nio/file/attribute/DosFileAttributeView/Basic.java
+++ b/test/java/nio/file/attribute/DosFileAttributeView/Basic.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.attribute.DosFileAttributeView
* @library ../..
*/
@@ -75,7 +75,7 @@
// create "foo" and test that we can read/write each FAT attribute
Path file = dir.resolve("foo");
- file.newOutputStream().close();
+ file.createFile();
try {
testAttributes(file
.getFileAttributeView(DosFileAttributeView.class));
diff --git a/test/java/nio/file/attribute/FileStoreAttributeView/Basic.java b/test/java/nio/file/attribute/FileStoreAttributeView/Basic.java
index 993e8c1..13fed78 100644
--- a/test/java/nio/file/attribute/FileStoreAttributeView/Basic.java
+++ b/test/java/nio/file/attribute/FileStoreAttributeView/Basic.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.attribute.FileStoreAttributeView
* @library ../..
*/
@@ -106,43 +106,10 @@
checkWithin1GB(free, attrs.unallocatedSpace());
checkWithin1GB(usable, attrs.usableSpace());
- // get values by name (and in bulk)
- FileStoreAttributeView view = fs.getFileStoreAttributeView("space");
- checkWithin1GB(total, (Long)view.getAttribute("totalSpace"));
- checkWithin1GB(free, (Long)view.getAttribute("unallocatedSpace"));
- checkWithin1GB(usable, (Long)view.getAttribute("usableSpace"));
- Map<String,?> map = view.readAttributes("*");
- checkWithin1GB(total, (Long)map.get("totalSpace"));
- checkWithin1GB(free, (Long)map.get("unallocatedSpace"));
- checkWithin1GB(usable, (Long)map.get("usableSpace"));
- map = view.readAttributes("totalSpace", "unallocatedSpace", "usableSpace");
- checkWithin1GB(total, (Long)map.get("totalSpace"));
- checkWithin1GB(free, (Long)map.get("unallocatedSpace"));
- checkWithin1GB(usable, (Long)map.get("usableSpace"));
- }
-
- /**
- * Check (Windows-specific) volume attributes
- */
- static void checkVolumeAttributes() throws IOException {
- System.out.println(" -- volumes -- ");
- for (FileStore store: FileSystems.getDefault().getFileStores()) {
- FileStoreAttributeView view = store.getFileStoreAttributeView("volume");
- if (view == null)
- continue;
- Map<String,?> attrs = view.readAttributes("*");
- int vsn = (Integer)attrs.get("vsn");
- boolean compressed = (Boolean)attrs.get("compressed");
- boolean removable = (Boolean)attrs.get("removable");
- boolean cdrom = (Boolean)attrs.get("cdrom");
- String type;
- if (removable) type = "removable";
- else if (cdrom) type = "cdrom";
- else type = "unknown";
- System.out.format("%s (%s) vsn:%x compressed:%b%n", store.name(),
- type, vsn, compressed);
- }
-
+ // get values by name
+ checkWithin1GB(total, (Long)fs.getAttribute("space:totalSpace"));
+ checkWithin1GB(free, (Long)fs.getAttribute("space:unallocatedSpace"));
+ checkWithin1GB(usable, (Long)fs.getAttribute("space:usableSpace"));
}
public static void main(String[] args) throws IOException {
@@ -161,9 +128,6 @@
Path file = dir.resolve("foo").createFile();
checkSpace(file);
- // volume attributes (Windows specific)
- checkVolumeAttributes();
-
} finally {
TestUtil.removeAll(dir);
}
diff --git a/test/java/nio/file/attribute/FileTime/Basic.java b/test/java/nio/file/attribute/FileTime/Basic.java
new file mode 100644
index 0000000..13bebf3
--- /dev/null
+++ b/test/java/nio/file/attribute/FileTime/Basic.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 6844313
+ * @summary Unit test for java.nio.file.FileTime
+ */
+
+import java.nio.file.attribute.FileTime;
+import java.util.concurrent.TimeUnit;
+import static java.util.concurrent.TimeUnit.*;
+import java.io.IOException;
+
+public class Basic {
+
+ public static void main(String[] args) throws IOException {
+ long now = System.currentTimeMillis();
+ long tomorrowInDays = TimeUnit.DAYS.convert(now, MILLISECONDS) + 1;
+
+ // equals
+ eq(now, MILLISECONDS, now, MILLISECONDS);
+ eq(now, MILLISECONDS, now*1000L, MICROSECONDS);
+ neq(now, MILLISECONDS, 0, MILLISECONDS);
+ neq(now, MILLISECONDS, 0, MICROSECONDS);
+
+ // compareTo
+ cmp(now, MILLISECONDS, now, MILLISECONDS, 0);
+ cmp(now, MILLISECONDS, now*1000L, MICROSECONDS, 0);
+ cmp(now, MILLISECONDS, now-1234, MILLISECONDS, 1);
+ cmp(now, MILLISECONDS, now+1234, MILLISECONDS, -1);
+ cmp(tomorrowInDays, DAYS, now, MILLISECONDS, 1);
+ cmp(now, MILLISECONDS, tomorrowInDays, DAYS, -1);
+
+ // toString
+ ts(1L, DAYS, "1970-01-02T00:00:00Z");
+ ts(1L, HOURS, "1970-01-01T01:00:00Z");
+ ts(1L, MINUTES, "1970-01-01T00:01:00Z");
+ ts(1L, SECONDS, "1970-01-01T00:00:01Z");
+ ts(1L, MILLISECONDS, "1970-01-01T00:00:00.001Z");
+ ts(1L, MICROSECONDS, "1970-01-01T00:00:00.000001Z");
+ ts(1L, NANOSECONDS, "1970-01-01T00:00:00.000000001Z");
+
+ ts(-1L, DAYS, "1969-12-31T00:00:00Z");
+ ts(-1L, HOURS, "1969-12-31T23:00:00Z");
+ ts(-1L, MINUTES, "1969-12-31T23:59:00Z");
+ ts(-1L, SECONDS, "1969-12-31T23:59:59Z");
+ ts(-1L, MILLISECONDS, "1969-12-31T23:59:59.999Z");
+ ts(-1L, MICROSECONDS, "1969-12-31T23:59:59.999999Z");
+ ts(-1L, NANOSECONDS, "1969-12-31T23:59:59.999999999Z");
+
+ ts(-62135596799999L, MILLISECONDS, "0001-01-01T00:00:00.001Z");
+ ts(-62135596800000L, MILLISECONDS, "0001-01-01T00:00:00Z");
+ ts(-62135596800001L, MILLISECONDS, "-0001-12-31T23:59:59.999Z");
+
+ ts(253402300799999L, MILLISECONDS, "9999-12-31T23:59:59.999Z");
+ ts(-377642044800001L, MILLISECONDS, "-9999-12-31T23:59:59.999Z");
+
+ // NTFS epoch in usec.
+ ts(-11644473600000000L, MICROSECONDS, "1601-01-01T00:00:00Z");
+
+ // nulls
+ try {
+ FileTime.from(0L, null);
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException npe) { }
+ FileTime time = FileTime.fromMillis(now);
+ if (time.equals(null))
+ throw new RuntimeException("should not be equal to null");
+ try {
+ time.compareTo(null);
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException npe) { }
+ }
+
+ static void cmp(long v1, TimeUnit u1, long v2, TimeUnit u2, int expected) {
+ int result = FileTime.from(v1, u1).compareTo(FileTime.from(v2, u2));
+ if (result != expected)
+ throw new RuntimeException("unexpected order");
+ }
+
+ static void eq(long v1, TimeUnit u1, long v2, TimeUnit u2) {
+ FileTime t1 = FileTime.from(v1, u1);
+ FileTime t2 = FileTime.from(v2, u2);
+ if (!t1.equals(t2))
+ throw new RuntimeException("not equal");
+ if (t1.hashCode() != t2.hashCode())
+ throw new RuntimeException("hashCodes should be equal");
+ }
+
+ static void neq(long v1, TimeUnit u1, long v2, TimeUnit u2) {
+ FileTime t1 = FileTime.from(v1, u1);
+ FileTime t2 = FileTime.from(v2, u2);
+ if (t1.equals(t2))
+ throw new RuntimeException("should not be equal");
+ }
+
+ static void ts(long v, TimeUnit y, String expected) {
+ String s = FileTime.from(v, y).toString();
+ if (!s.equals(expected))
+ throw new RuntimeException("unexpected format");
+ }
+}
diff --git a/test/java/nio/file/attribute/PosixFileAttributeView/Basic.java b/test/java/nio/file/attribute/PosixFileAttributeView/Basic.java
index 2ee059b..2b518bd 100644
--- a/test/java/nio/file/attribute/PosixFileAttributeView/Basic.java
+++ b/test/java/nio/file/attribute/PosixFileAttributeView/Basic.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.attribute.PosixFileAttributeView
* @library ../..
*/
@@ -44,15 +44,14 @@
* Use view to update permission to the given mode and check that the
* permissions have been updated.
*/
- static void testPermissions(PosixFileAttributeView view, String mode)
- throws IOException
- {
+ static void testPermissions(Path file, String mode) throws IOException {
System.out.format("change mode: %s\n", mode);
Set<PosixFilePermission> perms = PosixFilePermissions.fromString(mode);
// change permissions and re-read them.
- view.setPermissions(perms);
- Set<PosixFilePermission> current = view.readAttributes().permissions();
+ Attributes.setPosixFilePermissions(file, perms);
+ Set<PosixFilePermission> current = Attributes
+ .readPosixFileAttributes(file).permissions();
if (!current.equals(perms)) {
throw new RuntimeException("Actual permissions: " +
PosixFilePermissions.toString(current) + ", expected: " +
@@ -60,8 +59,8 @@
}
// repeat test using setAttribute/getAttribute
- view.setAttribute("permissions", perms);
- current = (Set<PosixFilePermission>)view.getAttribute("permissions");
+ file.setAttribute("posix:permissions", perms);
+ current = (Set<PosixFilePermission>)file.getAttribute("posix:permissions");
if (!current.equals(perms)) {
throw new RuntimeException("Actual permissions: " +
PosixFilePermissions.toString(current) + ", expected: " +
@@ -98,17 +97,14 @@
FileAttribute<Set<PosixFilePermission>> attr =
PosixFilePermissions.asFileAttribute(requested);
System.out.format("create file with mode: %s\n", mode);
-
- EnumSet<StandardOpenOption> options = EnumSet.of(StandardOpenOption.CREATE_NEW,
- StandardOpenOption.WRITE);
- file.newOutputStream(options, attr).close();
+ file.createFile(attr);
try {
checkSecure(requested, file
.getFileAttributeView(PosixFileAttributeView.class)
.readAttributes()
.permissions());
} finally {
- file.delete(false);
+ file.delete();
}
System.out.format("create directory with mode: %s\n", mode);
@@ -119,7 +115,7 @@
.readAttributes()
.permissions());
} finally {
- file.delete(false);
+ file.delete();
}
}
@@ -134,7 +130,7 @@
// create file and test updating and reading its permissions
Path file = dir.resolve("foo");
System.out.format("create %s\n", file);
- file.newOutputStream().close();
+ file.createFile();
try {
// get initial permissions so that we can restore them later
PosixFileAttributeView view = file
@@ -144,32 +140,32 @@
// test various modes
try {
- testPermissions(view, "---------");
- testPermissions(view, "r--------");
- testPermissions(view, "-w-------");
- testPermissions(view, "--x------");
- testPermissions(view, "rwx------");
- testPermissions(view, "---r-----");
- testPermissions(view, "----w----");
- testPermissions(view, "-----x---");
- testPermissions(view, "---rwx---");
- testPermissions(view, "------r--");
- testPermissions(view, "-------w-");
- testPermissions(view, "--------x");
- testPermissions(view, "------rwx");
- testPermissions(view, "r--r-----");
- testPermissions(view, "r--r--r--");
- testPermissions(view, "rw-rw----");
- testPermissions(view, "rwxrwx---");
- testPermissions(view, "rw-rw-r--");
- testPermissions(view, "r-xr-x---");
- testPermissions(view, "r-xr-xr-x");
- testPermissions(view, "rwxrwxrwx");
+ testPermissions(file, "---------");
+ testPermissions(file, "r--------");
+ testPermissions(file, "-w-------");
+ testPermissions(file, "--x------");
+ testPermissions(file, "rwx------");
+ testPermissions(file, "---r-----");
+ testPermissions(file, "----w----");
+ testPermissions(file, "-----x---");
+ testPermissions(file, "---rwx---");
+ testPermissions(file, "------r--");
+ testPermissions(file, "-------w-");
+ testPermissions(file, "--------x");
+ testPermissions(file, "------rwx");
+ testPermissions(file, "r--r-----");
+ testPermissions(file, "r--r--r--");
+ testPermissions(file, "rw-rw----");
+ testPermissions(file, "rwxrwx---");
+ testPermissions(file, "rw-rw-r--");
+ testPermissions(file, "r-xr-x---");
+ testPermissions(file, "r-xr-xr-x");
+ testPermissions(file, "rwxrwxrwx");
} finally {
view.setPermissions(save);
}
} finally {
- file.delete(false);
+ file.delete();
}
// create link (to file that doesn't exist) and test reading of
@@ -185,7 +181,7 @@
throw new RuntimeException("not a link");
}
} finally {
- link.delete(false);
+ link.delete();
}
}
@@ -239,7 +235,7 @@
Path file = dir.resolve("gus");
System.out.format("create %s\n", file);
- file.newOutputStream().close();
+ file.createFile();
try {
// read attributes of directory to get owner/group
@@ -251,13 +247,14 @@
view.setOwner(attrs.owner());
view.setGroup(attrs.group());
- // repeat test using setAttribute
- Map<String,?> map = view.readAttributes("owner","group");
- view.setAttribute("owner", map.get("owner"));
- view.setAttribute("group", map.get("group"));
+ // repeat test using set/getAttribute
+ UserPrincipal owner = (UserPrincipal)file.getAttribute("posix:owner");
+ file.setAttribute("posix:owner", owner);
+ UserPrincipal group = (UserPrincipal)file.getAttribute("posix:group");
+ file.setAttribute("posix:group", group);
} finally {
- file.delete(false);
+ file.delete();
}
System.out.println("OKAY");
diff --git a/test/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java b/test/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java
index ffdb5b8..b540e22 100644
--- a/test/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java
+++ b/test/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887
+ * @bug 4313887 6838333
* @summary Unit test for java.nio.file.attribute.UserDefinedFileAttributeView
* @library ../..
*/
@@ -129,23 +129,24 @@
throw new RuntimeException("Attribute name in list");
// Test: dynamic access
+ String name = "user:" + ATTR_NAME;
byte[] valueAsBytes = ATTR_VALUE.getBytes();
- view.setAttribute(ATTR_NAME, valueAsBytes);
- byte[] actualAsBytes = (byte[])view.getAttribute(ATTR_NAME);
+ file.setAttribute(name, valueAsBytes);
+ byte[] actualAsBytes = (byte[])file.getAttribute(name);
if (!Arrays.equals(valueAsBytes, actualAsBytes))
throw new RuntimeException("Unexpected attribute value");
- Map<String,?> map = view.readAttributes(ATTR_NAME);
+ Map<String,?> map = file.readAttributes(name);
if (!Arrays.equals(valueAsBytes, (byte[])map.get(ATTR_NAME)))
throw new RuntimeException("Unexpected attribute value");
- map = view.readAttributes(ATTR_NAME, "*");
+ map = file.readAttributes("user:*");
if (!Arrays.equals(valueAsBytes, (byte[])map.get(ATTR_NAME)))
throw new RuntimeException("Unexpected attribute value");
- map = view.readAttributes("DoesNotExist");
+ map = file.readAttributes("user:DoesNotExist");
if (!map.isEmpty())
throw new RuntimeException("Map expected to be empty");
}
- static void miscTests(Path file) throws IOException {
+ static void miscTests(final Path file) throws IOException {
final UserDefinedFileAttributeView view = file
.getFileAttributeView(UserDefinedFileAttributeView.class);
view.write(ATTR_NAME, ByteBuffer.wrap(ATTR_VALUE.getBytes()));
@@ -179,27 +180,31 @@
}});
expectNullPointerException(new Task() {
public void run() throws IOException {
- view.getAttribute(null);
+ file.getAttribute(null);
}});
expectNullPointerException(new Task() {
public void run() throws IOException {
- view.setAttribute(ATTR_NAME, null);
+ file.getAttribute("user:" + ATTR_NAME, (LinkOption[])null);
}});
expectNullPointerException(new Task() {
public void run() throws IOException {
- view.setAttribute(null, new byte[0]);
- }});
- expectNullPointerException(new Task() {
- public void run() throws IOException {
- view.readAttributes(null);
+ file.setAttribute("user:" + ATTR_NAME, null);
}});
expectNullPointerException(new Task() {
public void run() throws IOException {
- view.readAttributes("*", (String[])null);
+ file.setAttribute(null, new byte[0]);
}});
expectNullPointerException(new Task() {
public void run() throws IOException {
- view.readAttributes("*", ATTR_NAME, null);
+ file.setAttribute("user: " + ATTR_NAME, new byte[0], (LinkOption[])null);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ file.readAttributes((String)null);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ file.readAttributes("*", (LinkOption[])null);
}});
// Read-only buffer
@@ -224,7 +229,7 @@
// create temporary directory to run tests
Path dir = TestUtil.createTemporaryDirectory();
try {
- if (!dir.getFileStore().supportsFileAttributeView("xattr")) {
+ if (!dir.getFileStore().supportsFileAttributeView("user")) {
System.out.println("UserDefinedFileAttributeView not supported - skip test");
return;
}