https://github.com/kjarosh/jfm
Java Filesystem Mapper
https://github.com/kjarosh/jfm
filesystem fuse java object-mapping
Last synced: 7 months ago
JSON representation
Java Filesystem Mapper
- Host: GitHub
- URL: https://github.com/kjarosh/jfm
- Owner: kjarosh
- License: mit
- Created: 2019-03-26T20:55:14.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-06-19T16:56:54.000Z (almost 3 years ago)
- Last Synced: 2025-04-03T10:43:44.534Z (about 1 year ago)
- Topics: filesystem, fuse, java, object-mapping
- Language: Java
- Homepage:
- Size: 245 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Java Filesystem Mapper
[](https://github.com/kjarosh/jfm/actions/workflows/maven.yml)
[](https://www.codacy.com/app/kjarosh/jfm?utm_source=github.com&utm_medium=referral&utm_content=kjarosh/jfm&utm_campaign=Badge_Grade)
[](https://codeclimate.com/github/kjarosh/jfm/maintainability)
[](https://jitpack.io/#kjarosh/jfm)
## What is it?
This is a library used to map filesystem resources to Java objects and vice-versa.
## Features
- mapping filesystem resources to Java objects,
- mapping Java objects to filesystem resources,
- registering custom type handlers.
## Example
Interface:
```java
@FilesystemResource
interface PersonInfo {
@Read
@Path("first-name")
String getFirstName();
@Read
@Path("last-name")
String getLastName();
}
```
### Filesystem to Java mapping
Filesystem:
```text
persons
|- person1
| |- first-name
| \- last-name
\- person2
|- first-name
\- last-name
```
The following code maps the above filesystem into instances of `PersonInfo`.
```java
Path root = Paths.get("persons");
FilesystemMapper fsmapper = FilesystemMapper.instance();
FilesystemMapperTarget person1Target = fsmapper.getTarget(root.resolve("person1"));
FilesystemMapperTarget person2Target = fsmapper.getTarget(root.resolve("person2"));
PersonInfo person1 = person1Target.proxy(PersonInfo.class);
PersonInfo person2 = person2Target.proxy(PersonInfo.class);
// print contents of persons/person1/first-name
System.out.println(person1.getFirstName());
// print contents of persons/person1/last-name
System.out.println(person1.getLastName());
// print contents of persons/person2/first-name
System.out.println(person2.getFirstName());
// print contents of persons/person2/last-name
System.out.println(person2.getLastName());
```
## Java to filesystem mapping
Implementation:
```java
class PersonInfoImpl implements PersonInfo {
public String getFirstName() {
return "John";
}
public String getLastName() {
return "Smith";
}
}
```
The following code maps the above implementation into the filesystem.
```java
Path root = Paths.get("person");
FilesystemMapper fsmapper = FilesystemMapper.instance();
FilesystemMapperTarget personTarget = fsmapper.getTarget(root);
PersonInfo person = new PersonInfoImpl();
personTarget.mount(person);
```
The resulting filesystem:
```text
person
|- first-name
\- last-name
```
The contents of `person/first-name` and `person/last-name` should be `John`
and `Smith` respectively.