Example usage for java.nio.file Files getFileAttributeView

List of usage examples for java.nio.file Files getFileAttributeView

Introduction

In this page you can find the example usage for java.nio.file Files getFileAttributeView.

Prototype

public static <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type,
        LinkOption... options) 

Source Link

Document

Returns a file attribute view of a given type.

Usage

From source file:org.eclipse.tycho.plugins.tar.TarGzArchiverTest.java

private PosixFileAttributes getPosixFileAttributes(File file) {
    try {//from w w w. ja  v a 2s.c o m
        PosixFileAttributeView attributeView = Files.getFileAttributeView(file.toPath(),
                PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
        return attributeView.readAttributes();
    } catch (Exception e) {
        Assume.assumeNoException("skip test on filesystems that do not support POSIX file attributes", e);
    }
    // never reached
    return null;
}

From source file:ch.psi.zmq.receiver.FileReceiver.java

/**
 * Recursively create directories for given user
 * //from  w  ww .j a  va  2  s  .  co  m
 * @param f
 * @param user
 * @param perms
 * @throws IOException
 */
public void mkdir(File f, UserPrincipal user, GroupPrincipal group, Set<PosixFilePermission> perms)
        throws IOException {
    if (!f.getParentFile().exists()) {
        mkdir(f.getParentFile(), user, group, perms);
    }

    logger.info("Create directory: " + f.getPath());
    f.mkdir();
    Files.setOwner(f.toPath(), user);
    Files.getFileAttributeView(f.toPath(), PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS)
            .setGroup(group);
    Files.setPosixFilePermissions(f.toPath(), perms);
}

From source file:org.duracloud.retrieval.mgmt.RetrievalWorker.java

protected void applyTimestamps(ContentStream content, File localFile) {
    FileTime createTime = convertDateToFileTime(content.getDateCreated());
    FileTime lastAccessTime = convertDateToFileTime(content.getDateLastAccessed());
    FileTime lastModTime = convertDateToFileTime(content.getDateLastModified());

    BasicFileAttributeView fileAttributeView = Files.getFileAttributeView(localFile.toPath(),
            BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
    // If any time value is null, that value is left unchanged
    try {/*w w w  . j av a 2 s.  c o  m*/
        fileAttributeView.setTimes(lastModTime, lastAccessTime, createTime);
    } catch (IOException e) {
        logger.error("Error setting timestamps for local file " + localFile.getAbsolutePath() + ": "
                + e.getMessage(), e);
    }
}