3232import java .io .Reader ;
3333import java .nio .file .Files ;
3434import java .util .List ;
35+ import java .util .function .Predicate ;
3536
3637/**
3738 * Utility methods for common filesystem activities
@@ -129,14 +130,16 @@ public static boolean delete(File toDelete) {
129130 }
130131
131132 public static void copy (File from , File to ) throws IOException {
132- copy (from , to , new NoFilter () );
133+ copy (from , to , ( file ) -> true );
133134 }
134135
135136 public static void copy (File source , File dest , String suffix ) throws IOException {
136- copy (source , dest , suffix == null ? new NoFilter () : new FileSuffixFilter (suffix ));
137+ copy (source , dest , suffix == null
138+ ? (file ) -> true
139+ : (file ) -> file .isDirectory () || file .getAbsolutePath ().endsWith (suffix ));
137140 }
138141
139- private static void copy (File source , File dest , Filter onlyCopy ) throws IOException {
142+ private static void copy (File source , File dest , Predicate < File > onlyCopy ) throws IOException {
140143 if (!source .exists ()) {
141144 return ;
142145 }
@@ -148,8 +151,8 @@ private static void copy(File source, File dest, Filter onlyCopy) throws IOExcep
148151 }
149152 }
150153
151- private static void copyDir (File from , File to , Filter onlyCopy ) throws IOException {
152- if (!onlyCopy .isRequired (from )) {
154+ private static void copyDir (File from , File to , Predicate < File > onlyCopy ) throws IOException {
155+ if (!onlyCopy .test (from )) {
153156 return ;
154157 }
155158
@@ -168,8 +171,8 @@ private static void copyDir(File from, File to, Filter onlyCopy) throws IOExcept
168171 }
169172 }
170173
171- private static void copyFile (File from , File to , Filter onlyCopy ) throws IOException {
172- if (!onlyCopy .isRequired (from )) {
174+ private static void copyFile (File from , File to , Predicate < File > onlyCopy ) throws IOException {
175+ if (!onlyCopy .test (from )) {
173176 return ;
174177 }
175178
@@ -182,35 +185,6 @@ private static void copyFile(File from, File to, Filter onlyCopy) throws IOExcep
182185 }
183186 }
184187
185- /**
186- * Used by file operations to determine whether or not to make use of a file.
187- */
188- public interface Filter {
189- /**
190- * @param file File to be considered.
191- * @return Whether or not to make use of the file in this oprtation.
192- */
193- boolean isRequired (File file );
194- }
195-
196- private static class FileSuffixFilter implements Filter {
197- private final String suffix ;
198-
199- public FileSuffixFilter (String suffix ) {
200- this .suffix = suffix ;
201- }
202-
203- public boolean isRequired (File file ) {
204- return file .isDirectory () || file .getAbsolutePath ().endsWith (suffix );
205- }
206- }
207-
208- private static class NoFilter implements Filter {
209- public boolean isRequired (File file ) {
210- return true ;
211- }
212- }
213-
214188 public static String readAsString (File toRead ) throws IOException {
215189 try (Reader reader = new BufferedReader (new FileReader (toRead ))) {
216190 StringBuilder builder = new StringBuilder ();
0 commit comments