diff options
author | Olli Virtanen <olli.virtanen@oath.com> | 2018-06-13 13:38:26 +0200 |
---|---|---|
committer | Olli Virtanen <olli.virtanen@oath.com> | 2018-06-13 13:38:26 +0200 |
commit | d5836f186c269986cb9d86374b54b540bf600930 (patch) | |
tree | e95e2ec309835ef1d285630e87bae5d177e9934b /bundle-plugin/src/main/java/com/yahoo/container/plugin/util/Files.java | |
parent | eb80fb0d3a6004431ff13e36e9f480ccb32ec31f (diff) |
Bundle-plugin Scala code converted to Java
Diffstat (limited to 'bundle-plugin/src/main/java/com/yahoo/container/plugin/util/Files.java')
-rw-r--r-- | bundle-plugin/src/main/java/com/yahoo/container/plugin/util/Files.java | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/Files.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/Files.java new file mode 100644 index 00000000000..bcd5d3768f3 --- /dev/null +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/Files.java @@ -0,0 +1,30 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.plugin.util; + +import java.io.File; +import java.io.FileOutputStream; +import java.util.stream.Stream; + +/** + * @author Tony Vaagenes + * @author ollivir + */ +public class Files { + public static Stream<File> allDescendantFiles(File file) { + if (file.isFile()) { + return Stream.of(file); + } else if (file.isDirectory()) { + return Stream.of(file.listFiles()).flatMap(Files::allDescendantFiles); + } else { + return Stream.empty(); + } + } + + public static <T> T withFileOutputStream(File file, ThrowingFunction<FileOutputStream, T> f) { + try (FileOutputStream fos = new FileOutputStream(file)) { + return f.apply(fos); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} |