Package java.nio.file.attribute

Examples of java.nio.file.attribute.BasicFileAttributeView


        private Object[] doUTimes(Path path, double atime, double mtime, boolean nofollow)
            throws NodeOSException
        {
            try {
                BasicFileAttributeView attrView;
                if (nofollow) {
                    attrView = Files.getFileAttributeView(path, BasicFileAttributeView.class,
                                                          LinkOption.NOFOLLOW_LINKS);
                } else {
                    attrView = Files.getFileAttributeView(path, BasicFileAttributeView.class);
                }

                BasicFileAttributes attrs = attrView.readAttributes();
                // The timestamp seems to come from JavaScript as a decimal value of seconds
                FileTime newATime = FileTime.fromMillis((long)(atime * 1000.0));
                FileTime newMTime = FileTime.fromMillis((long)(mtime * 1000.0));
                attrView.setTimes(newMTime, newATime, attrs.creationTime());
            } catch (IOException ioe) {
                throw new NodeOSException(getErrorCode(ioe), ioe, path.toString());
            }
            return new Object[] { Context.getUndefinedValue(), Context.getUndefinedValue() };
        }
View Full Code Here


  @Test
  public void testOpenFileAttributeViewsThrow() throws IOException {
    Path p = fs.getPath("/foo");
    Files.createFile(p);

    BasicFileAttributeView view = Files.getFileAttributeView(p, BasicFileAttributeView.class);

    fs.close();

    try {
      view.readAttributes();
      fail();
    } catch (ClosedFileSystemException expected) {
    }

    try {
      view.setTimes(null, null, null);
      fail();
    } catch (ClosedFileSystemException expected) {
    }
  }
View Full Code Here

    assertSetFailsOnCreate("lastAccessTime", time);
  }

  @Test
  public void testView() throws IOException {
    BasicFileAttributeView view = provider.view(fileLookup(), NO_INHERITED_VIEWS);

    assertThat(view).isNotNull();
    assertThat(view.name()).isEqualTo("basic");

    BasicFileAttributes attrs = view.readAttributes();
    assertThat(attrs.fileKey()).isEqualTo(0);

    FileTime time = attrs.creationTime();
    assertThat(attrs.lastAccessTime()).isEqualTo(time);
    assertThat(attrs.lastModifiedTime()).isEqualTo(time);

    view.setTimes(null, null, null);

    attrs = view.readAttributes();
    assertThat(attrs.creationTime()).isEqualTo(time);
    assertThat(attrs.lastAccessTime()).isEqualTo(time);
    assertThat(attrs.lastModifiedTime()).isEqualTo(time);

    view.setTimes(FileTime.fromMillis(0L), null, null);

    attrs = view.readAttributes();
    assertThat(attrs.creationTime()).isEqualTo(time);
    assertThat(attrs.lastAccessTime()).isEqualTo(time);
    assertThat(attrs.lastModifiedTime()).isEqualTo(FileTime.fromMillis(0L));
  }
View Full Code Here

    Files.createDirectory(path("/foo/bar"));
    SecureDirectoryStream<Path> stream =
        (SecureDirectoryStream<Path>) Files.newDirectoryStream(path("/foo"));

    Iterator<Path> iter = stream.iterator();
    BasicFileAttributeView view1 = stream.getFileAttributeView(BasicFileAttributeView.class);
    BasicFileAttributeView view2 = stream.getFileAttributeView(
        path("bar"), BasicFileAttributeView.class);

    try {
      stream.iterator();
      fail("expected IllegalStateException");
    } catch (IllegalStateException expected) {
    }

    stream.close();

    try {
      iter.next();
      fail("expected ClosedDirectoryStreamException");
    } catch (ClosedDirectoryStreamException expected) {
    }

    try {
      view1.readAttributes();
      fail("expected ClosedDirectoryStreamException");
    } catch (ClosedDirectoryStreamException expected) {
    }

    try {
      view2.readAttributes();
      fail("expected ClosedDirectoryStreamException");
    } catch (ClosedDirectoryStreamException expected) {
    }

    try {
      view1.setTimes(null, null, null);
      fail("expected ClosedDirectoryStreamException");
    } catch (ClosedDirectoryStreamException expected) {
    }

    try {
      view2.setTimes(null, null, null);
      fail("expected ClosedDirectoryStreamException");
    } catch (ClosedDirectoryStreamException expected) {
    }
  }
View Full Code Here

    /**
     * Prints detailed information for specified file.
     */
    private void listFile(@NotNull final Path path, @NotNull final PrintWriter writer) throws IOException {

        final BasicFileAttributeView view = Files.getFileAttributeView(
                path, BasicFileAttributeView.class);

        final BasicFileAttributes attrs = view.readAttributes();
        final String timeStr = DateUtils.format(attrs.lastModifiedTime());

        // As not all the file systems support POSIX file permissions,
        // we don't try to retrieve them + retrieving such information
        // for each file, can entail performance degradation.
View Full Code Here

TOP

Related Classes of java.nio.file.attribute.BasicFileAttributeView

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.