Implement CleanUtils class for common file system operations
Create a org.torproject.collector.persist.CleanUtils
class, which should offer the methods listed below. First create the corresponding org.torproject.collector.persist.CleanUtilsTest
class for all these methods. After that make the tests pass.
Use Files.walkFileTree()
and SimpleFileVisitor
for the implementation.
- Basic clean-up method:
/**
* All files in the given directory and below are inspected and
* erased, if they are older than the given cut-off-time.
*/
public static void cleanDir(Path directory, long cutOffTime) {...}
- Remove files with a certain ending:
/**
* All files in the given directory and below are inspected and
* erased, if they are older than the given cut-off-time, and their name
* ends with one of the given patterns.
*/
public static void cleanDirPattern(Path directory, long cutOffTime,
String ... endingStrings) {...}
- Some renaming methods:
/**
* All files in the given directory and below are inspected and renamed
* from <filename><ending> to <fileneame>, if their name ends with the given
* 'ending'.
*/
public static void renameFiles(Path directory, String ending) {...}
/**
* All files in the given directory and below are inspected and renamed
* from <filename>.tmp to <fileneame>, if their name ends with '.tmp'.
*/
public static void renameTmpFiles(Path directory) {
renameFiles(directory, ".tmp");
}