MessageWriter.java

  1. /* Copyright 2002-2025 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.files.ccsds.utils.generation;

  18. import java.io.IOException;

  19. import org.orekit.files.ccsds.ndm.NdmConstituent;
  20. import org.orekit.files.ccsds.section.Header;
  21. import org.orekit.files.ccsds.section.Segment;

  22. /**
  23.  * Interface for writing Navigation Data Message (NDM) files.
  24.  * @param <H> type of the header
  25.  * @param <S> type of the segments
  26.  * @param <F> type of the file
  27.  * @author Luc Maisonobe
  28.  * @since 11.0
  29.  */
  30. public interface MessageWriter<H extends Header, S extends Segment<?, ?>, F extends NdmConstituent<H, S>> {

  31.     /** Write one complete message.
  32.      * @param generator generator to use for producing output
  33.      * @param message message to write
  34.      * @throws IOException if the stream cannot write to stream
  35.      */
  36.     default void writeMessage(final Generator generator, final F message)
  37.         throws IOException {
  38.         writeHeader(generator, message.getHeader());
  39.         for (final S segment : message.getSegments()) {
  40.             writeSegment(generator, segment);
  41.         }
  42.         writeFooter(generator);
  43.     }

  44.     /** Write header for the file.
  45.      * @param generator generator to use for producing output
  46.      * @param header header to write (creation date and originator will be added if missing)
  47.      * @throws IOException if the stream cannot write to stream
  48.      */
  49.     void writeHeader(Generator generator, H header) throws IOException;

  50.     /** Write one segment.
  51.      * @param generator generator to use for producing output
  52.      * @param segment segment to write
  53.      * @throws IOException if any buffer writing operations fails
  54.      */
  55.     void writeSegment(Generator generator, S segment) throws IOException;

  56.     /** Write footer for the file.
  57.      * @param generator generator to use for producing output
  58.      * @throws IOException if the stream cannot write to stream
  59.      */
  60.     void writeFooter(Generator generator) throws IOException;

  61.     /** Get root element for XML files.
  62.      * @return root element for XML files
  63.      * @since 12.0
  64.      */
  65.     String getRoot();

  66.     /** Get key for format version.
  67.      * @return key for format version
  68.      * @since 12.0
  69.      */
  70.     String getFormatVersionKey();

  71.     /** Get current format version.
  72.      * @return current format version
  73.      * @since 12.0
  74.      */
  75.     double getVersion();

  76. }