Java 类java.nio.file.attribute.DosFileAttributes 实例源码

项目:fim    文件:DosFilePermissions.java   
public static String toString(DosFileAttributes dosFileAttributes) {
    StringBuilder builder = new StringBuilder();
    if (dosFileAttributes.isArchive()) {
        builder.append('A');
    }
    if (dosFileAttributes.isHidden()) {
        builder.append('H');
    }
    if (dosFileAttributes.isReadOnly()) {
        builder.append('R');
    }
    if (dosFileAttributes.isSystem()) {
        builder.append('S');
    }
    return builder.toString();
}
项目:fim    文件:ResetFileAttributesCommand.java   
private int resetFileAttributes(Context context, FileState fileState, Path file) throws IOException {
    boolean attributesModified = false;

    try {
        BasicFileAttributes attributes;

        if (SystemUtils.IS_OS_WINDOWS) {
            DosFileAttributes dosFileAttributes = Files.readAttributes(file, DosFileAttributes.class);
            attributes = dosFileAttributes;

            attributesModified = resetDosPermissions(context, file, fileState, dosFileAttributes) || attributesModified;
        } else {
            PosixFileAttributes posixFileAttributes = Files.readAttributes(file, PosixFileAttributes.class);
            attributes = posixFileAttributes;

            attributesModified = resetPosixPermissions(file, fileState, posixFileAttributes) || attributesModified;
        }

        attributesModified = resetCreationTime(file, fileState, attributes) || attributesModified;
        attributesModified = resetLastModified(file, fileState, attributes) || attributesModified;
        attributesModified = resetSELinux(context, file, fileState) || attributesModified;
    } catch (Exception ex) {
        Logger.error(ex.getMessage());
    }
    return attributesModified ? 1 : 0;
}
项目:fim    文件:DosFilePermissionsTest.java   
@Test
public void canRetrieveTheStringVersion() {
    DosFileAttributes dosFileAttributes = mock(DosFileAttributes.class);

    assertThat(DosFilePermissions.toString(dosFileAttributes)).isEqualTo("");

    Mockito.when(dosFileAttributes.isArchive()).thenReturn(true);
    assertThat(DosFilePermissions.toString(dosFileAttributes)).isEqualTo("A");

    Mockito.when(dosFileAttributes.isHidden()).thenReturn(true);
    assertThat(DosFilePermissions.toString(dosFileAttributes)).isEqualTo("AH");

    Mockito.when(dosFileAttributes.isReadOnly()).thenReturn(true);
    assertThat(DosFilePermissions.toString(dosFileAttributes)).isEqualTo("AHR");

    Mockito.when(dosFileAttributes.isSystem()).thenReturn(true);
    assertThat(DosFilePermissions.toString(dosFileAttributes)).isEqualTo("AHRS");
}
项目:ephemeralfs    文件:DosFileAttributesTest.java   
@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());
    }

}
项目:ephemeralfs    文件:DosFileAttributesTest.java   
@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());
    }
}
项目:ephemeralfs    文件:DosFileAttributesTest.java   
@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);
        }
    }
}
项目:ephemeralfs    文件:DosFileAttributesTest.java   
@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());
    }
}
项目:EclipseCommander    文件:PathUtils.java   
/**
 * @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();
}
项目:jimfs    文件:JimfsFileSystemProvider.java   
@Override
public boolean isHidden(Path path) throws IOException {
  // TODO(cgdecker): This should probably be configurable, but this seems fine for now
  /*
   * If the DOS view is supported, use the Windows isHidden method (check the dos:hidden
   * attribute). Otherwise, use the Unix isHidden method (just check if the file name starts with
   * ".").
   */
  JimfsPath checkedPath = checkPath(path);
  FileSystemView view = getDefaultView(checkedPath);
  if (getFileStore(path).supportsFileAttributeView("dos")) {
    return view
        .readAttributes(checkedPath, DosFileAttributes.class, Options.NOFOLLOW_LINKS)
        .isHidden();
  }
  return path.getNameCount() > 0
      && path.getFileName().toString().startsWith(".");
}
项目:jimfs    文件:DosAttributeProviderTest.java   
@Test
public void testAttributes() {
  DosFileAttributes attrs = provider.readAttributes(file);
  assertThat(attrs.isHidden()).isFalse();
  assertThat(attrs.isArchive()).isFalse();
  assertThat(attrs.isReadOnly()).isFalse();
  assertThat(attrs.isSystem()).isFalse();

  file.setAttribute("dos", "hidden", true);

  attrs = provider.readAttributes(file);
  assertThat(attrs.isHidden()).isTrue();
  assertThat(attrs.isArchive()).isFalse();
  assertThat(attrs.isReadOnly()).isFalse();
  assertThat(attrs.isSystem()).isFalse();
}
项目:cyberduck    文件:LocalAttributesFinderFeature.java   
protected PathAttributes convert(final java.nio.file.Path file) throws IOException {
    final boolean isPosix = session.isPosixFilesystem();
    final PathAttributes attributes = new PathAttributes();
    final Class<? extends BasicFileAttributes> provider = isPosix ? PosixFileAttributes.class : DosFileAttributes.class;
    final BasicFileAttributes a = Files.readAttributes(file, provider, LinkOption.NOFOLLOW_LINKS);
    if(Files.isRegularFile(file)) {
        attributes.setSize(a.size());
    }
    attributes.setModificationDate(a.lastModifiedTime().toMillis());
    attributes.setCreationDate(a.creationTime().toMillis());
    attributes.setAccessedDate(a.lastAccessTime().toMillis());
    if(isPosix) {
        attributes.setOwner(((PosixFileAttributes) a).owner().getName());
        attributes.setGroup(((PosixFileAttributes) a).group().getName());
        attributes.setPermission(new Permission(PosixFilePermissions.toString(((PosixFileAttributes) a).permissions())));
    }
    else {
        Permission.Action actions = Permission.Action.none;
        if(Files.isReadable(file)) {
            actions = actions.or(Permission.Action.read);
        }
        if(Files.isWritable(file)) {
            actions = actions.or(Permission.Action.write);
        }
        if(Files.isExecutable(file)) {
            actions = actions.or(Permission.Action.execute);
        }
        attributes.setPermission(new Permission(
            actions, Permission.Action.none, Permission.Action.none
        ));
    }
    return attributes;
}
项目:ChromeForensics    文件:Utils.java   
/**
 * 
 * @param fileLoc
 * @return 
 */
