StreamingIIRVFileWriter.java

  1. /* Copyright 2024-2025 The Johns Hopkins University Applied Physics Laboratory
  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.iirv;

  18. import java.io.IOException;

  19. /**
  20.  * Writer class that outputs {@link IIRVMessage} data to an output stream.
  21.  *
  22.  * @author Nick LaFarge
  23.  * @see IIRVFileWriter
  24.  * @since 13.0
  25.  */
  26. public class StreamingIIRVFileWriter {

  27.     /** Output stream. */
  28.     private final Appendable writer;

  29.     /** Setting for when message metadata terms appear in the created IIRV message. */
  30.     private final IIRVMessage.IncludeMessageMetadata includeMessageMetadataSetting;

  31.     /**
  32.      * Create an IIRV writer that streams data to the given output stream.
  33.      *
  34.      * @param writer                        the output stream for the IIRV file.
  35.      * @param includeMessageMetadataSetting Setting for when message metadata terms appear in the created IIRV message
  36.      */
  37.     public StreamingIIRVFileWriter(final Appendable writer, final IIRVMessage.IncludeMessageMetadata includeMessageMetadataSetting) {
  38.         this.writer = writer;
  39.         this.includeMessageMetadataSetting = includeMessageMetadataSetting;
  40.     }

  41.     /**
  42.      * Write the passed in {@link IIRVMessage} using the passed in {@link Appendable}.
  43.      *
  44.      * @param iirvMessage a an {@link IIRVMessage} instance populated with {@link IIRVVector} terms.
  45.      * @throws IOException if any buffer writing operations fail
  46.      */
  47.     public void writeIIRVMessage(final IIRVMessage iirvMessage) throws IOException {
  48.         writer.append(iirvMessage.toMessageString(includeMessageMetadataSetting));
  49.     }

  50.     /**
  51.      * Gets the setting for when message metadata terms appear in the created IIRV message.
  52.      *
  53.      * @return setting for when message metadata terms appear in the created IIRV message
  54.      */
  55.     public IIRVMessage.IncludeMessageMetadata getIncludeMessageMetadataSetting() {
  56.         return includeMessageMetadataSetting;
  57.     }
  58. }