public abstract class FileSystem
extends java.lang.Object
implements java.io.Closeable
var inputFile = "input.fbx";
var format = FileFormat.detect(inputFile);
//create a load options instance and specify a zip file system
var opt = format.createLoadOptions();
opt.setFileSystem(new LocalFileSystem("textures/"));
//load the file
var scene = Scene.fromFile(inputFile, opt);
| Constructor and Description |
|---|
FileSystem() |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Dispose the File system and release its resources.
|
static FileSystem |
createDummyFileSystem()
Create a dummy file system, read/write operations are dummy operations.
|
static FileSystem |
createLocalFileSystem(java.lang.String directory)
Initialize a new
FileSystem that only access local directory. |
static FileSystem |
createMemoryFileSystem()
Create a memory-based file system which will maps the read/write operations to memory.
|
static FileSystem |
createMemoryFileSystem(java.util.HashMap<java.lang.String,MemoryStream> files)
Create a memory-based file system which will maps the read/write operations to memory.
|
static FileSystem |
createZipFileSystem(Stream stream)
Create a file system to provide to the read-only access to speicified zip file or zip stream.
|
static FileSystem |
createZipFileSystem(Stream stream,
java.lang.String baseDir)
Create a file system to provide to the read-only access to speicified zip file or zip stream.
|
static FileSystem |
createZipFileSystem(java.lang.String fileName)
File system to provide to the read-only access to speicified zip file or zip stream.
|
abstract Stream |
readFile(java.lang.String fileName,
IOConfig options)
Create a stream for reading dependencies.
|
abstract Stream |
writeFile(java.lang.String fileName,
IOConfig options)
Create a stream for writing dependencies.
|
public abstract Stream readFile(java.lang.String fileName, IOConfig options) throws java.io.IOException
fileName - File's name to open for readingoptions - Save or load optionsjava.io.IOException - The implementation throws this exception when failed to open the file for reading.public abstract Stream writeFile(java.lang.String fileName, IOConfig options) throws java.io.IOException
fileName - The file's name to open for writingoptions - Save or load optionsjava.io.IOException - Thrown when failed to open stream for writingpublic static FileSystem createLocalFileSystem(java.lang.String directory) throws java.io.FileNotFoundException
FileSystem that only access local directory.
All file read/write on this FileSystem instance will be mapped to specified directory.directory - The directory in your physical file system as the virtual root directory.java.io.FileNotFoundException - Thrown when directory cannot be found.
Example:
The following code shows how to import file, and provide dependent files in a given directory
var inputFile = "input.fbx";
var format = FileFormat.detect(inputFile);
//create a load options instance and specify a local file system
var opt = format.createLoadOptions();
opt.setFileSystem(FileSystem.createLocalFileSystem("textures/"));
//load the file
var scene = Scene.fromFile(inputFile, opt);
public static FileSystem createMemoryFileSystem(java.util.HashMap<java.lang.String,MemoryStream> files)
files - This allows you to read/write the virtual files.
//create a scene with material
Scene scene = new Scene();
scene.getRootNode().createChildNode(new Box()).setMaterial(new LambertMaterial());
//create a save option and specify the file system, so the dependent file will be written to memory
var opt = FileFormat.WAVEFRONTOBJ.createSaveOptions();
var mfs = new HashMap<String, MemoryStream>();
opt.setFileSystem(FileSystem.createMemoryFileSystem(mfs));
//obj's material file name is associated with the obj's file name, so we need a explicit name.
opt.setFileName("test.obj");
try (var ms = new MemoryStream())
{
scene.save(ms, opt);
}
//the test.obj was written to variable ms, and we can also get the test.mtl file content by
var materialFile = mfs.get("test.mtl");
public static FileSystem createMemoryFileSystem()
//create a scene with material
Scene scene = new Scene();
scene.getRootNode().createChildNode(new Box()).setMaterial(new LambertMaterial());
//create a save option and specify the file system, so the dependent file will be written to memory
var opt = FileFormat.WAVEFRONTOBJ.createSaveOptions();
var mfs = new HashMap<String, MemoryStream>();
opt.setFileSystem(FileSystem.createMemoryFileSystem(mfs));
//obj's material file name is associated with the obj's file name, so we need a explicit name.
opt.setFileName("test.obj");
try (var ms = new MemoryStream())
{
scene.save(ms, opt);
}
//the test.obj was written to variable ms, and we can also get the test.mtl file content by
var materialFile = mfs.get("test.mtl");
public static FileSystem createDummyFileSystem()
//create a scene with material
Scene scene = new Scene();
scene.getRootNode().createChildNode(new Box()).setMaterial(new LambertMaterial());
//create a save option and specify the file system, so the dependent file will be written to memory
var opt = FileFormat.WAVEFRONTOBJ.createSaveOptions();
var dfs = FileSystem.CreateDummyFileSystem();
opt.setFileSystem(dfs);
//obj's material file name is associated with the obj's file name, so we need a explicit name.
opt.setFileName("test.obj");
try (var ms = new MemoryStream())
{
scene.save(ms, opt);
}
public static FileSystem createZipFileSystem(Stream stream, java.lang.String baseDir) throws java.io.IOException
stream - The stream to access the zip filebaseDir - The base directory inside the zip file.java.io.IOException - Thrown when failed to read from stream.
Remarks:
This is a read-only file system, so no write operations are supported.
Example:
The following code shows how to import file, and provide dependent files in a zip archive file.
var inputFile = "input.fbx";
var format = FileFormat.detect(inputFile);
//create a load options instance and specify a zip file system
var opt = format.createLoadOptions();
opt.setFileSystem(FileSystem.createZipFileSystem("textures.zip"));
//load the file
var scene = Scene.fromFile(inputFile, opt);
public static FileSystem createZipFileSystem(Stream stream) throws java.io.IOException
stream - The stream to access the zip filejava.io.IOException - Thrown when failed to read from stream.
Remarks:
This is a read-only file system, so no write operations are supported.
Example:
The following code shows how to import file, and provide dependent files in a zip archive file.
var inputFile = "input.fbx";
var format = FileFormat.detect(inputFile);
//create a load options instance and specify a zip file system
var opt = format.createLoadOptions();
opt.setFileSystem(FileSystem.createZipFileSystem("textures.zip"));
//load the file
var scene = Scene.fromFile(inputFile, opt);
public static FileSystem createZipFileSystem(java.lang.String fileName) throws java.io.IOException
fileName - File name to the zip file.java.io.IOException - Thrown when failed to read from stream.
Example:
The following code shows how to import file, and provide dependent files in a zip archive file.
var inputFile = "input.fbx";
var format = FileFormat.detect(inputFile);
//create a load options instance and specify a zip file system
var opt = format.createLoadOptions();
opt.setFileSystem(FileSystem.createZipFileSystem("textures.zip"));
//load the file
var scene = Scene.fromFile(inputFile, opt);
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOException