/** * Get the files in the folder specified, provided that the filter returns true. * A filter is given each file and its type, and decides which files should be returned * and which should be discarded. To classify files into their type, we read transaction * log files. Should we fail to read these log files after a few times, we look at onTxnErr * to determine what to do. * * @param folder - the folder to scan * @param onTxnErr - how to handle a failure to read a txn log file * @param filter - A function that receives each file and its type, it should return true to have the file returned * @return - the list of files that were scanned and for which the filter returned true */ public static List<File> getFiles(Path folder, BiFunction<File, Directories.FileType, Boolean> filter, Directories.OnTxnErr onTxnErr) { return new LogAwareFileLister(folder, filter, onTxnErr).list(); }
/** * Get the files in the folder specified, provided that the filter returns true. * A filter is given each file and its type, and decides which files should be returned * and which should be discarded. To classify files into their type, we read transaction * log files. Should we fail to read these log files after a few times, we look at onTxnErr * to determine what to do. * * @param folder - the folder to scan * @param onTxnErr - how to handle a failure to read a txn log file * @param filter - A function that receives each file and its type, it should return true to have the file returned * @return - the list of files that were scanned and for which the filter returned true */ public static List<File> getFiles(Path folder, BiFunction<File, Directories.FileType, Boolean> filter, Directories.OnTxnErr onTxnErr) { return new LogAwareFileLister(folder, filter, onTxnErr).list(); }
/** * Get the files in the folder specified, provided that the filter returns true. * A filter is given each file and its type, and decides which files should be returned * and which should be discarded. To classify files into their type, we read transaction * log files. Should we fail to read these log files after a few times, we look at onTxnErr * to determine what to do. * * @param folder - the folder to scan * @param onTxnErr - how to handle a failure to read a txn log file * @param filter - A function that receives each file and its type, it should return true to have the file returned * @return - the list of files that were scanned and for which the filter returned true */ public static List<File> getFiles(Path folder, BiFunction<File, Directories.FileType, Boolean> filter, Directories.OnTxnErr onTxnErr) { return new LogAwareFileLister(folder, filter, onTxnErr).list(); }
List<File> innerList() throws Throwable { list(Files.newDirectoryStream(folder)) .stream() .filter((f) -> !LogFile.isLogFile(f)) .forEach((f) -> files.put(f, FileType.FINAL)); // Since many file systems are not atomic, we cannot be sure we have listed a consistent disk state // (Linux would permit this, but for simplicity we keep our behaviour the same across platforms) // so we must be careful to list txn log files AFTER every other file since these files are deleted last, // after all other files are removed list(Files.newDirectoryStream(folder, '*' + LogFile.EXT)) .stream() .filter(LogFile::isLogFile) .forEach(this::classifyFiles); // Finally we apply the user filter before returning our result return files.entrySet().stream() .filter((e) -> filter.apply(e.getKey(), e.getValue())) .map(Map.Entry::getKey) .collect(Collectors.toList()); }
/** * Get the files in the folder specified, provided that the filter returns true. * A filter is given each file and its type, and decides which files should be returned * and which should be discarded. To classify files into their type, we read transaction * log files. Should we fail to read these log files after a few times, we look at onTxnErr * to determine what to do. * * @param folder - the folder to scan * @param onTxnErr - how to handle a failure to read a txn log file * @param filter - A function that receives each file and its type, it should return true to have the file returned * @return - the list of files that were scanned and for which the filter returned true */ public static List<File> getFiles(Path folder, BiFunction<File, Directories.FileType, Boolean> filter, Directories.OnTxnErr onTxnErr) { return new LogAwareFileLister(folder, filter, onTxnErr).list(); }
List<File> innerList() throws Throwable { list(Files.newDirectoryStream(folder)) .stream() .filter((f) -> !LogFile.isLogFile(f)) .forEach((f) -> files.put(f, FileType.FINAL)); // Since many file systems are not atomic, we cannot be sure we have listed a consistent disk state // (Linux would permit this, but for simplicity we keep our behaviour the same across platforms) // so we must be careful to list txn log files AFTER every other file since these files are deleted last, // after all other files are removed list(Files.newDirectoryStream(folder, '*' + LogFile.EXT)) .stream() .filter(LogFile::isLogFile) .forEach(this::classifyFiles); // Finally we apply the user filter before returning our result return files.entrySet().stream() .filter((e) -> filter.apply(e.getKey(), e.getValue())) .map(Map.Entry::getKey) .collect(Collectors.toList()); }
List<File> innerList() throws Throwable { list(Files.newDirectoryStream(folder)) .stream() .filter((f) -> !LogFile.isLogFile(f)) .forEach((f) -> files.put(f, FileType.FINAL)); // Since many file systems are not atomic, we cannot be sure we have listed a consistent disk state // (Linux would permit this, but for simplicity we keep our behaviour the same across platforms) // so we must be careful to list txn log files AFTER every other file since these files are deleted last, // after all other files are removed list(Files.newDirectoryStream(folder, '*' + LogFile.EXT)) .stream() .filter(LogFile::isLogFile) .forEach(this::classifyFiles); // Finally we apply the user filter before returning our result return files.entrySet().stream() .filter((e) -> filter.apply(e.getKey(), e.getValue())) .map(Map.Entry::getKey) .collect(Collectors.toList()); }
List<File> innerList() throws Throwable { list(Files.newDirectoryStream(folder)) .stream() .filter((f) -> !LogFile.isLogFile(f)) .forEach((f) -> files.put(f, FileType.FINAL)); // Since many file systems are not atomic, we cannot be sure we have listed a consistent disk state // (Linux would permit this, but for simplicity we keep our behaviour the same across platforms) // so we must be careful to list txn log files AFTER every other file since these files are deleted last, // after all other files are removed list(Files.newDirectoryStream(folder, '*' + LogFile.EXT)) .stream() .filter(LogFile::isLogFile) .forEach(this::classifyFiles); // Finally we apply the user filter before returning our result return files.entrySet().stream() .filter((e) -> filter.apply(e.getKey(), e.getValue())) .map(Map.Entry::getKey) .collect(Collectors.toList()); }