Path: blob/master/src/java.base/share/classes/java/nio/file/SimpleFileVisitor.java
41159 views
/*1* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.nio.file;2627import java.nio.file.attribute.BasicFileAttributes;28import java.io.IOException;29import java.util.Objects;3031/**32* A simple visitor of files with default behavior to visit all files and to33* re-throw I/O errors.34*35* <p> Methods in this class may be overridden subject to their general contract.36*37* @param <T> The type of reference to the files38*39* @since 1.740*/4142public class SimpleFileVisitor<T> implements FileVisitor<T> {43/**44* Initializes a new instance of this class.45*/46protected SimpleFileVisitor() {47}4849/**50* Invoked for a directory before entries in the directory are visited.51*52* <p> Unless overridden, this method returns {@link FileVisitResult#CONTINUE53* CONTINUE}.54*/55@Override56public FileVisitResult preVisitDirectory(T dir, BasicFileAttributes attrs)57throws IOException58{59Objects.requireNonNull(dir);60Objects.requireNonNull(attrs);61return FileVisitResult.CONTINUE;62}6364/**65* Invoked for a file in a directory.66*67* <p> Unless overridden, this method returns {@link FileVisitResult#CONTINUE68* CONTINUE}.69*/70@Override71public FileVisitResult visitFile(T file, BasicFileAttributes attrs)72throws IOException73{74Objects.requireNonNull(file);75Objects.requireNonNull(attrs);76return FileVisitResult.CONTINUE;77}7879/**80* Invoked for a file that could not be visited.81*82* <p> Unless overridden, this method re-throws the I/O exception that prevented83* the file from being visited.84*/85@Override86public FileVisitResult visitFileFailed(T file, IOException exc)87throws IOException88{89Objects.requireNonNull(file);90throw exc;91}9293/**94* Invoked for a directory after entries in the directory, and all of their95* descendants, have been visited.96*97* <p> Unless overridden, this method returns {@link FileVisitResult#CONTINUE98* CONTINUE} if the directory iteration completes without an I/O exception;99* otherwise this method re-throws the I/O exception that caused the iteration100* of the directory to terminate prematurely.101*/102@Override103public FileVisitResult postVisitDirectory(T dir, IOException exc)104throws IOException105{106Objects.requireNonNull(dir);107if (exc != null)108throw exc;109return FileVisitResult.CONTINUE;110}111}112113114