in pekko-connectors-sample-rotate-logs-to-ftp/src/main/java/playground/filesystem/impl/JimfsFtpFile.java [251:294]
public List<FtpFile> listFiles() {
// is a directory
if (!Files.isDirectory(path)) {
return null;
}
// directory - return all the files
DirectoryStream<Path> filesStream = null;
try {
filesStream = Files.newDirectoryStream(path);
} catch(IOException t) {
LOG.error(t.getMessage());
}
if (filesStream == null) {
return null;
}
List<Path> files = new ArrayList<>();
for (Path path : filesStream) {
files.add(path);
}
// make sure the files are returned in order
Collections.sort(files, new Comparator<Path>() {
public int compare(Path o1, Path o2) {
return o1.getFileName().compareTo(o2.getFileName());
}
});
// get the virtual name of the base directory
final String virtualFileStr =
getAbsolutePath().charAt(getAbsolutePath().length() - 1) != '/'
? getAbsolutePath() + '/' : getAbsolutePath();
// now return all the files under the directory
List<FtpFile> virtualFiles = new ArrayList<>(files.size());
for (Path file : files) {
String fileName = virtualFileStr + file.getFileName();
virtualFiles.add(new JimfsFtpFile(fileName, file, user));
}
return virtualFiles;
}