public static void writeFile(Logic logic, OutputStream os, boolean close) throws IOException { DataOutputStream dos; if (os instanceof DataOutputStream) dos = (DataOutputStream) os; else dos = new DataOutputStream(os); dos.writeInt(logic.getUnknown1()); dos.writeInt(logic.getControllers().size()); for (ControllerEntry controller : logic.getControllers()) { IOLogic.writePoint3s(dos, controller.getPosition()); dos.writeInt(controller.getGroups().size()); for (GroupEntry group : controller.getGroups()) { dos.writeShort(group.getBlockID()); dos.writeInt(group.getBlocks().size()); for (Point3s block : group.getBlocks()) IOLogic.writePoint3s(dos, block); } } if (close) dos.close(); }
public static Logic readFile(InputStream is, boolean close) throws IOException { DataInputStream dis; if (is instanceof DataInputStream) dis = (DataInputStream) is; else dis = new DataInputStream(is); Logic logic = new Logic(); logic.setUnknown1(dis.readInt()); int numControllers = dis.readInt(); for (int i = 0; i < numControllers; i++) { ControllerEntry controller = new ControllerEntry(); controller.setPosition(IOLogic.readPoint3s(dis)); int numGroups = dis.readInt(); for (int j = 0; j < numGroups; j++) { GroupEntry group = new GroupEntry(); group.setBlockID(dis.readShort()); int numBlocks = dis.readInt(); for (int k = 0; k < numBlocks; k++) group.getBlocks().add(IOLogic.readPoint3s(dis)); controller.getGroups().add(group); } logic.getControllers().add(controller); } if (close) dis.close(); return logic; }