Mariusz Czarnowski 4 лет назад
Родитель
Сommit
91aa2d6de7

+ 2 - 2
assira.core/src/main/java/net/ranides/assira/io/IOStreams.java

@@ -197,8 +197,8 @@ public final class IOStreams {
             } catch(IOException cause) {
                 listener.handleEvent(IOEvent.failure(cause));
             } finally {
-                IOUtils.close(input, listener);
-                IOUtils.close(output, listener);
+                IOUtils.close(input, listener.consumer(IOEvent::failure));
+                IOUtils.close(output, listener.consumer(IOEvent::failure));
                 listener.handleEvent(IOEvent.close(input));
                 listener.handleEvent(IOEvent.close(output));
             }

+ 3 - 3
assira.core/src/main/java/net/ranides/assira/io/IOUtils.java

@@ -45,12 +45,12 @@ public final class IOUtils {
         return false;
     }
     
-    public static boolean close(Closeable object, EventListener<? super IOEvent.Failure> listener) {
+    public static boolean close(Closeable object, Consumer<IOException> handler) {
         try {
             return close(object);
         } catch(IOException cause) {
-            if(null != listener) {
-                listener.handleEvent(IOEvent.failure(cause));
+            if(null != handler) {
+                handler.accept(cause);
             } else {
                 LOGGER.warn("Exception ignored on #close", cause);
             }

+ 21 - 3
assira.core/src/main/java/net/ranides/assira/io/PathUtils.java

@@ -6,12 +6,14 @@
  */
 package net.ranides.assira.io;
 
+import net.ranides.assira.collection.query.CQuery;
+
 import java.io.File;
+import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Locale;
+import java.nio.file.*;
+import java.util.*;
 
 /**
  *
@@ -100,4 +102,20 @@ public final class PathUtils {
     public static String normalize(String path) {
         return Paths.get(Paths.get(path).toUri().normalize()).toString();
     }
+
+    public static CQuery<Path> list(Path dir) {
+        try {
+            return CQuery.from().stream(() -> Files.list(dir));
+        } catch (IOException e) {
+            return CQuery.empty();
+        }
+    }
+
+    public static CQuery<Path> walk(Path dir) {
+        try {
+            return CQuery.from().stream(() -> Files.walk(dir, FileVisitOption.FOLLOW_LINKS));
+        } catch (IOException e) {
+            return CQuery.empty();
+        }
+    }
 }