memory-fs

An in-memory NIO.2 file system

License

License

GroupId

GroupId

com.github.robtimus
ArtifactId

ArtifactId

memory-fs
Last Version

Last Version

2.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

memory-fs
An in-memory NIO.2 file system
Project URL

Project URL

https://robtimus.github.io/memory-fs/
Source Code Management

Source Code Management

https://github.com/robtimus/memory-fs

Download memory-fs

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.robtimus/memory-fs/ -->
<dependency>
    <groupId>com.github.robtimus</groupId>
    <artifactId>memory-fs</artifactId>
    <version>2.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.robtimus/memory-fs/
implementation 'com.github.robtimus:memory-fs:2.0.1'
// https://jarcasting.com/artifacts/com.github.robtimus/memory-fs/
implementation ("com.github.robtimus:memory-fs:2.0.1")
'com.github.robtimus:memory-fs:jar:2.0.1'
<dependency org="com.github.robtimus" name="memory-fs" rev="2.0.1">
  <artifact name="memory-fs" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.robtimus', module='memory-fs', version='2.0.1')
)
libraryDependencies += "com.github.robtimus" % "memory-fs" % "2.0.1"
[com.github.robtimus/memory-fs "2.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
com.github.robtimus : fs-core jar 2.0

test (3)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.7.0
org.hamcrest : hamcrest jar 2.2
org.mockito : mockito-core jar 3.5.13

Project Modules

There are no modules declared in this project.

memory-fs

The memory-fs library provides an in-memory NIO.2 file system. It can be used where a NIO.2 file system implementation is required, without needing to write anything to disk.

Creating paths

If the in-memory file system library is available on the class path, it will register a FileSystemProvider for scheme memory. This means that, to create a Path for the in-memory file system, you can simply use Paths.get:

Path path = Paths.get(URI.create("memory:/foo/bar"));

Attributes

File attributes

The in-memory file system fully supports the attributes defined in BasicFileAttributeView and BasicFileAttributes. These are available both with and without prefix basic:.

Besides these attributes, the in-memory file system provides two extra attributes:

  • readOnly: if a file or directory is read only, its contents cannot be modified. For a directory this means that the list of child files and directories cannot be modified. The child files and directories themselves can still be modified if they are not read only.
  • hidden: files and directories can be hidden, allowing the hidden attribute to be used for filtering.

These attributes are accessible through interfaces MemoryFileAttributeView and MemoryFileAttributes (which extend BasicFileAttributeView and BasicFileAttributes respectively), or with prefix memory: (e.g. memory:hidden). The basic attributes are also available using prefix memory:.

File store attributes

When calling getAttribute on a file store, the following attributes are supported:

  • totalSpace: returns the same value as the getTotalSpace method, based on the contents of the in-memory file system.
  • usableSpace: returns the same value as the getUsableSpace method, which is based on the maximum amount of memory available to the JVM.
  • unallocatedSpace: returns the same value as the getUnallocatedSpace method, which is based on the amount of free memory in the JVM.

There is no support for FileStoreAttributeView. Calling getFileStoreAttributeView on a file store will simply return null.

Thread safety

Most operations are atomic and thread safe. Concurrent access to files using streams or channels may give unexpected results though. If concurrent access to files is necessary, it is suggested to use proper synchronisation.

Limitations

The in-memory file system knows the following limitations:

Versions

Version
2.0.1
2.0
1.3
1.2
1.1
1.0.1
1.0