Package java.nio.file.attribute

Examples of java.nio.file.attribute.BasicFileAttributes


                                                          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


    }

    @Override
    public long getCreation() {
        try {
            BasicFileAttributes attrs = Files.readAttributes(resource.toPath(),
                    BasicFileAttributes.class);
            return attrs.creationTime().toMillis();
        } catch (IOException e) {
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("fileResource.getCreationFail",
                        resource.getPath()), e);
            }
View Full Code Here


    @Override
    public long getCreation() {
        try {
            BasicFileAttributes attrs = Files.readAttributes(resource.toPath(),
                    BasicFileAttributes.class);
            return attrs.creationTime().toMillis();
        } catch (IOException e) {
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("fileResource.getCreationFail",
                        resource.getPath()), e);
            }
View Full Code Here

        assertThat(node.getProperty("jcr:created").getLong(), is(createdTimeFor(dir)));
    }

    protected long createdTimeFor( File file ) throws IOException {
        Path path = java.nio.file.Paths.get(file.toURI());
        BasicFileAttributes basicFileAttributes = Files.readAttributes(path, BasicFileAttributes.class);
        return basicFileAttributes.creationTime().toMillis();
    }
View Full Code Here

        // Return the document ...
        return writer.document();
    }

    private DateTime createdTimeFor( File file ) {
        BasicFileAttributes basicFileAttributes = basicAttributesFor(file);
        return basicFileAttributes != null ? factories().getDateFactory().create(basicFileAttributes.creationTime().toMillis()) : factories().getDateFactory()
                                                                                                                                             .create(file.lastModified());
    }
View Full Code Here

        return basicFileAttributes != null ? factories().getDateFactory().create(basicFileAttributes.creationTime().toMillis()) : factories().getDateFactory()
                                                                                                                                             .create(file.lastModified());
    }

    private DateTime lastModifiedTimeFor( File file ) {
        BasicFileAttributes basicFileAttributes = basicAttributesFor(file);
        return basicFileAttributes != null ? factories().getDateFactory().create(basicFileAttributes.lastModifiedTime()
                                                                                                    .toMillis()) : factories().getDateFactory()
                                                                                                                              .create(file.lastModified());
    }
View Full Code Here

  @Test
  public void testReadAttributes_asObject() {
    File file = Directory.create(0);
    service.setInitialAttributes(file);

    BasicFileAttributes basicAttrs = service.readAttributes(file, BasicFileAttributes.class);
    assertThat(basicAttrs.fileKey()).isEqualTo(0);
    assertThat(basicAttrs.isDirectory()).isTrue();
    assertThat(basicAttrs.isRegularFile()).isFalse();

    TestAttributes testAttrs = service.readAttributes(file, TestAttributes.class);
    assertThat(testAttrs.foo()).isEqualTo("hello");
    assertThat(testAttrs.bar()).is(0);
    assertThat(testAttrs.baz()).is(1);
View Full Code Here

    private FileTime modifiedTime;

    FileTimeTester(Path path) throws IOException {
      this.path = path;

      BasicFileAttributes attrs = attrs();
      accessTime = attrs.lastAccessTime();
      modifiedTime = attrs.lastModifiedTime();
    }
View Full Code Here

    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

    assertThat(attrs.lastModifiedTime()).isEqualTo(FileTime.fromMillis(0L));
  }

  @Test
  public void testAttributes() {
    BasicFileAttributes attrs = provider.readAttributes(file);
    assertThat(attrs.fileKey()).isEqualTo(0);
    assertThat(attrs.isDirectory()).isTrue();
    assertThat(attrs.isRegularFile()).isFalse();
    assertThat(attrs.creationTime()).isNotNull();
  }
View Full Code Here

TOP

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

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.