Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-memory file system in java

I want to create a simple in-memory file system in Java, which has one root directory and is able to make new sub directory. In the directory we can make new files, write in them, read from them, delete them and also rename them. Can you please give some advice from where to start (a simple code, or resouce).

like image 677
alle3x Avatar asked May 22 '15 10:05

alle3x


People also ask

What is an in memory file system?

Under the in memory filesystem regular files hold data. Data is dynamically allocated to the file in 128 byte chunks of memory. The individual chunks of memory are tracked by arrays of pointers that record the address of the allocated chunk of memory.

How to create in memory file in Java?

createTempFile("tmp", ". tmp"); FileOutputStream fos = new FileOutputStream(tempFile); fos. write(archiveContent); JarFile jarFile = new JarFile(tempFile); Manifest manifest = jarFile. getManifest();

What is Jimfs in Java?

Jimfs is an in-memory file system for Java 7 and above, implementing the java. nio. file abstract file system APIs.

What is file system in Java?

A file system is the factory for several types of objects: The getPath method converts a system dependent path string, returning a Path object that may be used to locate and access a file. The getPathMatcher method is used to create a PathMatcher that performs match operations on paths.


1 Answers

A custom file system provider must implement the java.nio.file.spi.FileSystemProvider class. A file system provider is identified by a URI scheme such as file, jar, memory, cd.

These links below provide good starting info

http://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/filesystemprovider.html

The link below(not about in memory file system) is about virtual file system. It talks about some design issues which could help you in case you decide to create your own file system.

http://www.flipcode.com/archives/Programming_a_Virtual_File_System-Part_I.shtml

But you could always use already built and tested code.This will be faster and easier to maintain and you will receive support in error conditions.

Take a look at jimfs ( An in-memory file system for Java 7+ )

https://github.com/google/jimfs

Also look into

Commons Virtual File System http://commons.apache.org/proper/commons-vfs/

marschall (An in memory implementation of a JSR-203 file system) https://github.com/marschall/memoryfilesystem

like image 125
Raj Avatar answered Sep 25 '22 05:09

Raj