Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import io.vertx.core.internal.VertxInternal;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.CopyOption;
import java.nio.file.DirectoryStream;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.FileStore;
import java.nio.file.FileVisitOption;
Expand Down Expand Up @@ -531,7 +531,7 @@ public Void perform() {
raf.setLength(len);
}
} catch (IOException e) {
throw new FileSystemException(getFileAccessErrorMessage("truncate", p) ,e);
throw new FileSystemException(getFileAccessErrorMessage("truncate", p), e);
}
return null;
}
Expand Down Expand Up @@ -840,28 +840,13 @@ public List<String> perform() {
if (!file.isDirectory()) {
throw new FileSystemException("Cannot read directory " + file + ". It's not a directory");
} else {
FilenameFilter fnFilter;
if (filter != null) {
Pattern fnPattern = Pattern.compile(filter);
fnFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return fnPattern.matcher(name).matches();
}
};
} else {
fnFilter = null;
}
File[] files;
if (fnFilter == null) {
files = file.listFiles();
} else {
files = file.listFiles(fnFilter);
}
List<String> ret = new ArrayList<>(files.length);
for (File f : files) {
ret.add(f.getCanonicalPath());
try (DirectoryStream<Path> pathStream = Files.newDirectoryStream(file.toPath(), directoryFilterInternal(filter))) {
List<String> ret = new ArrayList<>();
for (final Path path : pathStream) {
ret.add(path.toRealPath().toString());
}
return ret;
}
return ret;
}
} catch (IOException e) {
throw new FileSystemException(getFolderAccessErrorMessage("read", p), e);
Expand All @@ -870,6 +855,15 @@ public boolean accept(File dir, String name) {
};
}

private static DirectoryStream.Filter<Path> directoryFilterInternal(String filter) {
if (filter == null) {
return entry -> true;
} else {
Pattern filePattern = Pattern.compile(filter);
return entry -> filePattern.matcher(entry.getFileName().toString()).matches();
}
}

private BlockingAction<Buffer> readFileInternal(String path) {
Objects.requireNonNull(path);
return new BlockingAction<Buffer>() {
Expand Down
Loading