blob: bcd5d3768f3bbb911a642c48ad2363c41153dfe0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
}
}
}
|