當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。