View Javadoc
1   package org.metricshub.jawk.intermediate;
2   
3   /*-
4    * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5    * Jawk
6    * ჻჻჻჻჻჻
7    * Copyright (C) 2006 - 2025 MetricsHub
8    * ჻჻჻჻჻჻
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   *
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
23   */
24  
25  import java.io.IOException;
26  import java.io.InvalidClassException;
27  import java.io.ObjectInputStream;
28  import java.io.ObjectOutputStream;
29  import java.io.Serializable;
30  
31  class VersionManager implements Serializable {
32  
33  	private static final long serialVersionUID = -2015316238483923915L;
34  
35  	private static final int CLASS_VERSION = 2;
36  
37  	private int instanceVersion = CLASS_VERSION;
38  
39  	private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
40  		instanceVersion = ois.readInt();
41  		if (instanceVersion != CLASS_VERSION) {
42  			throw new InvalidClassException(
43  					"Invalid intermeidate file format (instance version " + instanceVersion
44  							+ " != class version " + CLASS_VERSION + ")");
45  		}
46  	}
47  
48  	private void writeObject(ObjectOutputStream oos) throws IOException {
49  		oos.writeInt(instanceVersion);
50  	}
51  
52  	@Override
53  	public String toString() {
54  		return "intermediate file format version = " + instanceVersion;
55  	}
56  }