java.nio.file.attribute.DosFileAttributeView源码实例Demo

java.nio.file.attribute.AclEntryPermission#java.nio.file.attribute.DosFileAttributeView源码实例Demo

下面列出了java.nio.file.attribute.AclEntryPermission#java.nio.file.attribute.DosFileAttributeView 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: zip4j   文件: FileUtils.java
private static void applyWindowsFileAttributes(Path file, byte[] fileAttributes) {
  if (fileAttributes[0] == 0) {
    // No file attributes defined in the archive
    return;
  }

  DosFileAttributeView fileAttributeView = Files.getFileAttributeView(file, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
  try {
    fileAttributeView.setReadOnly(isBitSet(fileAttributes[0], 0));
    fileAttributeView.setHidden(isBitSet(fileAttributes[0], 1));
    fileAttributeView.setSystem(isBitSet(fileAttributes[0], 2));
    fileAttributeView.setArchive(isBitSet(fileAttributes[0], 5));
  } catch (IOException e) {
    //Ignore
  }
}
 
源代码2 项目: zip4j   文件: FileUtils.java
private static byte[] getWindowsFileAttributes(Path file) {
  byte[] fileAttributes = new byte[4];

  try {
    DosFileAttributeView dosFileAttributeView = Files.getFileAttributeView(file, DosFileAttributeView.class,
        LinkOption.NOFOLLOW_LINKS);
    DosFileAttributes dosFileAttributes = dosFileAttributeView.readAttributes();

    byte windowsAttribute = 0;

    windowsAttribute = setBitIfApplicable(dosFileAttributes.isReadOnly(), windowsAttribute, 0);
    windowsAttribute = setBitIfApplicable(dosFileAttributes.isHidden(), windowsAttribute, 1);
    windowsAttribute = setBitIfApplicable(dosFileAttributes.isSystem(), windowsAttribute, 2);
    windowsAttribute = setBitIfApplicable(dosFileAttributes.isArchive(), windowsAttribute, 5);
    fileAttributes[0] = windowsAttribute;
  } catch (IOException e) {
    // ignore
  }

  return fileAttributes;
}
 
源代码3 项目: zip4j   文件: FileUtilsTestWindows.java
@Test
public void testSetFileAttributesOnWindowsMachineWhenAttributesSet() throws IOException {
  Path mockedPath = mock(Path.class);
  DosFileAttributeView dosFileAttributeView = mockDosFileAttributeView(mockedPath, true, null);

  byte attribute = 0;
  attribute = BitUtils.setBit(attribute, 0);
  attribute = BitUtils.setBit(attribute, 1);
  attribute = BitUtils.setBit(attribute, 2);
  attribute = BitUtils.setBit(attribute, 5);

  FileUtils.setFileAttributes(mockedPath, new byte[]{attribute, 0, 0, 0});

  verify(dosFileAttributeView).setReadOnly(true);
  verify(dosFileAttributeView).setHidden(true);
  verify(dosFileAttributeView).setSystem(true);
  verify(dosFileAttributeView).setArchive(true);
}
 
源代码4 项目: zip4j   文件: FileUtilsTestWindows.java
@Test
public void testGetFileAttributesReturnsAttributesAsDefined() throws IOException {
  File file = mock(File.class);
  Path path = mock(Path.class);
  when(file.toPath()).thenReturn(path);
  when(file.exists()).thenReturn(true);
  DosFileAttributes dosFileAttributes = mock(DosFileAttributes.class);
  DosFileAttributeView dosFileAttributeView = mockDosFileAttributeView(path, true, dosFileAttributes);
  when(dosFileAttributeView.readAttributes()).thenReturn(dosFileAttributes);
  when(dosFileAttributes.isReadOnly()).thenReturn(true);
  when(dosFileAttributes.isHidden()).thenReturn(true);
  when(dosFileAttributes.isSystem()).thenReturn(true);
  when(dosFileAttributes.isArchive()).thenReturn(true);

  byte[] attributes = FileUtils.getFileAttributes(file);

  assertThat(isBitSet(attributes[0], 0)).isTrue();
  assertThat(isBitSet(attributes[0], 1)).isTrue();
  assertThat(isBitSet(attributes[0], 2)).isTrue();
  assertThat(isBitSet(attributes[0], 5)).isTrue();
}
 
源代码5 项目: zip4j   文件: FileUtilsTestWindows.java
private DosFileAttributeView mockDosFileAttributeView(Path path, boolean fileExists, DosFileAttributes dosFileAttributes) throws IOException {
  FileSystemProvider fileSystemProvider = mock(FileSystemProvider.class);
  FileSystem fileSystem = mock(FileSystem.class);
  DosFileAttributeView dosFileAttributeView = mock(DosFileAttributeView.class);

  when(fileSystemProvider.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS)).thenReturn(dosFileAttributes);
  when(path.getFileSystem()).thenReturn(fileSystem);
  when(fileSystemProvider.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS))
      .thenReturn(dosFileAttributeView);
  when(path.getFileSystem().provider()).thenReturn(fileSystemProvider);

  if (!fileExists) {
    doThrow(new IOException()).when(fileSystemProvider).checkAccess(path);
  }

  return dosFileAttributeView;
}
 
