mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-28 03:29:06 +00:00
Smoothiemaps & nbt
This commit is contained in:
26
src/main/java/net/querz/io/Serializer.java
Normal file
26
src/main/java/net/querz/io/Serializer.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package net.querz.io;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface Serializer<T> {
|
||||
|
||||
void toStream(T object, OutputStream out) throws IOException;
|
||||
|
||||
default void toFile(T object, File file) throws IOException {
|
||||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
toStream(object, bos);
|
||||
}
|
||||
}
|
||||
|
||||
default byte[] toBytes(T object) throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
toStream(object, bos);
|
||||
bos.close();
|
||||
return bos.toByteArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user