This commit is contained in:
Daniel Mills
2021-08-10 06:06:39 -04:00
parent fc4377abaf
commit d0fb3dde66
2 changed files with 31 additions and 12 deletions

View File

@@ -186,18 +186,19 @@ public interface Matter {
}
default <T> MatterSlice<T> slice(Class<?> c) {
if (!hasSlice(c)) {
MatterSlice<?> s = createSlice(c, this);
MatterSlice<T> slice = (MatterSlice<T>) getSlice(c);
if (slice == null) {
slice = (MatterSlice<T>) createSlice(c, this);
if (s == null) {
if (slice == null) {
Iris.error("Unable to find a slice for class " + C.DARK_RED + c.getCanonicalName());
return null;
}
putSlice(c, (MatterSlice<T>) s);
putSlice(c, slice);
}
return (MatterSlice<T>) getSlice(c);
return slice;
}
/**
@@ -254,11 +255,15 @@ public interface Matter {
*/
Map<Class<?>, MatterSlice<?>> getSliceMap();
default void write(File f) throws IOException {
FileOutputStream out = new FileOutputStream(f);
GZIPOutputStream gzo = new GZIPOutputStream(out);
write(gzo);
gzo.close();
write(f, true);
}
default void write(File f, boolean compression) throws IOException {
OutputStream out = new FileOutputStream(f);
write(out);
out.close();
}
/**
@@ -310,9 +315,8 @@ public interface Matter {
static Matter read(File f) throws IOException, ClassNotFoundException {
FileInputStream in = new FileInputStream(f);
GZIPInputStream gzi = new GZIPInputStream(in);
Matter m = read(gzi);
gzi.close();
Matter m = read(in);
in.close();
return m;
}