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


Java Files.getFileAttributeView方法代码示例

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


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

示例1: getInode

import java.nio.file.Files; //导入方法依赖的package包/类
private long getInode(File file) throws IOException {

        UserDefinedFileAttributeView view = null;
        // windows system and file customer Attribute
        if (OS_WINDOWS.equals(os)) {
            view = Files.getFileAttributeView(file.toPath(), UserDefinedFileAttributeView.class);// 把文件的内容属性值放置在view里面?
            try {
                ByteBuffer buffer = ByteBuffer.allocate(view.size(INODE));// view.size得到inode属性值大小
                view.read(INODE, buffer);// 把属性值放置在buffer中
                buffer.flip();
                return Long.parseLong(Charset.defaultCharset().decode(buffer).toString());// 返回编码后的inode的属性值

            }
            catch (NoSuchFileException e) {
                long winode = random.nextLong();
                view.write(INODE, Charset.defaultCharset().encode(String.valueOf(winode)));
                return winode;
            }
        }
        long inode = (long) Files.getAttribute(file.toPath(), "unix:ino");// 返回unix的inode的属性值
        return inode;
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:23,代码来源:ReliableTaildirEventReader.java

示例2: makeFileNonReadable

import java.nio.file.Files; //导入方法依赖的package包/类
private static void makeFileNonReadable(String file) throws IOException {
    Path filePath = Paths.get(file);
    Set<String> supportedAttr = filePath.getFileSystem().supportedFileAttributeViews();

    if (supportedAttr.contains("posix")) {
        Files.setPosixFilePermissions(filePath, PosixFilePermissions.fromString("-w--w----"));
    } else if (supportedAttr.contains("acl")) {
        UserPrincipal fileOwner = Files.getOwner(filePath);

        AclFileAttributeView view = Files.getFileAttributeView(filePath, AclFileAttributeView.class);

        AclEntry entry = AclEntry.newBuilder()
                .setType(AclEntryType.DENY)
                .setPrincipal(fileOwner)
                .setPermissions(AclEntryPermission.READ_DATA)
                .build();

        List<AclEntry> acl = view.getAcl();
        acl.add(0, entry);
        view.setAcl(acl);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TestVMOptionsFile.java

示例3: testWritingKeepsFileAttributes

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Test for bug 240953 - Netbeans Deletes User Defined Attributes.
 *
 * @throws java.io.IOException
 */
public void testWritingKeepsFileAttributes() throws IOException {

    final String attName = "User_Attribute";
    final String attValue = "User_Attribute_Value";

    if (Utilities.isWindows()) {
        clearWorkDir();
        File f = new File(getWorkDir(), "fileWithAtts.txt");
        f.createNewFile();
        UserDefinedFileAttributeView attsView = Files.getFileAttributeView(
                f.toPath(), UserDefinedFileAttributeView.class);
        ByteBuffer buffer = Charset.defaultCharset().encode(attValue);
        attsView.write(attName, buffer);

        buffer.rewind();
        attsView.read(attName, buffer);
        buffer.flip();
        String val = Charset.defaultCharset().decode(buffer).toString();
        assertEquals(attValue, val);

        FileObject fob = FileUtil.toFileObject(f);
        OutputStream os = fob.getOutputStream();
        try {
            os.write(55);
        } finally {
            os.close();
        }

        buffer.rewind();
        attsView.read(attName, buffer);
        buffer.flip();
        String val2 = Charset.defaultCharset().decode(buffer).toString();
        assertEquals(attValue, val2);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:FileObjTest.java

示例4: getCustomerAttr

import java.nio.file.Files; //导入方法依赖的package包/类
@Test
public void getCustomerAttr() throws IOException {

    Path target = Paths.get("/Users/fathead/temp/file4");
    UserDefinedFileAttributeView view2 = Files.getFileAttributeView(target, UserDefinedFileAttributeView.class);
    ByteBuffer buf = ByteBuffer.allocate(view2.size(name));
    view2.read(name, buf);
    buf.flip();
    String value = Charset.defaultCharset().decode(buf).toString();
    System.out.println("value=" + value);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:12,代码来源:DoTestRuleFilterFactory.java

示例5: save

import java.nio.file.Files; //导入方法依赖的package包/类
/** Write the keystore to the given config directory. */
void save(Path configDir) throws Exception {
    char[] password = this.keystorePassword.get().getPassword();

    SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
    // write to tmp file first, then overwrite
    String tmpFile = KEYSTORE_FILENAME + ".tmp";
    try (IndexOutput output = directory.createOutput(tmpFile, IOContext.DEFAULT)) {
        CodecUtil.writeHeader(output, KEYSTORE_FILENAME, FORMAT_VERSION);
        output.writeByte(password.length == 0 ? (byte)0 : (byte)1);
        output.writeString(type);
        output.writeString(secretFactory.getAlgorithm());

        ByteArrayOutputStream keystoreBytesStream = new ByteArrayOutputStream();
        keystore.get().store(keystoreBytesStream, password);
        byte[] keystoreBytes = keystoreBytesStream.toByteArray();
        output.writeInt(keystoreBytes.length);
        output.writeBytes(keystoreBytes, keystoreBytes.length);
        CodecUtil.writeFooter(output);
    }

    Path keystoreFile = keystorePath(configDir);
    Files.move(configDir.resolve(tmpFile), keystoreFile, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
    PosixFileAttributeView attrs = Files.getFileAttributeView(keystoreFile, PosixFileAttributeView.class);
    if (attrs != null) {
        // don't rely on umask: ensure the keystore has minimal permissions
        attrs.setPermissions(PosixFilePermissions.fromString("rw-------"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:KeyStoreWrapper.java

示例6: installConfig

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Copies the files from {@code tmpConfigDir} into {@code destConfigDir}.
 * Any files existing in both the source and destination will be skipped.
 */
private void installConfig(PluginInfo info, Path tmpConfigDir, Path destConfigDir) throws Exception {
    if (Files.isDirectory(tmpConfigDir) == false) {
        throw new UserException(ExitCodes.IO_ERROR, "config in plugin " + info.getName() + " is not a directory");
    }

    Files.createDirectories(destConfigDir);
    setFileAttributes(destConfigDir, CONFIG_DIR_PERMS);
    final PosixFileAttributeView destConfigDirAttributesView =
        Files.getFileAttributeView(destConfigDir.getParent(), PosixFileAttributeView.class);
    final PosixFileAttributes destConfigDirAttributes =
        destConfigDirAttributesView != null ? destConfigDirAttributesView.readAttributes() : null;
    if (destConfigDirAttributes != null) {
        setOwnerGroup(destConfigDir, destConfigDirAttributes);
    }

    try (DirectoryStream<Path> stream = Files.newDirectoryStream(tmpConfigDir)) {
        for (Path srcFile : stream) {
            if (Files.isDirectory(srcFile)) {
                throw new UserException(ExitCodes.DATA_ERROR, "Directories not allowed in config dir for plugin " + info.getName());
            }

            Path destFile = destConfigDir.resolve(tmpConfigDir.relativize(srcFile));
            if (Files.exists(destFile) == false) {
                Files.copy(srcFile, destFile);
                setFileAttributes(destFile, CONFIG_FILES_PERMS);
                if (destConfigDirAttributes != null) {
                    setOwnerGroup(destFile, destConfigDirAttributes);
                }
            }
        }
    }
    IOUtils.rm(tmpConfigDir); // clean up what we just copied
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:InstallPluginCommand.java

示例7: setFileAttributes

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Sets the attributes for a path iff posix attributes are supported
 */
private static void setFileAttributes(final Path path, final Set<PosixFilePermission> permissions) throws IOException {
    PosixFileAttributeView fileAttributeView = Files.getFileAttributeView(path, PosixFileAttributeView.class);
    if (fileAttributeView != null) {
        Files.setPosixFilePermissions(path, permissions);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:InstallPluginCommand.java

示例8: setExecutable

import java.nio.file.Files; //导入方法依赖的package包/类
public static void setExecutable ( final Path path, final boolean state ) throws IOException
{
    final UserDefinedFileAttributeView ua = Files.getFileAttributeView ( path, UserDefinedFileAttributeView.class );
    if ( state )
    {
        ua.write ( ATTR_EXECUTE, ByteBuffer.wrap ( marker ) );
    }
    else
    {
        ua.delete ( ATTR_EXECUTE );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:13,代码来源:Executables.java

示例9: getExecutable

import java.nio.file.Files; //导入方法依赖的package包/类
public static boolean getExecutable ( final Path path ) throws IOException
{
    final UserDefinedFileAttributeView ua = Files.getFileAttributeView ( path, UserDefinedFileAttributeView.class );

    if ( !ua.list ().contains ( ATTR_EXECUTE ) )
    {
        // check first, otherwise the size() call with give an exception
        return false;
    }

    final ByteBuffer buf = ByteBuffer.allocate ( ua.size ( ATTR_EXECUTE ) );
    ua.read ( ATTR_EXECUTE, buf );
    buf.flip ();
    return Boolean.parseBoolean ( CHARSET.decode ( buf ).toString () );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:16,代码来源:Executables.java

示例10: chmod

import java.nio.file.Files; //导入方法依赖的package包/类
private static void chmod(final Path file, final String perms) throws IOException {
    final PosixFileAttributeView view =
        Files.getFileAttributeView(file, PosixFileAttributeView.class);

    if (view == null) {
        // OS (Windows) doesn't support POSIX file attributes
        return;
    }

    view.setPermissions(PosixFilePermissions.fromString("rwxr-xr-x"));
}
 
开发者ID:loom-build-tool,项目名称:loom-installer,代码行数:12,代码来源:LoomInstaller.java

示例11: removeReadOnly

import java.nio.file.Files; //导入方法依赖的package包/类
public static void removeReadOnly(Path path) throws IOException {
    DosFileAttributeView att = Files.getFileAttributeView(path, DosFileAttributeView.class);
    if (att != null) {
        att.setReadOnly(false);
    }
    Files.delete(path);
}
 
开发者ID:pgcodekeeper,项目名称:pgcodekeeper,代码行数:8,代码来源:FileUtils.java

示例12: getFileAttributeView

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public <V extends FileAttributeView> V getFileAttributeView(Path file,
                                                            Class<V> type,
                                                            LinkOption... options)
{
    return Files.getFileAttributeView(unwrap(file), type, options);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:FaultyFileSystem.java

示例13: setCustomerAttr

import java.nio.file.Files; //导入方法依赖的package包/类
@Test
public void setCustomerAttr() throws IOException {

    Path target = Paths.get("/Users/fathead/temp/file4");
    UserDefinedFileAttributeView view = Files.getFileAttributeView(target, UserDefinedFileAttributeView.class);
    view.write(name, Charset.defaultCharset().encode("pinelet"));
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:8,代码来源:DoTestRuleFilterFactory.java

示例14: chmod

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public void chmod(File f, int mode) throws IOException {
    PosixFileAttributeView fileAttributeView = Files.getFileAttributeView(f.toPath(), PosixFileAttributeView.class);
    fileAttributeView.setPermissions(convertToPermissionsSet(mode));
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:6,代码来源:PosixJdk7FilePermissionHandler.java

示例15: setFileCreationDate

import java.nio.file.Files; //导入方法依赖的package包/类
public static void setFileCreationDate(String filePath, Date creationDate) throws IOException
{
    BasicFileAttributeView attributes = Files.getFileAttributeView(Paths.get(filePath), BasicFileAttributeView.class);
    FileTime time = FileTime.fromMillis(creationDate.getTime());
    attributes.setTimes(time, time, time);
}
 
开发者ID:RetroFloppy,项目名称:transformenator,代码行数:7,代码来源:ExtractIBM8Files.java


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