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 19 import java.io.IOException; 20 21 import org.orekit.files.ccsds.ndm.NdmConstituent; 22 import org.orekit.files.ccsds.section.Header; 23 import org.orekit.files.ccsds.section.Segment; 24 25 /** 26 * Interface for writing Navigation Data Message (NDM) files. 27 * @param <H> type of the header 28 * @param <S> type of the segments 29 * @param <F> type of the file 30 * @author Luc Maisonobe 31 * @since 11.0 32 */ 33 public interface MessageWriter<H extends Header, S extends Segment<?, ?>, F extends NdmConstituent<H, S>> { 34 35 /** Write one complete message. 36 * @param generator generator to use for producing output 37 * @param message message to write 38 * @throws IOException if the stream cannot write to stream 39 */ 40 default void writeMessage(final Generator generator, final F message) 41 throws IOException { 42 writeHeader(generator, message.getHeader()); 43 for (final S segment : message.getSegments()) { 44 writeSegment(generator, segment); 45 } 46 writeFooter(generator); 47 } 48 49 /** Write header for the file. 50 * @param generator generator to use for producing output 51 * @param header header to write (creation date and originator will be added if missing) 52 * @throws IOException if the stream cannot write to stream 53 */ 54 void writeHeader(Generator generator, H header) throws IOException; 55 56 /** Write one segment. 57 * @param generator generator to use for producing output 58 * @param segment segment to write 59 * @throws IOException if any buffer writing operations fails 60 */ 61 void writeSegment(Generator generator, S segment) throws IOException; 62 63 /** Write footer for the file. 64 * @param generator generator to use for producing output 65 * @throws IOException if the stream cannot write to stream 66 */ 67 void writeFooter(Generator generator) throws IOException; 68 69 /** Get root element for XML files. 70 * @return root element for XML files 71 * @since 12.0 72 */ 73 String getRoot(); 74 75 /** Get key for format version. 76 * @return key for format version 77 * @since 12.0 78 */ 79 String getFormatVersionKey(); 80 81 /** Get current format version. 82 * @return current format version 83 * @since 12.0 84 */ 85 double getVersion(); 86 87 }