public static Map<String, String> getFileMetadata(Path fileLoc) {
    Map<String, String> linkedHashMap = new LinkedHashMap<>();

    try {
        DosFileAttributes dosFileAttr = Files.readAttributes(fileLoc, DosFileAttributes.class);

        linkedHashMap.put("File Name", fileLoc.getFileName().toString());
        linkedHashMap.put("File Location", fileLoc.toString());
        linkedHashMap.put("File Size", readableFileSize(dosFileAttr.size()));
        linkedHashMap.put("Creation Time", getDateTime(dosFileAttr.creationTime()));
        linkedHashMap.put("Last Accessed Time", getDateTime(dosFileAttr.lastAccessTime()));
        linkedHashMap.put("Last Modified Time", getDateTime(dosFileAttr.lastModifiedTime()));
        linkedHashMap.put("Is Directory?", dosFileAttr.isDirectory() ? "True" : "False");
        linkedHashMap.put("Is Regular File?", dosFileAttr.isRegularFile() ? "True" : "False");
        linkedHashMap.put("Is Symbolic Link?", dosFileAttr.isSymbolicLink() ? "True" : "False");
        linkedHashMap.put("Is Archive?", dosFileAttr.isArchive() ? "True" : "False");
        linkedHashMap.put("Is Hidden File?", dosFileAttr.isHidden() ? "True" : "False");
        linkedHashMap.put("Is ReadOnly?", dosFileAttr.isReadOnly() ? "True" : "False");
        linkedHashMap.put("Is System File?", dosFileAttr.isSystem() ? "True" : "False");

        if (getOsName().equals("Linux")) {
            PosixFileAttributes attr = Files.readAttributes(fileLoc, PosixFileAttributes.class);
            String posixPerm = String.format("%s %s %s%n", attr.owner().getName(), attr.group().getName(),
                    PosixFilePermissions.toString(attr.permissions()));

            linkedHashMap.put("Posix", posixPerm);
        }

    } catch (UnsupportedOperationException | IOException ex) {
        System.err.println(ex.getMessage());
    }

    return linkedHashMap;
}
项目:fim    文件:FileHasher.java   
private void hashFilesInQueue() throws InterruptedException {
    Path file;
    while ((file = filesToHashQueue.poll(100, TimeUnit.MILLISECONDS)) != null) {
        try {
            BasicFileAttributes attributes;
            List<Attribute> fileAttributes = null;

            if (SystemUtils.IS_OS_WINDOWS) {
                DosFileAttributes dosFileAttributes = Files.readAttributes(file, DosFileAttributes.class);
                fileAttributes = addAttribute(fileAttributes, FileAttribute.DosFilePermissions, DosFilePermissions.toString(dosFileAttributes));
                attributes = dosFileAttributes;
            } else {
                PosixFileAttributes posixFileAttributes = Files.readAttributes(file, PosixFileAttributes.class);
                fileAttributes = addAttribute(fileAttributes, FileAttribute.PosixFilePermissions, PosixFilePermissions.toString(posixFileAttributes.permissions()));
                if (SELinux.ENABLED) {
                    fileAttributes = addAttribute(fileAttributes, FileAttribute.SELinuxLabel, SELinux.getLabel(context, file));
                }
                attributes = posixFileAttributes;
            }

            hashProgress.updateOutput(attributes.size());

            FileHash fileHash = hashFile(file, attributes.size());
            String normalizedFileName = FileUtil.getNormalizedFileName(file);
            String relativeFileName = FileUtil.getRelativeFileName(rootDir, normalizedFileName);

            fileStates.add(new FileState(relativeFileName, attributes, fileHash, fileAttributes));
        } catch (Exception ex) {
            Logger.newLine();
            Logger.error("Skipping - Error hashing file '" + file + "'", ex, context.isDisplayStackTrace());
        }
    }
}
项目:fim    文件:ResetFileAttributesCommand.java   
private boolean resetDosPermissions(Context context, Path file, FileState fileState, DosFileAttributes dosFileAttributes) {
    String permissions = DosFilePermissions.toString(dosFileAttributes);
    String previousPermissions = getAttribute(fileState, FileAttribute.DosFilePermissions);
    if (previousPermissions != null && !Objects.equals(permissions, previousPermissions)) {
        DosFilePermissions.setPermissions(context, file, previousPermissions);
        Logger.out.printf("Set permissions: %s \t%s -> %s%n", fileState.getFileName(), permissions, previousPermissions);
        return true;
    }
    return false;
}
项目:UXplore    文件:OperationManager.java   
/**
 * open a folder and return it's contents
 *
 * @param folder
 * @return
 */
