/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override public Accounting load() throws IOException { final Path dataFile = getDataFile(); log.info(">>>> loading data from {}...", dataFile); try (final InputStream is = new FileInputStream(dataFile.toFile())) { return accounting.as(Unmarshallable).unmarshal(is); } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override public void save() throws IOException { final Path dataFile = getDataFile(); log.info(">>>> saving data to {}...", dataFile); try (final OutputStream os = new FileOutputStream(dataFile.toFile())) { accounting.as(Marshallable).marshal(os); } }
/******************************************************************************************************************* * * Loads the {@link Accounting} at initialization. * ******************************************************************************************************************/ @PostConstruct @VisibleForTesting void initialize() { try { log.info("initialize()"); accounting = Accounting.createNew().as(Loadable).load(); messageBus.publish(new AccountingOpenedEvent(accounting)); } catch (IOException e) { throw new RuntimeException(e); } }