(c) 2012 University of Manchester, UK support@mygrid.org.uk
Licensed under the GNU Lesser General Public License (LGPL) 2.1. See LICENSE.txt for the full terms of LGPL 2.1.
This is a FileSystemProvider for the Java NIO.2 API that allows wrapping calls to an existing file system, for instance for the purpose of logging, tracing paths in a manifest, etc.
- Java 1.7 or newer
- Maven 3.0 or newer (for building)
mvn clean install
The uk.org.taverna.fswrap.WrappedFileSystemProvider should automatically be registered under the URI scheme "wrap".
For instance, to wrap the default file system:
URI uri = URI.create("wrap:file:///");
try (FileSystem fs = FileSystems.newFileSystem(uri, env)) {
Path p = fs.getPath("tmp", "file.txt");
Files.createFile(p);
}
Or using this convenience method:
try (WrappedFileSystem fs = WrappedFileSystemProvider.wrapDefaultFs()) {
Path p = fs.getPath("tmp", "file.txt");
Files.createFile(p);
}
To register to listen for events occurring through the WrappedFileSystem (Note: not done directly on original file system):
listener = new uk.org.taverna.fswrap.FileSystemEventListener() {
@Override
public void copied(Path source, Path target, CopyOption[] options) {
System.out.println("copied " + source + " to " + target);
}
// ....
};
fs.provider().addFileSystemEventListener(listener);
You may want to use the uk.org.taverna.fswrap.FileSystemEventAdapter as a superclass if you are not interested in every captured event.
Note that in the current version of this library the listener will be informed of operations on any file systems wrapped using WrappedFileSystemProvider.