Skip to content
Snippets Groups Projects
Commit c2d67e8d authored by Bryan Cazabonne's avatar Bryan Cazabonne
Browse files

Fixed deserialization of TLE caused by the bStarParameterDriver.

Fixes #851
parent 08563720
No related branches found
No related tags found
No related merge requests found
...@@ -1014,4 +1014,46 @@ public class TLE implements TimeStamped, Serializable { ...@@ -1014,4 +1014,46 @@ public class TLE implements TimeStamped, Serializable {
return Collections.singletonList(bStarParameterDriver); return Collections.singletonList(bStarParameterDriver);
} }
/** Replace the instance with a data transfer object for serialization.
* @return data transfer object that will be serialized
*/
private Object writeReplace() {
return new DataTransferObject(line1, line2, utc);
}
/** Internal class used only for serialization. */
private static class DataTransferObject implements Serializable {
/** Serializable UID. */
private static final long serialVersionUID = -1596648022319057689L;
/** First line. */
private String line1;
/** Second line. */
private String line2;
/** The UTC scale. */
private final TimeScale utc;
/** Simple constructor.
* @param line1 the first element (69 char String)
* @param line2 the second element (69 char String)
* @param utc the UTC time scale
*/
DataTransferObject(final String line1, final String line2, final TimeScale utc) {
this.line1 = line1;
this.line2 = line2;
this.utc = utc;
}
/** Replace the deserialized data transfer object with a {@link TLE}.
* @return replacement {@link TLE}
*/
private Object readResolve() {
return new TLE(line1, line2, utc);
}
}
} }
...@@ -18,9 +18,13 @@ package org.orekit.propagation.analytical.tle; ...@@ -18,9 +18,13 @@ package org.orekit.propagation.analytical.tle;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.text.ParseException; import java.text.ParseException;
import org.hipparchus.geometry.euclidean.threed.Vector3D; import org.hipparchus.geometry.euclidean.threed.Vector3D;
...@@ -28,7 +32,9 @@ import org.hipparchus.util.CombinatoricsUtils; ...@@ -28,7 +32,9 @@ import org.hipparchus.util.CombinatoricsUtils;
import org.hipparchus.util.FastMath; import org.hipparchus.util.FastMath;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.orekit.Utils; import org.orekit.Utils;
import org.orekit.errors.OrekitException; import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitMessages; import org.orekit.errors.OrekitMessages;
...@@ -48,6 +54,9 @@ import org.orekit.utils.TimeStampedPVCoordinates; ...@@ -48,6 +54,9 @@ import org.orekit.utils.TimeStampedPVCoordinates;
public class TLETest { public class TLETest {
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
private TLE geoTLE; private TLE geoTLE;
private TLE leoTLE; private TLE leoTLE;
...@@ -648,6 +657,36 @@ public class TLETest { ...@@ -648,6 +657,36 @@ public class TLETest {
Assert.assertEquals(tleISS.getLine2(), rebuilt.getLine2()); Assert.assertEquals(tleISS.getLine2(), rebuilt.getLine2());
} }
@Test
public void testIssue851() throws IOException, ClassNotFoundException {
// Initialize TLE
final TLE tleISS = new TLE("1 25544U 98067A 21035.14486477 .00001026 00000-0 26816-4 0 9998",
"2 25544 51.6455 280.7636 0002243 335.6496 186.1723 15.48938788267977");
String filename = tempFolder.newFile("file.ser").toString();
// Serialization
FileOutputStream fileSer = new FileOutputStream(filename);
ObjectOutputStream outSer = new ObjectOutputStream(fileSer);
outSer.writeObject(tleISS);
outSer.close();
fileSer.close();
// Deserialization
TLE rebuilt = null;
FileInputStream file = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(file);
rebuilt = (TLE) in.readObject();
in.close();
file.close();
// Verify
Assert.assertEquals(tleISS.getLine1(), rebuilt.getLine1());
Assert.assertEquals(tleISS.getLine2(), rebuilt.getLine2());
Assert.assertEquals(tleISS.getBStar(), rebuilt.getBStar(), 1.0e-15);
}
@Before @Before
public void setUp() { public void setUp() {
Utils.setDataRoot("regular-data"); Utils.setDataRoot("regular-data");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment