当前位置: 首页>>代码示例>>Java>>正文


Java PosixFilePermissions.asFileAttribute方法代码示例

本文整理汇总了Java中java.nio.file.attribute.PosixFilePermissions.asFileAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java PosixFilePermissions.asFileAttribute方法的具体用法?Java PosixFilePermissions.asFileAttribute怎么用?Java PosixFilePermissions.asFileAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.attribute.PosixFilePermissions的用法示例。


在下文中一共展示了PosixFilePermissions.asFileAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createLocalConfigFile

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
/**
 * Create localconf folder and properties file necessary to run build task in order to check merge integrity.
 * @param branchName
 */
public void createLocalConfigFile(String branchName) throws Exception {
  String branchPath = SvnUtils.TEMP_FOLDER + "/" + branchName;
  //create localconf directory
  String newDirectoryPath = branchPath + "/localconf";
  if ( !Files.exists( Paths.get(newDirectoryPath))) {
    Set<PosixFilePermission> permissions = PosixFilePermissions.fromString("rwxrwxrwx");
    FileAttribute<Set<PosixFilePermission>> fileAttributes = PosixFilePermissions
        .asFileAttribute(permissions);
    Files.createDirectory(Paths.get(newDirectoryPath), fileAttributes);
  }
  //copy properties template
  Files.copy(
      Paths.get(branchPath + "/common/conf/worldnettps.properties.template"),
      Paths.get(newDirectoryPath + "/worldnettps.properties"),
      StandardCopyOption.REPLACE_EXISTING);
  //setting glassfish directory in properties file
  String appServerDir = PropertiesUtil.getString("appserver.dir");
  String sedCommand = String.format(
      "sed -i '/glassfish.dir/c\\glassfish.dir=%s' localconf/worldnettps.properties", appServerDir);
  CommandExecutor.run( sedCommand, branchPath);
  logger.info("worldnettps.properties file has been created in localconf folder.");
}
 
开发者ID:lpavone,项目名称:SVNAutoMerger,代码行数:27,代码来源:Merger.java

示例2: create

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
@Override
public int create(String path, @mode_t long mode, FuseFileInfo fi) {
	try {
		Set<OpenFlags> flags = bitMaskUtil.bitMaskToSet(OpenFlags.class, fi.flags.longValue());
		LOG.info("createAndOpen {} with openOptions {}", path, flags);
		Path node = resolvePath(path);
		if (fileStore.supportsFileAttributeView(PosixFileAttributeView.class)) {
			FileAttribute<?> attrs = PosixFilePermissions.asFileAttribute(attrUtil.octalModeToPosixPermissions(mode));
			return fileHandler.createAndOpen(node, fi, attrs);
		} else {
			return fileHandler.createAndOpen(node, fi);
		}
	} catch (RuntimeException e) {
		LOG.error("create failed.", e);
		return -ErrorCodes.EIO();
	}
}
 
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:18,代码来源:ReadWriteAdapter.java

示例3: createUnixDirectories

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
public static void createUnixDirectories(
        final Permission perm,
        final Path... dirs) throws IOException {

    FileAttribute<Set<PosixFilePermission>> attr
            = PosixFilePermissions.asFileAttribute(POSIX_OWNrwx);

    switch (perm) {
        case OWNER_FULL_GROUP_EXEC:
            attr = PosixFilePermissions.asFileAttribute(POSIX_OWNrwx_GRPr_x);
            break;
        case OWNER_FULL_GROUP_EXEC_OTHER_EXEC:
            attr = PosixFilePermissions.asFileAttribute(POSIX_OWNrwx_GRPr_x_OTHr_x);
            break;
    }

    for (Path dir : dirs) {
        if (!java.nio.file.Files.exists(dir, LinkOption.NOFOLLOW_LINKS)) {
            m_logger.debug("Creating directory: {} with permissions: {}", dir, perm);
            java.nio.file.Files.createDirectories(dir, attr);
        } else {
            m_logger.debug("Directory exists: {}", dir);
        }
    }
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:26,代码来源:Files.java

示例4: createDir

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
public void createDir(String dstPath) {

        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 {
                if (osName.indexOf("Windows") == -1) {
                    Files.createDirectories(newdir, attr);
                } else {
                    Files.createDirectories(newdir);
                }
            } catch (Exception e) {
                System.err.println(e);

            }
        }
    }
 
