FileAttributes.java revision 3909
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * This code is free software; you can redistribute it and/or modify it
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * under the terms of the GNU General Public License version 2 only, as
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * published by the Free Software Foundation.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * This code is distributed in the hope that it will be useful, but WITHOUT
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * version 2 for more details (a copy is included in the LICENSE file that
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * accompanied this code).
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * You should have received a copy of the GNU General Public License version
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * 2 along with this work; if not, write to the Free Software Foundation,
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * or visit www.oracle.com if you need additional information or have any
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * questions.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * @bug 4313887 6838333 7017446
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * @summary Unit test for java.nio.file.Files
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * @library ..
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro * Exercises getAttribute/setAttribute/readAttributes methods.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro // checks that two time values are within 1s of each other
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro static void checkNearEqual(FileTime t1, FileTime t2) {
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro long diff = Math.abs(t1.toMillis() - t2.toMillis());
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro // Exercise getAttribute/setAttribute/readAttributes on basic attributes
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro static void checkBasicAttributes(Path file, BasicFileAttributes attrs)
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro // getAttribute
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro checkEqual(attrs.size(), Files.getAttribute(file, "size"));
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro checkEqual(attrs.lastModifiedTime(), Files.getAttribute(file, "basic:lastModifiedTime"));
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro checkEqual(attrs.lastAccessTime(), Files.getAttribute(file, "lastAccessTime"));
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro checkEqual(attrs.creationTime(), Files.getAttribute(file, "basic:creationTime"));
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro assertTrue((Boolean)Files.getAttribute(file, "isRegularFile"));
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro assertTrue(!(Boolean)Files.getAttribute(file, "basic:isDirectory"));
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro assertTrue(!(Boolean)Files.getAttribute(file, "isSymbolicLink"));
870e5f5a88924152aec599e51ebb5ebbb899560evenki assertTrue(!(Boolean)Files.getAttribute(file, "basic:isOther"));
870e5f5a88924152aec599e51ebb5ebbb899560evenki checkEqual(attrs.fileKey(), Files.getAttribute(file, "basic:fileKey"));
870e5f5a88924152aec599e51ebb5ebbb899560evenki // setAttribute
870e5f5a88924152aec599e51ebb5ebbb899560evenki Files.setAttribute(file, "basic:lastModifiedTime", FileTime.fromMillis(0L));
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro Files.setAttribute(file, "lastModifiedTime", modTime);
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro checkEqual(Files.getLastModifiedTime(file), modTime);
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro checkEqual(attrs.isRegularFile(), map.get("isRegularFile")); // check one
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro checkEqual(attrs.lastAccessTime(), map.get("lastAccessTime")); // check one
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro map = Files.readAttributes(file, "size,lastModifiedTime");
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro checkEqual(attrs.lastModifiedTime(), map.get("lastModifiedTime"));
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro // Exercise getAttribute/setAttribute/readAttributes on posix attributes
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro static void checkPosixAttributes(Path file, PosixFileAttributes attrs)
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro // getAttribute
// Exercise getAttribute/readAttributes on unix attributes
// Exercise getAttribute/setAttribute on dos attributes
throws IOException
boolean value;
throws IOException