CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-google-jimfs--jimfs

In-memory file system implementation for Java that provides complete java.nio.file API compatibility

Pending
Overview
Eval results
Files

filesystem-creation.mddocs/

File System Creation

The Jimfs class provides static factory methods for creating in-memory file systems with different configuration options.

Core Imports

import com.google.common.jimfs.Jimfs;
import com.google.common.jimfs.Configuration;
import java.nio.file.FileSystem;

Factory Methods

Default File System Creation

Create a file system with platform-appropriate defaults.

public static FileSystem newFileSystem();

Creates a file system using Configuration.forCurrentPlatform() which selects Unix, Mac OS X, or Windows configuration based on the current operating system.

Usage Example:

FileSystem fs = Jimfs.newFileSystem();
Path root = fs.getPath("/");  // Unix-style on Linux/Mac, "C:\" style on Windows

Named File System Creation

Create a file system with a custom name for URI identification.

public static FileSystem newFileSystem(String name);

The file system uses the given name as the host part of its URI. For example, with name "test-fs", the file system URI will be jimfs://test-fs and path URIs will be jimfs://test-fs/path/to/file.

Parameters:

  • name - String name for the file system (used in URI host part)

Usage Example:

FileSystem fs = Jimfs.newFileSystem("my-test-filesystem");
// File system URI: jimfs://my-test-filesystem
// Path URI example: jimfs://my-test-filesystem/work/data.txt

Configured File System Creation

Create a file system with a specific configuration.

public static FileSystem newFileSystem(Configuration configuration);

Parameters:

  • configuration - Configuration object defining file system behavior

Usage Example:

Configuration config = Configuration.unix()
    .toBuilder()
    .setMaxSize(1024 * 1024 * 1024) // 1GB limit
    .setBlockSize(4096)             // 4KB blocks
    .setSupportedFeatures(Feature.LINKS, Feature.SYMBOLIC_LINKS)
    .build();

FileSystem fs = Jimfs.newFileSystem(config);

Named and Configured File System Creation

Create a file system with both a custom name and configuration.

public static FileSystem newFileSystem(String name, Configuration configuration);

Parameters:

  • name - String name for the file system
  • configuration - Configuration object defining file system behavior

Usage Example:

Configuration winConfig = Configuration.windows()
    .toBuilder()
    .setWorkingDirectory("C:\\temp")
    .setAttributeViews("basic", "dos")
    .build();

FileSystem fs = Jimfs.newFileSystem("windows-test", winConfig);

URI Scheme

All Jimfs file systems use the URI scheme:

public static final String URI_SCHEME = "jimfs";

This constant defines the scheme used in all Jimfs file system URIs.

File System Lifecycle

File systems created by these methods:

  • Are immediately available for use with all java.nio.file APIs
  • Exist only in memory and are destroyed when the JVM terminates
  • Can be closed explicitly using fileSystem.close()
  • Support concurrent access from multiple threads
  • Are registered with the system provider for URI-based access via Paths.get(URI)

Integration with Standard APIs

Once created, Jimfs file systems work with all standard Java NIO.2 APIs:

FileSystem fs = Jimfs.newFileSystem(Configuration.unix());

// Standard path operations
Path workDir = fs.getPath("/work");
Path dataFile = workDir.resolve("data.txt");

// Standard file operations
Files.createDirectories(workDir);
Files.write(dataFile, "Hello World".getBytes());
List<String> lines = Files.readAllLines(dataFile);

// Standard stream operations
try (InputStream in = Files.newInputStream(dataFile)) {
    // Process file content
}

Error Handling

File system creation methods may throw:

  • IllegalArgumentException - If the name parameter contains invalid characters for URI construction
  • AssertionError - If an unexpected IOException occurs during file system setup (this should not happen in normal operation)

Install with Tessl CLI

npx tessl i tessl/maven-com-google-jimfs--jimfs

docs

configuration.md

features-monitoring.md

filesystem-creation.md

index.md

path-types.md

tile.json