开发者ID:hubinix,项目名称:kamike.fast,代码行数:24,代码来源:MiscUtils.java

示例5: makeDirectory

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
@Override
public void makeDirectory(String directoryPath) throws GFacException {
    Path dirPath = Paths.get(directoryPath);
    Set<PosixFilePermission> perms = new HashSet<>();
    // add permission as rwxr--r-- 744
    perms.add(PosixFilePermission.OWNER_WRITE);
    perms.add(PosixFilePermission.OWNER_READ);
    perms.add(PosixFilePermission.OWNER_EXECUTE);
    perms.add(PosixFilePermission.GROUP_READ);
    perms.add(PosixFilePermission.OTHERS_READ);
    FileAttribute<Set<PosixFilePermission>> fileAttributes = PosixFilePermissions.asFileAttribute(perms);
    try {
        Files.createDirectory(dirPath, fileAttributes);
    } catch (IOException e) {
        throw new GFacException("Error making directory", e);
    }

}
 
开发者ID:apache,项目名称:airavata,代码行数:19,代码来源:LocalRemoteCluster.java

示例6: testWriteContentsWithSpecifiedFileAttributes

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
@Test
public void testWriteContentsWithSpecifiedFileAttributes() {
  FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
  ImmutableSet<PosixFilePermission> permissions =
    ImmutableSet.of(
        PosixFilePermission.OWNER_READ,
        PosixFilePermission.GROUP_READ,
        PosixFilePermission.OTHERS_READ);
  FileAttribute<?> attribute = PosixFilePermissions.asFileAttribute(permissions);

  Path path = Paths.get("hello.txt");
  filesystem.writeContentsToPath(
      "hello world",
      Paths.get("hello.txt"),
      attribute);
  assertEquals(ImmutableSet.of(attribute), filesystem.getFileAttributesAtPath(path));
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:18,代码来源:FakeProjectFilesystemTest.java

示例7: testGeneratedProjectIsReadOnlyIfOptionSpecified

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
@Test
public void testGeneratedProjectIsReadOnlyIfOptionSpecified() throws IOException {
  ProjectGenerator projectGenerator =
      createProjectGeneratorForCombinedProject(
          ImmutableSet.of(), ImmutableSet.of(ProjectGenerator.Option.GENERATE_READ_ONLY_FILES));

  projectGenerator.createXcodeProjects();

  ImmutableSet<PosixFilePermission> permissions =
      ImmutableSet.of(
          PosixFilePermission.OWNER_READ,
          PosixFilePermission.GROUP_READ,
          PosixFilePermission.OTHERS_READ);
  FileAttribute<?> expectedAttribute = PosixFilePermissions.asFileAttribute(permissions);
  // This is lame; Java's PosixFilePermissions class doesn't
  // implement equals() or hashCode() in its FileAttribute anonymous
  // class (http://tinyurl.com/nznhfhy).  So instead of comparing
  // the sets, we have to pull out the attribute and check its value
  // for equality.
  FileAttribute<?> actualAttribute =
      Iterables.getOnlyElement(
          fakeProjectFilesystem.getFileAttributesAtPath(OUTPUT_PROJECT_FILE_PATH));
  assertEquals(expectedAttribute.value(), actualAttribute.value());
}
 
开发者ID:facebook,项目名称:buck,代码行数:25,代码来源:ProjectGeneratorTest.java

示例8: testExtractToReadOnlyDir

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
public void testExtractToReadOnlyDir() throws IOException {
    Set<PosixFilePermission> perms = PosixFilePermissions.fromString("r-xr--r--");
    FileAttribute<Set<PosixFilePermission>> atts = PosixFilePermissions.asFileAttribute(perms);
    Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName(), atts);
    jimage("extract", "--dir", tmp.toString(), getImagePath())
            .assertFailure()
            .assertShowsError();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:JImageExtractTest.java

示例9: hasReadWrite

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
@Test
public void hasReadWrite() throws IOException {
  final FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(EnumSet.of(
      PosixFilePermission.OWNER_READ,
      PosixFilePermission.OWNER_WRITE
  ));
  final Path path = createTempFile(attr);
  this.validator.ensureValid("testing", path.toString());
}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:10,代码来源:ValidFileWritableTests.java

示例10: notWritable

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
@Test
public void notWritable() throws IOException {
  final FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(EnumSet.of(
      PosixFilePermission.OWNER_READ
  ));
  final Path path = createTempFile(attr);

  assertThrows(ConfigException.class, () -> {
    this.validator.ensureValid("testing", path.toString());
  });
}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:12,代码来源:ValidFileWritableTests.java

示例11: hasReadWrite

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
@Test
public void hasReadWrite() throws IOException {
  final FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(EnumSet.of(
      PosixFilePermission.OWNER_READ,
      PosixFilePermission.OWNER_WRITE
  ));
  final Path path = createTempDirectory(attr);
  this.validator.ensureValid("testing", path.toString());
}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:10,代码来源:ValidDirectoryWritableTests.java

示例12: notWritable

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
@Test
public void notWritable() throws IOException {
  final FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(EnumSet.of(
      PosixFilePermission.OWNER_READ
  ));
  final Path path = createTempDirectory(attr);

  assertThrows(ConfigException.class, () -> {
    this.validator.ensureValid("testing", path.toString());
  });
}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:12,代码来源:ValidDirectoryWritableTests.java

示例13: ensureExists

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
public static Path ensureExists(Path folder) throws IOException {
    if (folder != null && !Files.exists(folder)) {
        if (isPosixFileSystem()) {
            Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-xr-x");
            FileAttribute<Set<PosixFilePermission>> attrs = PosixFilePermissions.asFileAttribute(perms);
            folder = Files.createDirectories(folder, attrs);
        } else {
            folder = Files.createDirectories(folder);
        }

    }
    return folder;
}
 
开发者ID:kraftek,项目名称:awsdownload,代码行数:14,代码来源:Utilities.java

示例14: doCreate

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
private SegmentProperties doCreate(String streamSegmentName) throws IOException {
    long traceId = LoggerHelpers.traceEnter(log, "create", streamSegmentName);
    FileAttribute<Set<PosixFilePermission>> fileAttributes = PosixFilePermissions.asFileAttribute(READ_WRITE_PERMISSION);

    Path path = Paths.get(config.getRoot(), streamSegmentName);
    Files.createDirectories(path.getParent());
    Files.createFile(path, fileAttributes);
    LoggerHelpers.traceLeave(log, "create", traceId);
    return this.doGetStreamSegmentInfo(streamSegmentName);
}
 
开发者ID:pravega,项目名称:pravega,代码行数:11,代码来源:FileSystemStorage.java

示例15: testGeneratedProjectIsReadOnlyIfOptionSpecified

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
@Test
public void testGeneratedProjectIsReadOnlyIfOptionSpecified() throws IOException {
  ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(
      createPartialGraphFromBuildRules(ImmutableSet.<BuildRule>of()),
      ImmutableSet.<BuildTarget>of(),
      ImmutableSet.of(ProjectGenerator.Option.GENERATE_READ_ONLY_FILES));

  projectGenerator.createXcodeProjects();

  ImmutableSet<PosixFilePermission> permissions =
    ImmutableSet.of(
        PosixFilePermission.OWNER_READ,
        PosixFilePermission.GROUP_READ,
        PosixFilePermission.OTHERS_READ);
  FileAttribute<?> expectedAttribute = PosixFilePermissions.asFileAttribute(permissions);
  // This is lame; Java's PosixFilePermissions class doesn't
  // implement equals() or hashCode() in its FileAttribute anonymous
  // class (http://tinyurl.com/nznhfhy).  So instead of comparing
  // the sets, we have to pull out the attribute and check its value
  // for equality.
  FileAttribute<?> actualAttribute =
    Iterables.getOnlyElement(
        fakeProjectFilesystem.getFileAttributesAtPath(OUTPUT_PROJECT_FILE_PATH));
  assertEquals(
      expectedAttribute.value(),
      actualAttribute.value());
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:28,代码来源:ProjectGeneratorTest.java


注:本文中的java.nio.file.attribute.PosixFilePermissions.asFileAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。