Skip to content

Commit

Permalink
Improvements IO-API-for-Modules doc (fixes MovingBlocks#3654)
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloCactus authored Jul 17, 2024
1 parent 07a4555 commit f1b7981
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/IO-API-for-Modules.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
I/O API for Modules
=================

To protect the user's system, you cannot use `java.io.File` directly, however a bunch of modules may need access to files. Finally, this feature allow modules to have **limited** access to files. Basically, there are two file operations allowed, `readFile` and `writeFile`, both of them works under the `Terasology/sandbox` directory. Take a look on the instructions bellow to learn how to use them.
To protect the user's system, you cannot use `java.io.File` directly, however a bunch of modules may need access to files. Finally, this feature allow modules to have **limited** access to files. Basically, there are two file operations allowed, `readFile` and `writeFile`, both of them works under the `Terasology/sandbox` directory. This does not allow to create directories. Take a look on the instructions bellow to learn how to use them.

1. The first step is to import and initialize the sandbox file manager where you need it, for this you can do the following:
```java
SandboxFileManager sandboxFileManager = new SandboxFileManager();
```
2. Second, create a consumer. We have two different types of consumers.
* Read file consumer:
* Write file consumer:
```java
// put whatever you need here
byte[] someBytes = new byte[2];
Expand All @@ -21,7 +21,7 @@ Consumer<OutputStream> consumer = outputStream -> {
}
};
```
* Write file consumer:
* Read file consumer:
```java
Consumer<InputStream> consumer = inputStream -> {
try {
Expand All @@ -46,4 +46,4 @@ sandboxFileManager.readFile("file.txt", consumer);
sandboxFileManager.writeFile("file.txt", consumer);
```

Finally, if you wrote any file, you can see them in `Terasology/sandbox` directory. :smiley:
Finally, if you wrote any file, you can see them in `Terasology/sandbox` directory. :smiley:

0 comments on commit f1b7981

Please sign in to comment.