Maybe, Fix Schematics Readers

This commit is contained in:
2024-12-03 22:43:14 +01:00
parent 57d4727f35
commit 0134ef1f61
18 changed files with 1010 additions and 125 deletions

View File

@@ -28,12 +28,15 @@ import java.sql.PreparedStatement;
import java.util.zip.GZIPInputStream;
@AllArgsConstructor
@Getter
public class NodeData {
static {
new SqlTypeMapper<>(PipedInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("PipedInputStream is write only datatype"); }, PreparedStatement::setBinaryStream);
new SqlTypeMapper<>(ByteArrayInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("ByteArrayInputStream is write only datatype"); }, PreparedStatement::setBinaryStream);
new SqlTypeMapper<>(BufferedInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("BufferedInputStream is write only datatype"); }, PreparedStatement::setBinaryStream);
SqlTypeMapper.ordinalEnumMapper(SchematicFormat.class);
}
private static final Table<NodeData> table = new Table<>(NodeData.class);
@@ -48,21 +51,24 @@ public class NodeData {
throw new IllegalArgumentException("Node is a directory");
return get.select(rs -> {
if(rs.next()) {
return new NodeData(node.getId(), rs.getBoolean("NodeFormat"));
return new NodeData(node.getId(), SchematicFormat.values()[rs.getInt("NodeFormat")]);
} else {
return new NodeData(node.getId(), false);
return new NodeData(node.getId(), SchematicFormat.MCEDIT);
}
}, node);
}
@Getter
@Field(keys = {Table.PRIMARY})
private final int nodeId;
@Field
private boolean nodeFormat;
private SchematicFormat nodeFormat;
public InputStream schemData() throws IOException {
return new GZIPInputStream(schemDataRaw());
}
public InputStream schemDataRaw() throws IOException {
try {
return selSchemData.select(rs -> {
rs.next();
@@ -81,12 +87,18 @@ public class NodeData {
}
}
public void saveFromStream(InputStream blob, boolean newFormat) {
public void saveFromStream(InputStream blob, SchematicFormat newFormat) {
updateDatabase.update(nodeId, newFormat, blob);
nodeFormat = newFormat;
}
public boolean getNodeFormat() {
return nodeFormat;
@AllArgsConstructor
@Getter
public enum SchematicFormat {
MCEDIT(".schematic"),
V2(".schem"),
V3(".schem");
private final String fileEnding;
}
}

View File

@@ -375,11 +375,10 @@ public class SchematicNode {
return nodeType == null;
}
@Deprecated
public boolean getSchemFormat() {
public String getFileEnding() {
if(isDir())
throw new SecurityException("Node is Directory");
return NodeData.get(this).getNodeFormat();
return NodeData.get(this).getNodeFormat().getFileEnding();
}
public int getRank() {