@Override public long size() throws IOException { BasicFileAttributes attrs = readAttributes(); // Don't return a size for directories or symbolic links; their sizes are implementation // specific and they can't be read as bytes using the read methods anyway. if (attrs.isDirectory()) { throw new IOException("can't read: is a directory"); } else if (attrs.isSymbolicLink()) { throw new IOException("can't read: is a symbolic link"); } return attrs.size(); }
/** Returns whether or not the file with the given name in the given dir is a directory. */ private static boolean isDirectory( SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException { return dir.getFileAttributeView(name, BasicFileAttributeView.class, options) .readAttributes() .isDirectory(); }
BasicFileAttributes srcAttr = Files.readAttributes(src, BasicFileAttributes.class); if (srcAttr.isDirectory()) { Files.walkFileTree(src, new SimpleFileVisitor<Path>() { @Override
Path path= Paths.get("C:\\Users\\Danny\\Documents\\workspace\\Test\\bin\\SomeFiles"); final List<Path> files=new ArrayList<>(); try { Files.walkFileTree(path, new SimpleFileVisitor<Path>(){ @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if(!attrs.isDirectory()){ files.add(file); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); }
@Override public Optional<Long> sizeIfKnown() { BasicFileAttributes attrs; try { attrs = readAttributes(); } catch (IOException e) { // Failed to get attributes; we don't know the size. return Optional.absent(); } // Don't return a size for directories or symbolic links; their sizes are implementation // specific and they can't be read as bytes using the read methods anyway. if (attrs.isDirectory() || attrs.isSymbolicLink()) { return Optional.absent(); } return Optional.of(attrs.size()); }
@Override public long size() throws IOException { BasicFileAttributes attrs = readAttributes(); // Don't return a size for directories or symbolic links; their sizes are implementation // specific and they can't be read as bytes using the read methods anyway. if (attrs.isDirectory()) { throw new IOException("can't read: is a directory"); } else if (attrs.isSymbolicLink()) { throw new IOException("can't read: is a symbolic link"); } return attrs.size(); }
/** Returns whether or not the file with the given name in the given dir is a directory. */ private static boolean isDirectory( SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException { return dir.getFileAttributeView(name, BasicFileAttributeView.class, options) .readAttributes() .isDirectory(); }
/** Returns whether or not the file with the given name in the given dir is a directory. */ private static boolean isDirectory( SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException { return dir.getFileAttributeView(name, BasicFileAttributeView.class, options) .readAttributes() .isDirectory(); }
@Override public long size() throws IOException { BasicFileAttributes attrs = readAttributes(); // Don't return a size for directories or symbolic links; their sizes are implementation // specific and they can't be read as bytes using the read methods anyway. if (attrs.isDirectory()) { throw new IOException("can't read: is a directory"); } else if (attrs.isSymbolicLink()) { throw new IOException("can't read: is a symbolic link"); } return attrs.size(); }
@Override public Type getType() { try { BasicFileAttributes attributes = java.nio.file.Files.readAttributes( file.toPath(), BasicFileAttributes.class); if (attributes.isDirectory()) { return Type.DIRECTORY; } else if (attributes.isRegularFile()) { return Type.RESOURCE; } else { throw new IllegalStateException( "Path does not represent a configuration resource: " + path); } } catch (NoSuchFileException e) { return Type.UNDEFINED; } catch (IOException e) { throw new IllegalStateException(e); } }
BasicFileAttributes srcAttr = Files.readAttributes(src, BasicFileAttributes.class); if (srcAttr.isDirectory()) { Files.walkFileTree(src, new SimpleFileVisitor<Path>() { @Override
@Override public Optional<Long> sizeIfKnown() { BasicFileAttributes attrs; try { attrs = readAttributes(); } catch (IOException e) { // Failed to get attributes; we don't know the size. return Optional.absent(); } // Don't return a size for directories or symbolic links; their sizes are implementation // specific and they can't be read as bytes using the read methods anyway. if (attrs.isDirectory() || attrs.isSymbolicLink()) { return Optional.absent(); } return Optional.of(attrs.size()); }
@Override public long size() throws IOException { BasicFileAttributes attrs = readAttributes(); // Don't return a size for directories or symbolic links; their sizes are implementation // specific and they can't be read as bytes using the read methods anyway. if (attrs.isDirectory()) { throw new IOException("can't read: is a directory"); } else if (attrs.isSymbolicLink()) { throw new IOException("can't read: is a symbolic link"); } return attrs.size(); }
/** Returns whether or not the file with the given name in the given dir is a directory. */ private static boolean isDirectory( SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException { return dir.getFileAttributeView(name, BasicFileAttributeView.class, options) .readAttributes() .isDirectory(); }
/** * Delete directory recursively. * * @param f Directory. * @param deleteIfExists Ignore delete errors if the file doesn't exist. * @return {@code true} if successful. */ private boolean deleteRecursive(File f, boolean deleteIfExists) { BasicFileAttributes attrs; try { attrs = Files.readAttributes(f.toPath(), BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); } catch (IOException ignore) { return deleteIfExists && !f.exists(); } if (!attrs.isDirectory() || attrs.isSymbolicLink()) return f.delete() || (deleteIfExists && !f.exists()); File[] entries = f.listFiles(); if (entries != null) { for (File entry : entries) { boolean res = deleteRecursive(entry, true); if (!res) return false; } } return f.delete() || (deleteIfExists && !f.exists()); }
@Override public Optional<Long> sizeIfKnown() { BasicFileAttributes attrs; try { attrs = readAttributes(); } catch (IOException e) { // Failed to get attributes; we don't know the size. return Optional.absent(); } // Don't return a size for directories or symbolic links; their sizes are implementation // specific and they can't be read as bytes using the read methods anyway. if (attrs.isDirectory() || attrs.isSymbolicLink()) { return Optional.absent(); } return Optional.of(attrs.size()); }
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.CONTINUE; } final long lastModTime = getLastModTime(file); if (lastModTime < timestampThreshold) { try { Files.deleteIfExists(file); containerState.decrementArchiveCount(); LOG.debug("Deleted archived ContentClaim with ID {} from Container {} because it was older than the configured max archival duration", file.toFile().getName(), containerName); } catch (final IOException ioe) { LOG.warn("Failed to remove archived ContentClaim with ID {} from Container {} due to {}", file.toFile().getName(), containerName, ioe.toString()); if (LOG.isDebugEnabled()) { LOG.warn("", ioe); } } } else if (usableSpace < minRequiredSpace) { notYetExceedingThreshold.add(new ArchiveInfo(container, file, attrs.size(), lastModTime)); } return FileVisitResult.CONTINUE; } });
public FilePropsImpl(BasicFileAttributes attrs) { creationTime = attrs.creationTime().toMillis(); lastModifiedTime = attrs.lastModifiedTime().toMillis(); lastAccessTime = attrs.lastAccessTime().toMillis(); isDirectory = attrs.isDirectory(); isOther = attrs.isOther(); isRegularFile = attrs.isRegularFile(); isSymbolicLink = attrs.isSymbolicLink(); size = attrs.size(); }
/** * Determines the file type of a {@link Path}. * * @param p Path * @return FileType * @throws IOException if file attributes cannot be read */ public static FileType of(Path p) throws IOException { BasicFileAttributes attrs = Files.readAttributes(p, BasicFileAttributes.class); if (attrs.isRegularFile()) { return FileType.REGULAR_FILE; } else if (attrs.isDirectory()) { return FileType.DIR; } else if (attrs.isSymbolicLink()) { return FileType.SYMLINK; } return FileType.OTHER; }
@Override public Optional<Long> sizeIfKnown() { BasicFileAttributes attrs; try { attrs = readAttributes(); } catch (IOException e) { // Failed to get attributes; we don't know the size. return Optional.absent(); } // Don't return a size for directories or symbolic links; their sizes are implementation // specific and they can't be read as bytes using the read methods anyway. if (attrs.isDirectory() || attrs.isSymbolicLink()) { return Optional.absent(); } return Optional.of(attrs.size()); }