Example usage for java.nio.file Files createDirectory

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

Introduction

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

Prototype

public static Path createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException 

Source Link

Document

Creates a new directory.

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:org.kie.workbench.common.migration.cli.RealSystemAccess.java

@Override
public Path createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException {
    return Files.createDirectory(dir, attrs);
}

From source file:org.elassandra.index.ElasticSecondaryIndex.java

/**
 * Cassandra table snapshot => hard links associated elasticsearch lucene files.
 *///ww  w  .  ja  v a 2 s .  c om
@SuppressForbidden(reason = "File used for snapshots")
public Callable<?> getSnapshotWithoutFlushTask(String snapshotName) {
    return () -> {
        if (isIndexing()) {
            for (ImmutableMappingInfo.ImmutableIndexInfo indexInfo : mappingInfo.indices) {
                IndexShard indexShard = indexInfo.indexService.shard(0);
                if (indexShard != null && indexInfo.snapshot) {
                    if (indexShard.state() == IndexShardState.STARTED) {
                        // snapshotPath = data/elasticsearch.data/<cluster_name>/nodes/0/snapshots
                        Path snapshotPath = indexShard.shardPath().resolveSnapshot();
                        if ((Files.notExists(snapshotPath)))
                            Files.createDirectory(snapshotPath, snapshotDirPermissions);

                        // snapshotIndex = data/elasticsearch.data/<cluster_name>/nodes/0/snapshots/<index_name>
                        Path snapshotIndex = snapshotPath.resolve(indexShard.shardId().getIndex());
                        if ((Files.notExists(snapshotIndex)))
                            Files.createDirectory(snapshotIndex, snapshotDirPermissions);

                        // snapshotDir = data/elasticsearch.data/<cluster_name>/nodes/0/snapshots/<index_name>/<snapshot_name>
                        Path snapshotDir = Files.createDirectory(snapshotIndex.resolve(snapshotName),
                                snapshotDirPermissions);
                        Path indexPath = indexShard.shardPath().resolveIndex();

                        try (DirectoryStream<Path> stream = Files.newDirectoryStream(indexPath,
                                "{_*.*,segments*}")) {
                            for (Path luceneFile : stream) {
                                File targetLink = new File(snapshotDir.toFile(),
                                        luceneFile.getFileName().toString());
                                FileUtils.createHardLink(luceneFile.toFile(), targetLink);
                            }
                            if (logger.isDebugEnabled())
                                logger.debug("Elasticsearch index=[{}], snapshot=[{}], path=[{}]",
                                        indexInfo.name, snapshotName, snapshotDir.toString());
                        } catch (DirectoryIteratorException ex) {
                            logger.error("Failed to retreive lucene files in {}", ex, indexPath);
                        }
                    } else {
                        if (logger.isDebugEnabled())
                            logger.debug("Cannot snapshot index=[{}], state=[{}], snapshot=[{}]",
                                    indexInfo.name, indexShard.state(), snapshotName);
                    }
                }
            }
        }
        return null;
    };
}