mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-27 19:19:07 +00:00
27 lines
682 B
Java
27 lines
682 B
Java
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();
|
|
}
|
|
}
|