mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 08:18:52 -05:00
Close File handle
This commit is contained in:
parent
e4e5c01cd7
commit
9e33199776
@ -43,6 +43,7 @@ import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
@ -172,7 +173,14 @@ public final class FileUtilities {
|
||||
}
|
||||
|
||||
public static Stream<String> streamLines(File file) throws IOException {
|
||||
return new BufferedReader(new UnicodeReader(new BufferedInputStream(new FileInputStream(file)), false, UTF_8), BUFFER_SIZE).lines();
|
||||
BufferedReader reader = new BufferedReader(new UnicodeReader(new BufferedInputStream(new FileInputStream(file)), false, UTF_8), BUFFER_SIZE);
|
||||
return reader.lines().onClose(() -> {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
debug.log(Level.SEVERE, "Failed to close file: " + file, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String readTextFile(File file) throws IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user