Package java.nio.file.attribute

Examples of java.nio.file.attribute.BasicFileAttributes


    Path path = Paths.get(dir.getPath());
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
        for (Path file: stream) {
          BasicFileAttributeView view = getFileAttributeView(file,
              BasicFileAttributeView.class);
          BasicFileAttributes attr = view.readAttributes();
          if (attr.isDirectory()) {
            foundSubDirs.add(file.toAbsolutePath().toString());
          } else if (attr.isRegularFile()) {
            foundFiles.add(new File(file, attr));
          }
        }
    } catch (IOException | DirectoryIteratorException e) {
      throw new ApplicationContextException("Couldn't read " + dir.getPath(), e);
View Full Code Here


        StringGroup modified = new StringGroup(files.size());

        try {
            int counter = 0;
            for(Resource file : files) {
                BasicFileAttributes attr = file.readAttributes(fileAttributes, LinkOption.NOFOLLOW_LINKS);

                if (Config.isOSPOSIXCompatible()) {
                    access.addString(AeshPosixFilePermissions.toString(((PosixFileAttributes) attr)), counter);
                } else {
                    access.addString("", counter);
                }

                size.addString(makeSizeReadable(attr.size()), counter);

                if (Config.isOSPOSIXCompatible()) {
                    owner.addString(((PosixFileAttributes) attr).owner().getName(), counter);
                    group.addString(((PosixFileAttributes) attr).group().getName(), counter);
                } else {
                    owner.addString("", counter);
                    group.addString("", counter);
                }

                // show year instead of time when file wasn't changed in actual year
                Date lastModifiedTime = new Date(attr.lastModifiedTime().toMillis());

                Calendar lastModifiedCalendar = Calendar.getInstance();
                lastModifiedCalendar.setTime(lastModifiedTime);

                Calendar nowCalendar = Calendar.getInstance();
View Full Code Here


    @Override
    public long getCreation() {
        try {
            BasicFileAttributes attrs = Files.readAttributes(resource.toPath(),
                    BasicFileAttributes.class);
            return attrs.creationTime().toMillis();
        } catch (IOException e) {
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("fileResource.getCreationFail",
                        resource.getPath()), e);
            }
View Full Code Here

      }
      if(source == null || parsedModule == null) {
        return true;
      }
     
      BasicFileAttributes newAttributes;
      try {
        newAttributes = Files.readAttributes(filePath, BasicFileAttributes.class);
      } catch (IOException e) {
        return true;
      }
View Full Code Here

    }

    @Override
    public long getCreation() {
        try {
            BasicFileAttributes attrs = Files.readAttributes(resource.toPath(),
                    BasicFileAttributes.class);
            return attrs.creationTime().toMillis();
        } catch (IOException e) {
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("fileResource.getCreationFail",
                        resource.getPath()), e);
            }
View Full Code Here

     * The {@code canUseCached} parameter determines whether cached attributes
     * for the file can be used or not.
     */
    private Event visit(Path entry, boolean ignoreSecurityException, boolean canUseCached) {
        // need the file attributes
        BasicFileAttributes attrs;
        try {
            attrs = getAttributes(entry, canUseCached);
        } catch (IOException ioe) {
            return new Event(EventType.ENTRY, entry, ioe);
        } catch (SecurityException se) {
            if (ignoreSecurityException)
                return null;
            throw se;
        }

        // at maximum depth or file is not a directory
        int depth = stack.size();
        if (depth >= maxDepth || !attrs.isDirectory()) {
            return new Event(EventType.ENTRY, entry, attrs);
        }

        // check for cycles when following links
        if (followLinks && wouldLoop(entry, attrs.fileKey())) {
            return new Event(EventType.ENTRY, entry,
                             new FileSystemLoopException(entry.toString()));
        }

        // file is a directory, attempt to open it
        DirectoryStream<Path> stream = null;
        try {
            stream = Files.newDirectoryStream(entry);
        } catch (IOException ioe) {
            return new Event(EventType.ENTRY, entry, ioe);
        } catch (SecurityException se) {
            if (ignoreSecurityException)
                return null;
            throw se;
        }

        // push a directory node to the stack and return an event
        stack.push(new DirectoryNode(entry, attrs.fileKey(), stream));
        return new Event(EventType.START_DIRECTORY, entry, attrs);
    }
View Full Code Here

    System.out.printf(">>> Store type is '%s'\n", store.type());
    String fileContentType = Files.probeContentType(filePathRef);
    System.out.printf("File '%s' content type is '%s'\n", f.getName(), fileContentType);
    List<String> content = Files.readAllLines(filePathRef, Charset.defaultCharset());
    System.out.printf("File '%s' content is '%s'\n", f.getName(), content);
    BasicFileAttributes basicAttributes = Files.readAttributes(filePathRef, BasicFileAttributes.class);
    System.out.println("File infos");
    System.out.printf(">>> Creation Time: %s\n", basicAttributes.creationTime());
    System.out.printf(">>> Directory? %s\n", basicAttributes.isDirectory());
    System.out.printf(">>> File? %s\n", basicAttributes.isRegularFile());
    System.out.printf(">>> Last accessed on: %s\n", basicAttributes.lastAccessTime());
    System.out.printf(">>> Last modified on: %s\n", basicAttributes.lastModifiedTime());
    System.out.printf(">>> File size (bytes): %s\n", basicAttributes.size());
    System.out.printf(">>> File key : %s\n", basicAttributes.fileKey());
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    Path tempDirPathRef = Paths.get(tempDir.toURI());
    Path p = null;
    Iterator<Path> tmpIter = null;
    System.out.printf("Files in directory '%s'\n", tempDir.getName());
View Full Code Here

        StringGroup modified = new StringGroup(files.length);

        try {
            int counter = 0;
            for(File file : files) {
                BasicFileAttributes attr = Files.readAttributes(file.toPath(), fileAttributes);

                access.addString(AeshPosixFilePermissions.toString(((PosixFileAttributes) attr)), counter);
                size.addString(makeSizeReadable(attr.size()), counter);
                if(Config.isOSPOSIXCompatible())
                    owner.addString(((PosixFileAttributes) attr).owner().getName(), counter);
                else
                    owner.addString("", counter);
                if(Config.isOSPOSIXCompatible())
                    group.addString(((PosixFileAttributes) attr).group().getName(), counter);
                else
                    owner.addString("", counter);
                modified.addString(DATE_FORMAT.format(new Date(attr.lastModifiedTime().toMillis())), counter);

                counter++;
            }
        }
        catch (IOException e) {
View Full Code Here

        StringGroup modified = new StringGroup(files.length);

        try {
            int counter = 0;
            for(File file : files) {
                BasicFileAttributes attr = Files.readAttributes(file.toPath(), fileAttributes, LinkOption.NOFOLLOW_LINKS);

                if (Config.isOSPOSIXCompatible()) {
                    access.addString(AeshPosixFilePermissions.toString(((PosixFileAttributes) attr)), counter);
                } else {
                    access.addString("", counter);
                }

                size.addString(makeSizeReadable(attr.size()), counter);

                if (Config.isOSPOSIXCompatible()) {
                    owner.addString(((PosixFileAttributes) attr).owner().getName(), counter);
                    group.addString(((PosixFileAttributes) attr).group().getName(), counter);
                } else {
                    owner.addString("", counter);
                    group.addString("", counter);
                }

                // show year instead of time when file wasn't changed in actual year
                Date lastModifiedTime = new Date(attr.lastModifiedTime().toMillis());

                Calendar lastModifiedCalendar = Calendar.getInstance();
                lastModifiedCalendar.setTime(lastModifiedTime);

                Calendar nowCalendar = Calendar.getInstance();
View Full Code Here

        int lastSep = relativePath.lastIndexOf("/");
        return relativePath.substring(lastSep + 1); // safe if "/" not found
    }

    private static boolean isDirectory(Path path) throws IOException {
        BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
        return attrs.isDirectory();
    }
View Full Code Here

TOP

Related Classes of java.nio.file.attribute.BasicFileAttributes

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.