源代码6 项目: jsr203-hadoop   文件: TestFileStore.java
/**
 * 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));
}
 
源代码7 项目: bazel   文件: ScopedTemporaryDirectory.java
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));
    }
  }
}
 
源代码8 项目: code   文件: TestNIO_2.java
@Test
    public void test6() throws IOException {
        Path path = Paths.get("e:/nio/hello7.txt");
//		System.out.println(Files.exists(path, LinkOption.NOFOLLOW_LINKS));

        BasicFileAttributes readAttributes = Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
        System.out.println(readAttributes.creationTime());
        System.out.println(readAttributes.lastModifiedTime());

        DosFileAttributeView fileAttributeView = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);

        fileAttributeView.setHidden(false);
    }
 
源代码9 项目: zip4j   文件: FileUtilsTestWindows.java
@Test
public void testSetFileAttributesOnWindowsWhenNoAttributesSetDoesNothing() throws IOException {
  Path mockedPath = mock(Path.class);
  DosFileAttributeView dosFileAttributeView = mockDosFileAttributeView(mockedPath, true, null);

  FileUtils.setFileAttributes(mockedPath, new byte[]{0, 0, 0, 0});

  verifyZeroInteractions(dosFileAttributeView);
}
 
源代码10 项目: jimfs   文件: DosAttributeProviderTest.java
@Test
public void testView() throws IOException {
  DosFileAttributeView view =
      provider.view(
          fileLookup(),
          ImmutableMap.<String, FileAttributeView>of(
              "basic", new BasicAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS)));
  assertNotNull(view);

  assertThat(view.name()).isEqualTo("dos");

  DosFileAttributes attrs = view.readAttributes();
  assertThat(attrs.isHidden()).isFalse();
  assertThat(attrs.isArchive()).isFalse();
  assertThat(attrs.isReadOnly()).isFalse();
  assertThat(attrs.isSystem()).isFalse();

  view.setArchive(true);
  view.setReadOnly(true);
  view.setHidden(true);
  view.setSystem(false);

  assertThat(attrs.isHidden()).isFalse();
  assertThat(attrs.isArchive()).isFalse();
  assertThat(attrs.isReadOnly()).isFalse();

  attrs = view.readAttributes();
  assertThat(attrs.isHidden()).isTrue();
  assertThat(attrs.isArchive()).isTrue();
  assertThat(attrs.isReadOnly()).isTrue();
  assertThat(attrs.isSystem()).isFalse();

  view.setTimes(FileTime.fromMillis(0L), null, null);
  assertThat(view.readAttributes().lastModifiedTime()).isEqualTo(FileTime.fromMillis(0L));
}
 
源代码11 项目: simple-nfs   文件: LocalFileSystem.java
private Stat statPath(Path p, long inodeNumber) throws IOException {

        Class<? extends  BasicFileAttributeView> attributeClass =
                IS_UNIX ? PosixFileAttributeView.class : DosFileAttributeView.class;

        BasicFileAttributes attrs = Files.getFileAttributeView(p, attributeClass, NOFOLLOW_LINKS).readAttributes();

        Stat stat = new Stat();

        stat.setATime(attrs.lastAccessTime().toMillis());
        stat.setCTime(attrs.creationTime().toMillis());
        stat.setMTime(attrs.lastModifiedTime().toMillis());

        if (IS_UNIX) {
            stat.setGid((Integer) Files.getAttribute(p, "unix:gid", NOFOLLOW_LINKS));
            stat.setUid((Integer) Files.getAttribute(p, "unix:uid", NOFOLLOW_LINKS));
            stat.setMode((Integer) Files.getAttribute(p, "unix:mode", NOFOLLOW_LINKS));
            stat.setNlink((Integer) Files.getAttribute(p, "unix:nlink", NOFOLLOW_LINKS));
        } else {
            DosFileAttributes dosAttrs = (DosFileAttributes)attrs;
            stat.setGid(0);
            stat.setUid(0);
            int type = dosAttrs.isSymbolicLink() ? Stat.S_IFLNK : dosAttrs.isDirectory() ? Stat.S_IFDIR : Stat.S_IFREG;
            stat.setMode( type |(dosAttrs.isReadOnly()? 0400 : 0600));
            stat.setNlink(1);
        }

        stat.setDev(17);
        stat.setIno((int) inodeNumber);
        stat.setRdev(17);
        stat.setSize(attrs.size());
        stat.setFileid((int) inodeNumber);
        stat.setGeneration(attrs.lastModifiedTime().toMillis());

        return stat;
    }
 
源代码12 项目: dragonwell8_jdk   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码13 项目: TencentKona-8   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码14 项目: jdk8u60   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码15 项目: openjdk-jdk8u   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码17 项目: openjdk-jdk9   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码18 项目: jdk8u-jdk   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码19 项目: hottub   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码20 项目: openjdk-8-source   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码21 项目: openjdk-8   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码22 项目: jdk8u_jdk   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码23 项目: jdk8u-jdk   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码24 项目: jdk8u-dev-jdk   文件: IsHidden.java
private static void setHidden(File f, boolean value) throws IOException {
    Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
 
源代码25 项目: jimfs   文件: DosAttributeProvider.java
@Override
public Class<DosFileAttributeView> viewType() {
  return DosFileAttributeView.class;
}
 
源代码26 项目: jimfs   文件: DosAttributeProvider.java
@Override
public DosFileAttributeView view(
    FileLookup lookup, ImmutableMap<String, FileAttributeView> inheritedViews) {
  return new View(lookup, (BasicFileAttributeView) inheritedViews.get("basic"));
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。