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


Java DosFileAttributeView类代码示例

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


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

示例1: getSupportedFileAttributes

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

示例2: supportsFileAttributeView

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

示例3: testSetGetSystem

import java.nio.file.attribute.DosFileAttributeView; //导入依赖的package包/类
@Test
public void testSetGetSystem() throws Exception {
    
    for(Path path : Arrays.asList(
            Files.createDirectory(root.resolve("dir")),
            Files.createFile(root.resolve("file")))) {
        DosFileAttributes attributes = Files.readAttributes(path, DosFileAttributes.class);
        assertFalse(attributes.isSystem());
        
        
        DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
        view.setSystem(true);
        
        attributes = Files.readAttributes(path, DosFileAttributes.class);
        assertTrue(attributes.isSystem());
    }
    
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:19,代码来源:DosFileAttributesTest.java

示例4: testSetGetArchiveUnix

import java.nio.file.attribute.DosFileAttributeView; //导入依赖的package包/类
@IgnoreIf(FsType.WINDOWS)
@Test
public void testSetGetArchiveUnix() throws Exception {
    for(Path path : Arrays.asList(
            Files.createDirectory(root.resolve("dir")),
            Files.createFile(root.resolve("file")))) {
    
        DosFileAttributes attributes = Files.readAttributes(path, DosFileAttributes.class);
        assertFalse(attributes.isArchive());
        
        
        DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
        view.setArchive(true);
        
        attributes = Files.readAttributes(path, DosFileAttributes.class);
        assertTrue(attributes.isArchive());
    }
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:19,代码来源:DosFileAttributesTest.java

示例5: testSetGetReadOnly

import java.nio.file.attribute.DosFileAttributeView; //导入依赖的package包/类
@Test
public void testSetGetReadOnly() throws Exception {
    for(Path path : Arrays.asList(
            Files.createDirectory(root.resolve("dir")),
            Files.createFile(root.resolve("file")))) {
        DosFileAttributes attributes = Files.readAttributes(path, DosFileAttributes.class);
        assertFalse(attributes.isReadOnly());
        
        
        DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
        try {
            view.setReadOnly(true);
            
            attributes = Files.readAttributes(path, DosFileAttributes.class);
            assertTrue(attributes.isReadOnly());
        } finally {
            view.setReadOnly(false);
        }
    }
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:21,代码来源:DosFileAttributesTest.java

示例6: testSetGetHidden

import java.nio.file.attribute.DosFileAttributeView; //导入依赖的package包/类
@Test
public void testSetGetHidden() throws Exception {
    for(Path path : Arrays.asList(
            Files.createDirectory(root.resolve("dir")),
            Files.createFile(root.resolve("file")))) {
    
        DosFileAttributes attributes = Files.readAttributes(path, DosFileAttributes.class);
        assertFalse(attributes.isHidden());
        
        
        DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
        view.setHidden(true);
        
        attributes = Files.readAttributes(path, DosFileAttributes.class);
        assertTrue(attributes.isHidden());
    }
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:18,代码来源:DosFileAttributesTest.java

示例7: tryDos

import java.nio.file.attribute.DosFileAttributeView; //导入依赖的package包/类
private void tryDos(Path p, boolean failIfDosIsNotSupported) {
    log("Falling back to DosFileAttributeView");
    boolean readOnly = !isWritable();
    DosFileAttributeView view = Files.getFileAttributeView(p, DosFileAttributeView.class);
    if (view != null) {
        try {
            view.setReadOnly(readOnly);
        } catch (IOException ioe) {
            maybeThrowException(ioe, "Failed to set permissions on '%s' due to %s",
                                p, ioe.getMessage());
        } catch (SecurityException uoe) {
            maybeThrowException(null,
                "the SecurityManager denies role accessUserInformation or write access for SecurityManager.checkWrite for resource '%s'",
                p);
        }
    } else {
        String msg = String.format(
            "the associated path '%s' does not support the DosFileAttributeView",
            p);
        if (failIfDosIsNotSupported) {
            throw new BuildException(msg);
        }
        log("Warning: " + msg, Project.MSG_ERR);
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:26,代码来源:SetPermissions.java

示例8: getDosAttributesString

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

    try {
        // + all basic attributes
        DosFileAttributes dosAttrs = basicView.readAttributes();

        attrs.append(dosAttrs.isReadOnly() ? "r" : "-"); //$NON-NLS-1$ //$NON-NLS-2$
        attrs.append(dosAttrs.isHidden() ? "h" : "-");//$NON-NLS-1$ //$NON-NLS-2$
        attrs.append(dosAttrs.isArchive() ? "a" : "-");//$NON-NLS-1$ //$NON-NLS-2$
        attrs.append(dosAttrs.isSystem() ? "s" : "-");//$NON-NLS-1$ //$NON-NLS-2$
    }
    catch (IOException e) {
        log.warn("unable to read DOS attributes.", e); //$NON-NLS-1$
    }
    return attrs.toString();
}
 
开发者ID:e4c,项目名称:EclipseCommander,代码行数:24,代码来源:PathUtils.java

示例9: testFileStoreAttributes

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

示例10: makeWritable

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

示例11: removeReadOnly

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

import java.nio.file.attribute.DosFileAttributeView; //导入依赖的package包/类
public static void setPermissions(Context context, Path file, String permissions) {
    DosFileAttributeView fileAttributeView = Files.getFileAttributeView(file, DosFileAttributeView.class);
    try {
        fileAttributeView.setArchive(permissions.contains("A"));
        fileAttributeView.setHidden(permissions.contains("H"));
        fileAttributeView.setReadOnly(permissions.contains("R"));
        fileAttributeView.setSystem(permissions.contains("S"));
    } catch (IOException ex) {
        Logger.error("Error setting permissions for '" + file + "'", ex, context.isDisplayStackTrace());
    }
}
 
开发者ID:evrignaud,项目名称:fim,代码行数:12,代码来源:DosFilePermissions.java

示例13: build

import java.nio.file.attribute.DosFileAttributeView; //导入依赖的package包/类
public <V extends FileAttributeView> V build(Class<V> type) {
    if (type == BasicFileAttributeView.class) {
        return (V) new EphemeralFsBasicFileAttributesView();
    } else if (type == PosixFileAttributeView.class) {
        return (V) new EphemeralFsPosixFileAttributesView();
    } else if (type == DosFileAttributeView.class) {
        return (V) new EphemeralFsDosFileAttributesView();
    } else if (type == FileOwnerAttributeView.class) {
        return (V) new EphemeralFsFileOwnerAttributeView();
    } else {
        throw new UnsupportedOperationException("type:" + type
                + " is not supported");
    }
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:15,代码来源:FileAttributesViewBuilder.java

示例14: viewClassFor

import java.nio.file.attribute.DosFileAttributeView; //导入依赖的package包/类
private Class<? extends BasicFileAttributeView> viewClassFor(
        Class<? extends BasicFileAttributes> attributeClass) {
    if (attributeClass == BasicFileAttributes.class) {
        return BasicFileAttributeView.class;
    } else if (attributeClass == PosixFileAttributes.class) {
        return PosixFileAttributeView.class;
    } else if (attributeClass == DosFileAttributes.class) {
        return DosFileAttributeView.class;
    } else {
        throw new IllegalArgumentException("unrecognized view class:"
                + attributeClass);
    }
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:14,代码来源:EphemeralFsFileSystemProvider.java

示例15: testReadOnlyCanStillWriteNotWindows

import java.nio.file.attribute.DosFileAttributeView; //导入依赖的package包/类
@IgnoreIf(FsType.WINDOWS)
@Test
public void testReadOnlyCanStillWriteNotWindows() throws Exception {
    Path path = Files.createFile(root.resolve("file"));
    DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
    view.setReadOnly(true);
    Files.write(path, new byte[] {1});
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:9,代码来源:DosFileAttributesTest.java


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