test/java/io/Serializable/evolution/RenamePackage/install/SerialDriver.java
Print this page
rev 3565 : 7022624: use try-with-resources in java.io tests
Reviewed-by: XXX
*** 25,35 ****
*
* @bug 4087295
* @build install/SerialDriver.java test/SerialDriver.java extension/ExtendedObjectInputStream.java
* @summary Enable resolveClass() to accommodate package renaming.
* This fix enables one to implement a resolveClass method that maps a
! * Serialiazable class within a serialization stream to the same class
* in a different package within the JVM runtime. See run shell script
* for instructions on how to run this test.
*/
package install;
--- 25,35 ----
*
* @bug 4087295
* @build install/SerialDriver.java test/SerialDriver.java extension/ExtendedObjectInputStream.java
* @summary Enable resolveClass() to accommodate package renaming.
* This fix enables one to implement a resolveClass method that maps a
! * Serializable class within a serialization stream to the same class
* in a different package within the JVM runtime. See run shell script
* for instructions on how to run this test.
*/
package install;
*** 84,120 ****
}
File f = new File("stream.ser");
if (serialize) {
// Serialize the subclass
! try {
! FileOutputStream fo = new FileOutputStream(f);
! ObjectOutputStream so = new ObjectOutputStream(fo);
so.writeObject(obj);
/* Skip arrays since they do not work with rename yet.
The serialVersionUID changes due to the name change
and there is no way to set the serialVersionUID for an
array. */
so.writeObject(array);
- so.flush();
} catch (Exception e) {
System.out.println(e);
throw e;
}
}
if (deserialize) {
// Deserialize the subclass
! try {
! FileInputStream fi = new FileInputStream(f);
! ExtendedObjectInputStream si =
! new ExtendedObjectInputStream(fi);
si.addRenamedClassName("test.SerialDriver", "install.SerialDriver");
si.addRenamedClassName("[Ltest.SerialDriver;",
"[Linstall.SerialDriver");
obj = (SerialDriver) si.readObject();
array = (SerialDriver[]) si.readObject();
- si.close();
} catch (Exception e) {
System.out.println(e);
throw e;
}
System.out.println();
--- 84,117 ----
}
File f = new File("stream.ser");
if (serialize) {
// Serialize the subclass
! try (FileOutputStream fo = new FileOutputStream(f);
! ObjectOutputStream so = new ObjectOutputStream(fo))
! {
so.writeObject(obj);
/* Skip arrays since they do not work with rename yet.
The serialVersionUID changes due to the name change
and there is no way to set the serialVersionUID for an
array. */
so.writeObject(array);
} catch (Exception e) {
System.out.println(e);
throw e;
}
}
if (deserialize) {
// Deserialize the subclass
! try (FileInputStream fi = new FileInputStream(f);
! ExtendedObjectInputStream si = new ExtendedObjectInputStream(fi))
! {
si.addRenamedClassName("test.SerialDriver", "install.SerialDriver");
si.addRenamedClassName("[Ltest.SerialDriver;",
"[Linstall.SerialDriver");
obj = (SerialDriver) si.readObject();
array = (SerialDriver[]) si.readObject();
} catch (Exception e) {
System.out.println(e);
throw e;
}
System.out.println();