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


Java UserDefinedFileAttributeView.read方法代码示例

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


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

示例1: getInode

import java.nio.file.attribute.UserDefinedFileAttributeView; //导入方法依赖的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: visible

import java.nio.file.attribute.UserDefinedFileAttributeView; //导入方法依赖的package包/类
@Override
public boolean visible() throws IOException {
    final boolean shown;
    final UserDefinedFileAttributeView view =
        Files.getFileAttributeView(
            this.file.toPath(), UserDefinedFileAttributeView.class
        );
    if (view.list().contains(MkAttributes.VISIBILITY)) {
        final ByteBuffer buf = ByteBuffer.allocate(
            view.size(MkAttributes.VISIBILITY)
        );
        view.read(MkAttributes.VISIBILITY, buf);
        buf.flip();
        shown = Boolean.valueOf(
            StandardCharsets.UTF_8.decode(buf).toString()
        );
    } else {
        shown = false;
    }
    return shown;
}
 
开发者ID:libreio,项目名称:libre,代码行数:22,代码来源:MkAttributes.java

示例3: readFileAttributeAsLong

import java.nio.file.attribute.UserDefinedFileAttributeView; //导入方法依赖的package包/类
Optional<Long> readFileAttributeAsLong(Path file, String attribute, UserDefinedFileAttributeView view, List<String> knownAttributes) {
  if (knownAttributes.contains(attribute)) {
    try {
      LOG.trace("Attempting to read attribute {}, from file {}", attribute, file);
      ByteBuffer buf = ByteBuffer.allocate(view.size(attribute));
      view.read(attribute, buf);
      buf.flip();
      String value = Charset.defaultCharset().decode(buf).toString();
      if (Strings.isNullOrEmpty(value)) {
        LOG.debug("No attrbiute {} found for file {}", attribute, file);
        return Optional.absent();
      }
      return Optional.of(Long.parseLong(value));
    } catch (Exception e) {
      LOG.error("Error getting extra file metadata for {}", file, e);
      return Optional.absent();
    }
  } else {
    return Optional.absent();
  }
}
 
开发者ID:HubSpot,项目名称:Singularity,代码行数:22,代码来源:SingularityUploader.java

示例4: testWritingKeepsFileAttributes

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

示例5: getExecutable

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

示例6: getCustomerAttr

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


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