RESTORE snapshot test with modifications using DirectoryStream API
package org.apache.ignite.internal.util.lang;
+import java.io.IOException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -41,6 +45,7 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import javax.cache.Cache;
import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.compute.ComputeJobResult;
import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException;
@@ -2312,6 +2317,23 @@ public class GridFunc {
return m == null || m.isEmpty();
}
+ /**
+ * Tests if the given path is a directory and is not {@code null} or empty.
+ *
+ * @param dir Path to test.
+ * @return Whether or not the given path is a directory and is not {@code null} or empty.
+ */
+ public static boolean isEmptyDirectory(Path dir) {
+ if (dir == null || !Files.isDirectory(dir))
+ return false;
+ try (DirectoryStream<Path> files = Files.newDirectoryStream(dir)) {
+ return !files.iterator().hasNext();
+ }
+ catch (IOException e) {
+ throw new IgniteException(e);
+ }
+ }
+
/**
* Converts collection of numbers to primitive {@code int[]} array.
*
