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


Java PosixFileAttributeView类代码示例

本文整理汇总了Java中java.nio.file.attribute.PosixFileAttributeView的典型用法代码示例。如果您正苦于以下问题:Java PosixFileAttributeView类的具体用法?Java PosixFileAttributeView怎么用?Java PosixFileAttributeView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: create

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的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

示例2: assertFilePermissions

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
public static void assertFilePermissions(Path testRoot) throws IOException {
  Path file1 = testRoot.resolve(FILE_1); // mode 664
  PosixFileAttributeView allAttributesFile1 =
      Files.getFileAttributeView(file1, PosixFileAttributeView.class);
  Assert.assertThat(
      allAttributesFile1.readAttributes().permissions(),
      Matchers.containsInAnyOrder(
          PosixFilePermission.OWNER_READ,
          PosixFilePermission.OWNER_WRITE,
          PosixFilePermission.GROUP_READ));

  Path file2 = testRoot.resolve(FILE_2); // mode 777
  PosixFileAttributeView allAttributesFile2 =
      Files.getFileAttributeView(file2, PosixFileAttributeView.class);
  Assert.assertThat(
      allAttributesFile2.readAttributes().permissions(),
      Matchers.containsInAnyOrder(PosixFilePermission.values()));
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-plugins-core,代码行数:19,代码来源:GenericArchivesVerifier.java

示例3: setupEnvironment

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
/**
 * creates and grants permission to daemon files directory
 */
private static void setupEnvironment() {
	final File daemonFilePath = new File("/var/run/iofabric");
	if (!daemonFilePath.exists()) {
		try {
			daemonFilePath.mkdirs();

			UserPrincipalLookupService lookupservice = FileSystems.getDefault().getUserPrincipalLookupService();
			final GroupPrincipal group = lookupservice.lookupPrincipalByGroupName("iofabric");
			Files.getFileAttributeView(daemonFilePath.toPath(), PosixFileAttributeView.class,
					LinkOption.NOFOLLOW_LINKS).setGroup(group);
			Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxrwx---");
			Files.setPosixFilePermissions(daemonFilePath.toPath(), perms);
		} catch (Exception e) {
		}
	}

}
 
开发者ID:iotracks,项目名称:iofabric,代码行数:21,代码来源:Start.java

示例4: addExecutablePermission

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
/**
 * Adds the executable file permission.
 *
 * @param file the path to the file
 */
private void addExecutablePermission(String file) {
    final Path path = Paths.get(file);
    if (Files.exists(path)) {
        try {
            PosixFileAttributeView attr = Files.getFileAttributeView(path, PosixFileAttributeView.class);
            Set<PosixFilePermission> permissions = attr.readAttributes().permissions();
            if(permissions.add(PosixFilePermission.OWNER_EXECUTE)) {
                logger.info(String.format("Added +x permission to file: %s", file));
            }
            attr.setPermissions(permissions);
        } catch (IOException e) {
            logger.error(String.format("Failed to add the executable permissions to file: %s", file));
        }
    }
}
 
开发者ID:jmnarloch,项目名称:gocd-gradle-plugin,代码行数:21,代码来源:GradleTaskConfigParser.java

示例5: posixAttributes

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
/**
 * Get POSIX attributes for file.
 *
 * @param file File.
 * @return PosixFileAttributes.
 */
@Nullable public static PosixFileAttributes posixAttributes(File file) {
    PosixFileAttributes attrs = null;

    try {
        PosixFileAttributeView view = Files.getFileAttributeView(file.toPath(), PosixFileAttributeView.class);

        if (view != null)
            attrs = view.readAttributes();
    }
    catch (IOException e) {
        throw new IgfsException("Failed to read POSIX attributes: " + file.getAbsolutePath(), e);
    }

    return attrs;
}
 
开发者ID:apache,项目名称:ignite,代码行数:22,代码来源:LocalFileSystemUtils.java

示例6: getSupportedFileAttributes

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
private Set<String> getSupportedFileAttributes(FileStore fs) {
  Set<String> attrs = new HashSet<String>();
  if (fs.supportsFileAttributeView(AclFileAttributeView.class)) {
    attrs.add("acl");
  }
  if (fs.supportsFileAttributeView(BasicFileAttributeView.class)) {
    attrs.add("basic");
  }
  if (fs.supportsFileAttributeView(FileOwnerAttributeView.class)) {
    attrs.add("owner");
  }
  if (fs.supportsFileAttributeView(UserDefinedFileAttributeView.class)) {
    attrs.add("user");
  }
  if (fs.supportsFileAttributeView(DosFileAttributeView.class)) {
    attrs.add("dos");
  }
  if (fs.supportsFileAttributeView(PosixFileAttributeView.class)) {
    attrs.add("posix");
  }
  if (fs.supportsFileAttributeView(FileAttributeView.class)) {
    attrs.add("file");
  }
  return attrs;
}
 
开发者ID:tinyMediaManager,项目名称:tinyMediaManager,代码行数:26,代码来源:FSTest.java

示例7: supportsFileAttributeView

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
public boolean supportsFileAttributeView(
        Class<? extends FileAttributeView> type) {
    
    String name = "notFound";
    if(type == BasicFileAttributeView.class) {
        name = "basic";
    } else if(type == DosFileAttributeView.class) {
        name = "dos";
    } else if(type == PosixFileAttributeView.class) {
        name = "posix";
    } else if(type == FileOwnerAttributeView.class) {
        name = "owner";
    }
    
    return  attributeSets.containsKey(name);
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:17,代码来源:AttributeLookup.java

示例8: setPermissions

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
/**
 * Sets permissions on a {@link Resource} - doesn't do anything
 * for unsupported resource types.
 *
 * <p>Supported types are:</p>
 * <ul>
 *  <li>any {@link FileProvider}</li>
 *  <li>{@link ArchiveResource}</li>
 * </ul>
 *
 * @param r the resource to set permissions for
 * @param permissions the permissions
 * @param posixNotSupportedCallback optional callback that is
 * invoked for a file provider resource if the file-system holding
 * the file doesn't support PosixFilePermissions. The Path
 * corresponding to the file is passed to the callback.
 * @throws IOException if something goes wrong
 */
public static void setPermissions(Resource r, Set<PosixFilePermission> permissions,
                                  Consumer<Path> posixNotSupportedCallback)
    throws IOException {
    FileProvider f = r.as(FileProvider.class);
    if (f != null) {
        Path p = f.getFile().toPath();
        PosixFileAttributeView view =
            Files.getFileAttributeView(p, PosixFileAttributeView.class);
        if (view != null) {
            view.setPermissions(permissions);
        } else if (posixNotSupportedCallback != null) {
            posixNotSupportedCallback.accept(p);
        }
    } else if (r instanceof ArchiveResource) {
        ((ArchiveResource) r).setMode(modeFromPermissions(permissions,
                                                          FileType.of(r)));
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:37,代码来源:PermissionUtils.java

示例9: getPosixAttributesString

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
/**
 * @param path
 * @return
 */
public static String getPosixAttributesString(Path path) {
    PosixFileAttributeView posixView = Files.getFileAttributeView(path, PosixFileAttributeView.class);
    StringBuilder attrs = new StringBuilder();

    try {
        // + all basic attributes
        PosixFileAttributes posixAttrs = posixView.readAttributes();

        if (posixAttrs != null) {
            attrs.append(PosixFilePermissions.toString(posixAttrs.permissions()));
        }
    }
    catch (IOException e) {
        log.warn("unable to read Posix file attributes.", e); //$NON-NLS-1$
    }
    return attrs.toString();
}
 
开发者ID:e4c,项目名称:EclipseCommander,代码行数:22,代码来源:PathUtils.java

示例10: testFileStoreAttributes

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
/**
 * Test: File and FileStore attributes
 */
@Test
public void testFileStoreAttributes() throws URISyntaxException, IOException {
  URI uri = clusterUri.resolve("/tmp/testFileStore");
  Path path = Paths.get(uri);
  if (Files.exists(path))
    Files.delete(path);
  assertFalse(Files.exists(path));
  Files.createFile(path);
  assertTrue(Files.exists(path));
  FileStore store1 = Files.getFileStore(path);
  assertNotNull(store1);
  assertTrue(store1.supportsFileAttributeView("basic"));
  assertTrue(store1.supportsFileAttributeView(BasicFileAttributeView.class));
  assertTrue(store1.supportsFileAttributeView("posix") == store1
      .supportsFileAttributeView(PosixFileAttributeView.class));
  assertTrue(store1.supportsFileAttributeView("dos") == store1
      .supportsFileAttributeView(DosFileAttributeView.class));
  assertTrue(store1.supportsFileAttributeView("acl") == store1
      .supportsFileAttributeView(AclFileAttributeView.class));
  assertTrue(store1.supportsFileAttributeView("user") == store1
      .supportsFileAttributeView(UserDefinedFileAttributeView.class));
}
 
开发者ID:damiencarol,项目名称:jsr203-hadoop,代码行数:26,代码来源:TestFileStore.java

示例11: testGetPosixFileAttributeView

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
/**
 * Test {@code posix} file view support.
 * 
 * @throws IOException
 */
@Test
public void testGetPosixFileAttributeView() throws IOException {
  Path rootPath = Paths.get(clusterUri);

  assertTrue(rootPath.getFileSystem().supportedFileAttributeViews()
      .contains("posix"));

  // Get root view
  PosixFileAttributeView view = Files.getFileAttributeView(rootPath,
      PosixFileAttributeView.class);

  assertNotNull(view);
  assertNotNull(view.readAttributes());
  assertNotNull(view.readAttributes().lastModifiedTime());
}
 
开发者ID:damiencarol,项目名称:jsr203-hadoop,代码行数:21,代码来源:TestFiles.java

示例12: UnixBuilder

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
public UnixBuilder( FSDescription descr, T t ) {
        super( descr, t );

        PathLimits pathLimits = new PathLimits( OS.UNIX );
        PathSpec pathSpec = new PathSpecUnix();

        descr.props.put( Tests10PathWithContent.ONE_CHAR_COUNT, pathLimits.getBigChar() );
        descr.props.put( Tests10PathWithContent.MAX_FILENAME_LENGTH, pathSpec.getMaxFilenameLength() );
        descr.props.put( Tests10PathWithContent.MAX_PATH_LENGTH, pathSpec.getMaxPathLength() );
        descr.props.put( Tests10PathWithContent.GET_FILENAME_LENGTH, (Function<String,Integer>)pathSpec::getFilenameLength );
        descr.props.put( Tests10PathWithContent.GET_PATH_LENGTH, (Function<String,Integer>)pathSpec::getPathLength );


//        descr.removeTopic( LimitedPath.class ); theory but linux c limits
        descr.removeTopic( Windows.class );
        descr.removeTopic( DosAttributesT.class );
        descr.removeTopic( CaseInsensitive.class );
        descr.removeTopic( NonCasePreserving.class );

        descr.attributeDescriptions.put( "posix", attributeBuilding( Posix.class, "posix", PosixFileAttributeView.class, PosixFileAttributes.class ).
                addAttribute( "owner", PosixFileAttributes::owner ).
                addAttribute( "permissions", PosixFileAttributes::permissions ).
                addAttribute( "group", PosixFileAttributes::group ).
                build());

    }
 
开发者ID:openCage,项目名称:niotest,代码行数:27,代码来源:UnixBuilder.java

示例13: makeWritable

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
private void makeWritable(Path file) throws IOException {
  FileStore fileStore = Files.getFileStore(file);
  if (IS_WINDOWS && fileStore.supportsFileAttributeView(DosFileAttributeView.class)) {
    DosFileAttributeView dosAttribs =
        Files.getFileAttributeView(file, DosFileAttributeView.class);
    if (dosAttribs != null) {
      dosAttribs.setReadOnly(false);
    }
  } else if (fileStore.supportsFileAttributeView(PosixFileAttributeView.class)) {
    PosixFileAttributeView posixAttribs =
        Files.getFileAttributeView(file, PosixFileAttributeView.class);
    if (posixAttribs != null) {
      posixAttribs.setPermissions(EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE));
    }
  }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:17,代码来源:ScopedTemporaryDirectory.java

示例14: setPosixFilePermissions

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
@Override
public void setPosixFilePermissions(Path path, Set<PosixFilePermission> permissions) throws XenonException {

    if (permissions == null) {
        throw new IllegalArgumentException("Permissions is null!");
    }

    Path absPath = toAbsolutePath(path);

    assertPathExists(absPath);

    try {
        PosixFileAttributeView view = Files.getFileAttributeView(javaPath(absPath), PosixFileAttributeView.class);
        view.setPermissions(javaPermissions(permissions));
    } catch (IOException e) {
        throw new XenonException(ADAPTOR_NAME, "Failed to set permissions " + absPath, e);
    }
}
 
开发者ID:NLeSC,项目名称:Xenon,代码行数:19,代码来源:LocalFileSystem.java

示例15: getattr

import java.nio.file.attribute.PosixFileAttributeView; //导入依赖的package包/类
@Override
public int getattr(Path node, FileStat stat) {
	int result = super.getattr(node, stat);
	if (result == 0 && fileStore.supportsFileAttributeView(PosixFileAttributeView.class)) {
		stat.st_mode.set(FileStat.S_IFDIR | 0755);
	} else if (result == 0) {
		stat.st_mode.set(FileStat.S_IFDIR | 0777);
	}
	return result;
}
 
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:11,代码来源:ReadWriteDirectoryHandler.java


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