mirror of https://github.com/apache/lucene.git
LUCENE-10144:fix resource leak due to Files.list (#354)
* LUCENE-10144:fix resource leak due to Files.list * LUCENE-10144:fix resource leak due to Files.list
This commit is contained in:
parent
cdc7d87fcc
commit
cbb5b6e331
|
@ -27,6 +27,7 @@ import java.nio.file.Paths;
|
|||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Split the Reuters SGML documents into Simple Text files containing:
|
||||
|
@ -44,9 +45,10 @@ public class ExtractReuters {
|
|||
public void extract() throws IOException {
|
||||
long count = 0;
|
||||
Files.createDirectories(outputDir);
|
||||
|
||||
if (Files.list(outputDir).count() > 0) {
|
||||
throw new IOException("The output directory must be empty: " + outputDir);
|
||||
try(Stream<Path> files = Files.list(outputDir)) {
|
||||
if (files.count() > 0) {
|
||||
throw new IOException("The output directory must be empty: " + outputDir);
|
||||
}
|
||||
}
|
||||
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(reutersDir, "*.sgm")) {
|
||||
|
|
Loading…
Reference in New Issue