public ArrayList<FSItem> openFolder(FSItem folder) {
    ArrayList<FSItem> contents = new ArrayList<>();
    try {
        DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(folder.getFsItemPath()));
        for (Path path : directoryStream) {

            DosFileAttributes attrs = Files.readAttributes(path, DosFileAttributes.class);
            FSItemProperties itemProperties = new FSItemProperties();
            FSIcon itemIcon = new FSIcon();

            FileSystemView fsv = FileSystemView.getFileSystemView();
            ImageIcon icon = (ImageIcon) fsv.getSystemIcon(path.toFile());
            itemIcon.setIconHeight((byte) icon.getIconHeight());
            itemIcon.setIconWidth((byte) icon.getIconWidth());
            itemIcon.setIconImage(this.createImage(icon.getImage()));

            itemProperties.setItemCreationDate(attrs.creationTime().toString());
            itemProperties.setItemLastAccessDate(attrs.lastAccessTime().toString());
            itemProperties.setItemName(path.getFileName().toString());
            itemProperties.setItemSize(attrs.size());
            itemProperties.setHidden(attrs.isHidden());

            FSItem item = new FSItem(path.toString());
            item.setItemProperties(itemProperties);
            item.setIcon(itemIcon);
            contents.add(item);
        }
        return contents;
    } catch (IOException ex) {
        ex.printStackTrace();
        return null;
    }

}
项目:ephemeralfs    文件:FileAttributesSnapshot.java   
public <V extends BasicFileAttributes> V cast(Class<V> type) {
     if(type == BasicFileAttributes.class) {
         return (V) new EphemeralFsBasicFileAttributes();
    } else if(type == PosixFileAttributes.class) {
         return (V) new EphemeralFsPosixFileAttributes();
    } else if(type == DosFileAttributes.class) { 
        return (V) new EphemeralFsDosFileAttributes();
    }
    //there is no FileOwnerAttributes ?
    else {
        throw new UnsupportedOperationException("type:" + type + " is not supported");
    }
}
项目:ephemeralfs    文件:EphemeralFsFileSystemProvider.java   
@Override
public boolean isHidden(Path path) throws IOException {
    EphemeralFsFileSystem fs = getFs(path);
    if(!fs.getSettings().isPosix()) {
        DosFileAttributes atts = readAttributes(path, DosFileAttributes.class);
        if(atts.isDirectory()) {
            return false;
        }
        return atts.isHidden();    
    }
    return path.getFileName().toString().startsWith(".");
}
项目:ephemeralfs    文件:EphemeralFsFileSystemProvider.java   
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);
    }
}
项目:ephemeralfs    文件:DosFileAttributesTest.java   
@Before
public void checkDos() {
    //some linux file systems do not support dos attributes, some do
    try {
        Files.readAttributes(root, DosFileAttributes.class).isSystem();
    } catch(IOException e) {
        assumeTrue(false);
    }
}
项目:eightyfs    文件:EightyProvider.java   
@Override
public boolean isHidden( @Nullable Path path ) throws IOException {
    EightyPath ep = checkProvider( path );
    AttributeProvider attributeProvider = ep._getFileSystem().getAttributeProvider();

    if( attributeProvider.isViewSupported( DosFileAttributeView.class ) ) {
        return _nn( readAttributes( path, DosFileAttributes.class ) ).isHidden();
    }

    @Nullable EightyPath fname = ep.getFileName();

    return fname != null && fname.toString().startsWith( "." );

}
项目:eightyfs    文件:RWAttributesBuilder.java   
public RWAttributesBuilder addDos() {
    attributes( "dos", DosFileAttributeView.class, DosFileAttributes.class ).
            attribute( "hidden", DosFileAttributes::isHidden,
                       BiConsumerE.u( ( v, b ) -> v.setHidden( (Boolean) b ) ) ).
            attribute( "readonly", DosFileAttributes::isReadOnly ).
            attribute( "system", DosFileAttributes::isSystem ).
            attribute( "archive", DosFileAttributes::isArchive );

    return this;
}
项目:jsr203-hadoop    文件:TestFiles.java   
@Test(expected = UnsupportedOperationException.class)
public void getFileAttributeViewUnsupportedOperationException()
    throws IOException {
  Path rootPath = Paths.get(clusterUri);
  Path path = Files.createTempFile(rootPath, "test", "tmp");
  Files.readAttributes(path, DosFileAttributes.class);
}
项目:niotest    文件:WindowsBuilder.java   
public WindowsBuilder( FSDescription descr, T t ) {
    super( descr, t );

    descr.removeTopic( Unix.class );

    PathLimits pathLimits = new PathLimits( OS.WINDOWS );
    PathSpec pathSpec = new PathSpecWindows();
    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( Posix.class );
    descr.removeTopic( MoveWhile.class );
    descr.removeTopic( NonCasePreserving.class );
    descr.removeTopic( FileKeyT.class );


    descr.attributeDescriptions.put( "dos",
            attributeBuilding( DosAttributesT.class, "dos", DosFileAttributeView.class, DosFileAttributes.class ).
                    addAttribute( "hidden", DosFileAttributes::isHidden ).
                    addAttribute( "archive", DosFileAttributes::isArchive ).
                    addAttribute( "system", DosFileAttributes::isSystem ).
                    addAttribute( "readonly", DosFileAttributes::isReadOnly ).
                    build() );

}
项目: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));
}
项目: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.isDirectory() ? Stat.S_IFDIR : Stat.S_IFREG;
            stat.setMode( type |(dosAttrs.isReadOnly()? 0600 : 0400));
            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;
    }
