本文整理汇总了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.");
}
示例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();
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
示例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));
}
示例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());
}
示例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();
}
示例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());
}
示例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());
});
}
示例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());
}
示例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());
});
}
示例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;
}
示例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);
}
示例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());
}