diff --git a/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java b/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java index 3cc31f349..e650b5cee 100644 --- a/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java +++ b/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java @@ -362,7 +362,7 @@ public abstract class AbstractStepInterpolator /** {@inheritDoc} */ public abstract void readExternal(ObjectInput in) - throws IOException; + throws IOException, ClassNotFoundException; /** Save the base state of the instance. * This method performs step finalization if it has not been done diff --git a/src/java/org/apache/commons/math/ode/sampling/NordsieckStepInterpolator.java b/src/java/org/apache/commons/math/ode/sampling/NordsieckStepInterpolator.java index 85fa2eee1..b408a0bae 100644 --- a/src/java/org/apache/commons/math/ode/sampling/NordsieckStepInterpolator.java +++ b/src/java/org/apache/commons/math/ode/sampling/NordsieckStepInterpolator.java @@ -187,18 +187,64 @@ public class NordsieckStepInterpolator extends AbstractStepInterpolator { @Override public void writeExternal(final ObjectOutput out) throws IOException { + + // save the state of the base class writeBaseExternal(out); + + // save the local attributes + out.writeDouble(scalingH); + out.writeDouble(referenceTime); + + final int n = (currentState == null) ? -1 : currentState.length; + if (scaled == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + for (int j = 0; j < n; ++j) { + out.writeDouble(scaled[j]); + } + } + + if (nordsieck == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + out.writeObject(nordsieck); + } + } /** {@inheritDoc} */ @Override public void readExternal(final ObjectInput in) - throws IOException { + throws IOException, ClassNotFoundException { // read the base class final double t = readBaseExternal(in); - if ((scaled != null) && (nordsieck != null)) { + // read the local attributes + scalingH = in.readDouble(); + referenceTime = in.readDouble(); + + final int n = (currentState == null) ? -1 : currentState.length; + final boolean hasScaled = in.readBoolean(); + if (hasScaled) { + scaled = new double[n]; + for (int j = 0; j < n; ++j) { + scaled[j] = in.readDouble(); + } + } else { + scaled = null; + } + + final boolean hasNordsieck = in.readBoolean(); + if (hasNordsieck) { + nordsieck = (Array2DRowRealMatrix) in.readObject(); + } else { + nordsieck = null; + } + + if (hasScaled && hasNordsieck) { // we can now set the interpolated time and state setInterpolatedTime(t); } diff --git a/src/test/org/apache/commons/math/ode/sampling/NordsieckStepInterpolatorTest.java b/src/test/org/apache/commons/math/ode/sampling/NordsieckStepInterpolatorTest.java index f7f772a53..1e2db9858 100644 --- a/src/test/org/apache/commons/math/ode/sampling/NordsieckStepInterpolatorTest.java +++ b/src/test/org/apache/commons/math/ode/sampling/NordsieckStepInterpolatorTest.java @@ -62,8 +62,8 @@ public class NordsieckStepInterpolatorTest { oos.writeObject(handler); } - assertTrue(bos.size () > 16000); - assertTrue(bos.size () < 17000); + assertTrue(bos.size () > 20000); + assertTrue(bos.size () < 25000); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bis);