项目:ats-framework    文件:LocalFileSystemOperations.java   
@Override
public void setFileHiddenAttribute(
                                    String sourceFile,
                                    boolean hidden ) {

    sourceFile = IoUtils.normalizeFilePath(sourceFile, osType);
    checkFileExistence(new File(sourceFile));

    final String errMsg = "Could not " + (hidden
                                                 ? "set"
                                                 : "unset")
                          + " the hidden attribute of file '" + sourceFile + "'";
    if (OperatingSystemType.getCurrentOsType().isWindows()) {
        try {
            Path path = Paths.get(sourceFile);
            DosFileAttributes attr;
            attr = Files.readAttributes(path, DosFileAttributes.class, LinkOption.NOFOLLOW_LINKS);

            boolean goHidden = attr.isHidden();
            if (!hidden && goHidden) {
                Files.setAttribute(path, "dos:hidden", false, LinkOption.NOFOLLOW_LINKS);
            } else if (hidden && !goHidden) {
                Files.setAttribute(path, "dos:hidden", true, LinkOption.NOFOLLOW_LINKS);
            }
        } catch (IOException e) {
            throw new FileSystemOperationException(errMsg, e);
        }
    } else if (OperatingSystemType.getCurrentOsType().isUnix()) {
        // a '.' prefix makes the file hidden
        String filePath = IoUtils.getFilePath(sourceFile);
        String fileName = IoUtils.getFileName(sourceFile);
        if (hidden) {
            if (fileName.startsWith(".")) {
                log.warn("File '" + sourceFile + "' is already hidden. No changes are made!");
                return;
            } else {
                fileName = "." + fileName;
            }
        } else {
            if (!fileName.startsWith(".")) {
                log.warn("File '" + sourceFile + "' is already NOT hidden. No changes are made!");
                return;
            } else {
                fileName = fileName.substring(1);
            }
        }
        renameFile(sourceFile, filePath + fileName, false);
    } else {
        throw new FileSystemOperationException(errMsg + ": Unknown OS type");
    }
}
项目:fim    文件:DosFilePermissionsTest.java   
private void assertCanSetPermissions(Path file, String permissions) throws IOException {
    DosFilePermissions.setPermissions(context, file, permissions);

    DosFileAttributes dosFileAttributes = Files.readAttributes(file, DosFileAttributes.class);
    assertThat(DosFilePermissions.toString(dosFileAttributes)).isEqualTo(permissions);
}
项目:ephemeralfs    文件:FileAttributesViewBuilder.java   
@Override
public DosFileAttributes readAttributes() throws IOException {
    return snapshotProperties().cast(DosFileAttributes.class);
}
项目:ephemeralfs    文件:DosFileAttributesTest.java   
@Test
public void testReadDos() throws Exception {
    DosFileAttributes attributes = Files.readAttributes(root, DosFileAttributes.class);
    assertNotNull(attributes);
    assertNotNull(attributes.creationTime());
}
项目:ephemeralfs    文件:DosFileAttributesTest.java   
@IgnoreUnless(FsType.WINDOWS)
@Test
public void testSetGetArchiveWindowsFile() throws Exception {


   Path path = Files.createFile(root.resolve("file"));

    DosFileAttributes attributes = Files.readAttributes(path, DosFileAttributes.class);
    assertTrue(attributes.isArchive());


    DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class);
    view.setArchive(false);

    attributes = Files.readAttributes(path, DosFileAttributes.class);
    assertFalse(attributes.isArchive());

    Files.write(path, new byte[] {1});
    attributes = Files.readAttributes(path, DosFileAttributes.class);
    assertTrue(attributes.isArchive());
}
项目:ephemeralfs    文件:DosFileAttributesTest.java   
@IgnoreUnless(FsType.WINDOWS)
@Test
public void testSetGetArchiveWindowsDir() throws Exception {

   Path path = Files.createDirectory(root.resolve("dir"));

    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());
}
项目:bazel    文件:WindowsFileSystem.java   
@Override
protected FileStatus stat(Path path, boolean followSymlinks) throws IOException {
  File file = getIoFile(path);
  final DosFileAttributes attributes;
  try {
    attributes = getAttribs(file, followSymlinks);
  } catch (IOException e) {
    throw new FileNotFoundException(path + ERR_NO_SUCH_FILE_OR_DIR);
  }

  final boolean isSymbolicLink = !followSymlinks && fileIsSymbolicLink(file);
  FileStatus status =
      new FileStatus() {
        @Override
        public boolean isFile() {
          return attributes.isRegularFile() || (isSpecialFile() && !isDirectory());
        }

        @Override
        public boolean isSpecialFile() {
          return attributes.isOther();
        }

        @Override
        public boolean isDirectory() {
          return attributes.isDirectory();
        }

        @Override
        public boolean isSymbolicLink() {
          return isSymbolicLink;
        }

        @Override
        public long getSize() throws IOException {
          return attributes.size();
        }

        @Override
        public long getLastModifiedTime() throws IOException {
          return attributes.lastModifiedTime().toMillis();
        }

        @Override
        public long getLastChangeTime() {
          // This is the best we can do with Java NIO...
          return attributes.lastModifiedTime().toMillis();
        }

        @Override
        public long getNodeId() {
          // TODO(bazel-team): Consider making use of attributes.fileKey().
          return -1;
        }
      };

  return status;
}
项目:bazel    文件:WindowsFileSystem.java   
private static DosFileAttributes getAttribs(File file, boolean followSymlinks)
    throws IOException {
  return Files.readAttributes(
      file.toPath(), DosFileAttributes.class, symlinkOpts(followSymlinks));
}
项目:jimfs    文件:DosAttributeProvider.java   
@Override
public Class<DosFileAttributes> attributesType() {
  return DosFileAttributes.class;
}
项目:jimfs    文件:DosAttributeProvider.java   
@Override
public DosFileAttributes readAttributes(File file) {
  return new Attributes(file);
}
项目:jimfs    文件:DosAttributeProvider.java   
@Override
public DosFileAttributes readAttributes() throws IOException {
  return new Attributes(lookupFile());
}
项目:glusterfs-java-filesystem    文件:GlusterFileSystemProviderTest.java   
@Test(expected = UnsupportedOperationException.class)
public void testReadAttributes_whenDosAttributes() throws IOException {
    provider.readAttributes(mockPath, DosFileAttributes.class);
}