saved search results have serial version

This commit is contained in:
Jindra Petřík
2021-02-23 10:01:22 +01:00
parent 640f34f452
commit c25028ac91
3 changed files with 58 additions and 23 deletions

View File

@@ -54,12 +54,16 @@ public class ABCSearchResult implements Serializable {
private final int traitId;
private static final int SERIAL_VERSION_MAJOR = 1;
private static final int SERIAL_VERSION_MINOR = 0;
@SuppressWarnings("unchecked")
public ABCSearchResult(SWF swf, ObjectInputStream ois) throws IOException, ScriptNotFoundException {
public ABCSearchResult(SWF swf, InputStream is) throws IOException, ScriptNotFoundException {
ObjectInputStream ois = new ObjectInputStream(is);
int versionMajor = ois.read();
ois.read(); //minor
if (versionMajor != 1) {
throw new IOException("Unknown search result version");
if (versionMajor != SERIAL_VERSION_MAJOR) {
throw new IOException("Unknown search result version: " + versionMajor);
}
ClassPath cp;
@@ -88,14 +92,16 @@ public class ABCSearchResult implements Serializable {
}
}
public void save(ObjectOutputStream oos) throws IOException {
oos.write(1); //version major
oos.write(0); //version minor
public void save(OutputStream os) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.write(SERIAL_VERSION_MAJOR);
oos.write(SERIAL_VERSION_MINOR);
oos.writeObject(scriptPack.getClassPath());
oos.writeObject(scriptPack.traitIndices);
oos.writeBoolean(pcode);
oos.writeInt(classIndex);
oos.writeInt(traitId);
oos.flush();
}
public ABCSearchResult(ScriptPack scriptPack) {

View File

@@ -39,8 +39,17 @@ public class ActionSearchResult {
private final String path;
public ActionSearchResult(SWF swf, ObjectInputStream ois) throws IOException, ScriptNotFoundException {
private static final int SERIAL_VERSION_MAJOR = 1;
private static final int SERIAL_VERSION_MINOR = 0;
public ActionSearchResult(SWF swf, InputStream is) throws IOException, ScriptNotFoundException {
Map<String, ASMSource> asms = swf.getASMs(false);
ObjectInputStream ois = new ObjectInputStream(is);
int versionMajor = ois.read();
ois.read(); //minor
if (versionMajor != SERIAL_VERSION_MAJOR) {
throw new IOException("Unknown search result version: " + versionMajor);
}
path = ois.readUTF();
if (asms.containsKey(path)) {
src = asms.get(path);
@@ -50,9 +59,13 @@ public class ActionSearchResult {
pcode = ois.readBoolean();
}
public void save(ObjectOutputStream oos) throws IOException {
public void save(OutputStream os) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.write(SERIAL_VERSION_MAJOR);
oos.write(SERIAL_VERSION_MINOR);
oos.writeUTF(path);
oos.writeBoolean(pcode);
oos.flush();
}
public ActionSearchResult(ASMSource src, boolean pcode, String path) {