Nebulae is a custom binary file format. The idea is to have a compressed file (ZSTD for V2) that can store any kind of data with a protection layer based on a private key system.
- Custom binary file format.
- Compression (GZIP for V1, ZSTD for V2). // Note that V1 was a prototype made years ago and is not really recommanded to be used, but it's still supported for backward compatibility.
- Protection layer based on a private key system.
View on JitPack : https://jitpack.io/#Niwer1525/Nebulae
Gradle:
repositories {
mavenCentral();
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.Niwer1525:Nebulae:1.0.0'
}Maven:
<repositories>
<repository>
<id>maven-central</id>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.Niwer1525</groupId>
<artifactId>Nebulae</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>Processors are classes that allows you to convert all kind of data to nebulae data and vice versa.
final NebulaeProcessor PROCESSOR_V1 = NebulaeEngine.forVersion(NebulaeVersion.V1, "null"); // The key is ignored for V1, but we need to provide something to avoid an exception.
final NebulaeProcessor PROCESSOR_V2 = NebulaeEngine.forVersion(NebulaeVersion.V2, "mySecretKey");Registering classes is required if you want to serialize custom classes. A few common classes are already registered by default (more will be added in the future). To add your own classes you just have to call one of the registerClass method on the processor:
PROCESSOR_V2.registerClass(MyCustomClass.class);
PROCESSOR_V2.registerClass(MyCustomClass.class, 25); // You can also specify an ID for the class, but it's not required. Keep in mind to not overlap with the default ids.
PROCESSOR_V2.registerClass(MyCustomClass.class, ImmutableSerializer, 25); // You can also specify a custom serializer for the class, but it's not required. The default serializer is based on Kryo's default serializer, so it should work for most classes, but if you have a specific use case you can provide your own serializer.Then you just have to write and read data using the processor:
PROCESSOR.write("This is a text", NebulaeType.DATA, new File("test.nebulae"));Note that NebulaeType is used to indicate the type of data you want to write, it will be primarily used for the
associated icons system.
final String ASSET = PROCESSOR.read(new File("test_folder/test.nebulae"), String.class);Of course you can also write directly to an output stream and read from an input stream:
private static InputStream readFromResources(String path) { return AClass.class.getResourceAsStream(path); }
try (InputStream is = readFromResources("/player_model.nebulae")) {
final var MODEL = PROCESSOR.read(is, byte[].class);
}