Introducing an In-Memory File System for Java: ShrinkWrap NIO.2

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:

  1. The API is clean, concise, and intuitive
  2. 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.

In addition, we compose this support together with the ability to be directly added to an archive via MemoryAsset and MemoryNamedAsset.

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.




  1. […] Introducing an In-Memory File System for Java: ShrinkWrap NIO.2 « Exit Condition […]

  2. […] in Java 7. I see at least a couple implementations that support an in-memory file system: ShrinkWrap, […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: