Why can't I save the required object to the hard disk?

I want to save the BoundedPropagator object to the hard disk after java serialization, but now it can’t be saved when serialization. Is there a good solution?

    public static BoundedPropagator getEphemeris() {
        Path path = Paths.get("d:/", "config.data");
        if (Files.exists(path)) {
            try (ObjectInputStream objectInputStream = new ObjectInputStream(Files.newInputStream(path))) {
                BoundedPropagatorBO boundedPropagatorBO = (BoundedPropagatorBO) objectInputStream.readObject();
                return boundedPropagatorBO.getGeneratedEphemeris();
            } catch (IOException e) {
                throw new RuntimeException(e);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
        return null;
    }

    public static void saveEphemeris(BoundedPropagator generatedEphemeris) {
        Path path = Paths.get("d:/", "config.data");
        if (!Files.exists(path)) {
            try {
                Files.createFile(path);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(Files.newOutputStream(path))) {
            objectOutputStream.writeObject(new BoundedPropagatorBO(generatedEphemeris));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

Hi @Sohnny,

I’m not very familiar with serialization but shouldn’t the desired class to serialize implement the Serializable interface ? It is currently not the case for the BoundedPropagator so it may be why it does not work in your case ?

A simple workaround would be to save your ephemeris during propagation using an OrekitFixedStepHandler with a StringBuilder for example.

Cheers,
Vincent

Yes, thank you for your reply. I still recommend implementing Serializable in the relevant class so that users can save the running state of the program at any time.

Hi Sohnny,

The problem is that a class such as IntegratedEphemerisPropagator is a very complex object, wrapping an interpolator and emulating the propagation features of Orekit. It would be pretty difficult to break it down in a bunch of Serializable objects, even if it is theoretically possible.

Cheers,
Romain.

One of the main problem when serializing a propagator is the reference to an AttitudeProvider

1 Like