We’d initially built ShrinkWrap as virtual filesystem which would simplify the declaration of deployable archives for a Java Enterprise environment. It’s mostly been successful for two reasons:
- The API is clean, concise, and intuitive
- The backend adaptors allow us to translate the ShrinkWrap grammars into something Java EE containers can understand
Though the project has never had any EE dependencies, its most famous application has always been as the deployment mechanism for the Arquillian Test Platform. Today I can announce that ShrinkWrap is officially equipped with its first SE-targeted feature as backend provider of an in-memory Java7 FileSystem.
Creation of the FileSystem through the NIO.2 API looks like this:
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class,"myArchive.jar"); final Map<String, JavaArchive> environment = new HashMap<>(); environment.put(ShrinkWrapFileSystems.FS_ENV_KEY_ARCHIVE, archive); final URI uri = ShrinkWrapFileSystems.getRootUri(archive); final FileSystem fileSystem = FileSystems.newFileSystem(uri, environment);
And of course we offer a shortcut API:
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class); final FileSystem fileSystem = ShrinkWrapFileSystems.newFileSystem(archive);
From there, simply interact with ShrinkWrap through the NIO.2 classes just as you would with the default filesystem; lots of operations are made easy by the new Files API.
The magic piece backing all I/O is our new implementation of SeekableByteChannel. This interface defines operations for random access to an in-memory byte store in both read and write modes, and our implementation is available for use standalone.
ShrinkWrap Core remains free of dependencies. While the base implementation runs on Java5, this new support does require Java7. To this end, we’ve provided a new Dependency Chain POM to bring in this support without imposing Java7 on all users.
ShrinkWrap NIO.2 is available in versions starting at 1.1.0-alpha-4, now available from Maven Central.