Example usage for java.nio.file.attribute PosixFilePermissions asFileAttribute

List of usage examples for java.nio.file.attribute PosixFilePermissions asFileAttribute

Introduction

In this page you can find the example usage for java.nio.file.attribute PosixFilePermissions asFileAttribute.

Prototype

public static FileAttribute<Set<PosixFilePermission>> asFileAttribute(Set<PosixFilePermission> perms) 

Source Link

Document

Creates a FileAttribute , encapsulating a copy of the given file permissions, suitable for passing to the java.nio.file.Files#createFile createFile or java.nio.file.Files#createDirectory createDirectory methods.

Usage

From source file:Test.java

public static void main(String[] args) throws Exception {
    FileSystem fileSystem = FileSystems.getDefault();
    Path directory = fileSystem.getPath("./newDirectoryWPermissions");
    Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-x---");
    FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);
    Files.createDirectory(directory, attr);
}

From source file:Main.java

public static void main(String[] args) {

    Path newfile_2 = FileSystems.getDefault().getPath("/home/tutorial/Java/2010/demo.txt");

    //create a file with a set of specified attributes
    Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rw-------");
    FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);
    try {// w w w.  j a va2s  .c  om
        Files.createFile(newfile_2, attr);
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    Path path = Paths.get("c:/home/tutorial/Java/JavaFX/Topic.txt");
    Path new_path = Paths.get("/home/tutorial/Java/JavaFX/new_Topic.txt");
    PosixFileAttributes attr = Files.readAttributes(path, PosixFileAttributes.class);
    attr = Files.getFileAttributeView(path, PosixFileAttributeView.class).readAttributes();

    //use of asFileAttribute
    FileAttribute<Set<PosixFilePermission>> posixattrs = PosixFilePermissions
            .asFileAttribute(attr.permissions());
    try {//from ww w. j av  a  2 s. c o  m
        Files.createFile(new_path, posixattrs);
    } catch (IOException e) {
        System.err.println(e);
    }
}

From source file:net.certiv.antlr.project.util.Utils.java

/**
 * Creates a new, unique directory, with the given prefix, in the system temp directory.
 * /*from  w  ww.ja  va2  s  .  c o  m*/
 * @return a File representing the new directory
 * @throws IOException
 */
public static File createTmpDir() throws IOException {
    Path p = null;
    if (Strings.pathSepStr == Strings.STD_SEPARATOR) {
        Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-x---");
        FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);
        p = Files.createTempDirectory("ReGen", attr);
    } else {
        p = Files.createTempDirectory("ReGen");
    }
    return p.toFile();
}

From source file:com.kamike.misc.FsUtils.java

public static void createDir(String dstPath) {
    Properties props = System.getProperties(); //    
    String osName = props.getProperty("os.name"); //???   
    Path newdir = FileSystems.getDefault().getPath(dstPath);

    boolean pathExists = Files.exists(newdir, new LinkOption[] { LinkOption.NOFOLLOW_LINKS });
    if (!pathExists) {
        Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxrwxrwx");
        FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);
        try {/*from   w  w w.ja  va  2 s.c o  m*/
            if (!osName.contains("Windows")) {
                Files.createDirectories(newdir, attr);
            } else {
                Files.createDirectories(newdir);
            }
        } catch (Exception e) {
            System.err.println(e);

        }
    }
}

From source file:com.olacabs.fabric.compute.builder.impl.HttpJarDownloader.java

public HttpJarDownloader() throws Exception {
    FileAttribute<Set<PosixFilePermission>> perms = PosixFilePermissions
            .asFileAttribute(PosixFilePermissions.fromString("rwxr-xr-x"));
    Path createdPath = Files.createTempDirectory(null, perms);
    this.tmpDirectory = createdPath.toAbsolutePath().toString();

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(20);/*from w ww  . j  av a2  s  . com*/

    httpClient = HttpClients.custom().setConnectionManager(cm).build();
}

From source file:org.ulyssis.ipp.publisher.FileOutput.java

@Override
public void outputScore(Score score) {
    Path tmpFile = null;/*from w w w. j a  v a2  s.c  o  m*/
    try {
        if (tmpDir.isPresent()) {
            tmpFile = Files.createTempFile(tmpDir.get(), "score-", ".json",
                    PosixFilePermissions.asFileAttribute(defaultPerms));
        } else {
            tmpFile = Files.createTempFile("score-", ".json",
                    PosixFilePermissions.asFileAttribute(defaultPerms));
        }
        BufferedWriter writer = Files.newBufferedWriter(tmpFile, StandardCharsets.UTF_8);
        Serialization.getJsonMapper().writer(new DefaultPrettyPrinter()).writeValue(writer, score);
        Files.move(tmpFile, filePath, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        LOG.error("Error writing score to file!", e);
    } finally {
        try {
            if (tmpFile != null)
                Files.deleteIfExists(tmpFile);
        } catch (IOException ignored) {
        }
    }
}

From source file:com.collective.celos.ci.mode.TestTask.java

private static FileAttribute<Set<PosixFilePermission>> getTempDirAttributes() {
    return PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr-xr-x"));
}

From source file:org.roda.core.plugins.PluginReportContentTest.java

@BeforeClass
public static void setUp() throws Exception {
    basePath = TestsHelper.createBaseTempDir(PluginReportContentTest.class, true,
            PosixFilePermissions.asFileAttribute(new HashSet<>(Arrays.asList(PosixFilePermission.OWNER_READ,
                    PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE,
                    PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_EXECUTE))));

    boolean deploySolr = true;
    boolean deployLdap = true;
    boolean deployFolderMonitor = true;
    boolean deployOrchestrator = true;
    boolean deployPluginManager = true;
    boolean deployDefaultResources = false;
    RodaCoreFactory.instantiateTest(deploySolr, deployLdap, deployFolderMonitor, deployOrchestrator,
            deployPluginManager, deployDefaultResources);

    model = RodaCoreFactory.getModelService();
    index = RodaCoreFactory.getIndexService();

    LOGGER.debug("Running index tests under storage {}", basePath);
}

From source file:org.apache.spark.sql.hive.thriftserver.rsc.RSCDriver.java

public RSCDriver(SparkConf conf, RSCConf livyConf) throws Exception {
    Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwx------");
    this.localTmpDir = Files.createTempDirectory("rsc-tmp", PosixFilePermissions.asFileAttribute(perms))
            .toFile();/*from  w w  w.  j a va  2s.c  o  m*/
    this.executor = Executors.newCachedThreadPool();
    this.clients = new ConcurrentLinkedDeque<>();

    this.conf = conf;
    this.livyConf = livyConf;
    this.jcLock = new Object();
    this.shutdownLock = new Object();

    this.idleTimeout = new AtomicReference<>();
}