EphemerisFileWriter.java

  1. /* Copyright 2016 Applied Defense Solutions (ADS)
  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.  * ADS 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.general;

  18. import java.io.BufferedWriter;
  19. import java.io.IOException;
  20. import java.nio.charset.StandardCharsets;
  21. import java.nio.file.Files;
  22. import java.nio.file.Paths;

  23. import org.orekit.utils.TimeStampedPVCoordinates;

  24. /**
  25.  * An interface for writing out ephemeris files to disk.
  26.  *
  27.  * <p>
  28.  * An {@link EphemerisFile} consists of one or more satellites each an ID unique
  29.  * within the file. The ephemeris for each satellite consists of one or more
  30.  * segments.
  31.  *
  32.  * <p>
  33.  * Ephemeris file formats may have additional settings that need to be
  34.  * configured to be compliant with their formats.
  35.  *
  36.  * @author Hank Grabowski
  37.  * @since 9.0
  38.  *
  39.  */
  40. public interface EphemerisFileWriter {

  41.     /**
  42.      * Write the passed in {@link EphemerisFile} using the passed in
  43.      * {@link Appendable}.
  44.      *
  45.      * @param writer
  46.      *            a configured Appendable to feed with text
  47.      * @param ephemerisFile
  48.      *            a populated ephemeris file to serialize into the buffer
  49.      * @param <C> type of the Cartesian coordinates
  50.      * @param <S> type of the segment
  51.      * @throws IOException
  52.      *             if any buffer writing operations fail or if the underlying
  53.      *             format doesn't support a configuration in the EphemerisFile
  54.      *             (for example having multiple satellites in one file, having
  55.      *             the origin at an unspecified celestial body, etc.)
  56.      */
  57.     <C extends TimeStampedPVCoordinates, S extends EphemerisFile.EphemerisSegment<C>>
  58.         void write(Appendable writer, EphemerisFile<C, S> ephemerisFile) throws IOException;

  59.     /**
  60.      * Write the passed in {@link EphemerisFile} to a file at the output path
  61.      * specified.
  62.      *
  63.      * @param outputFilePath
  64.      *            a file path that the corresponding file will be written to
  65.      * @param ephemerisFile
  66.      *            a populated ephemeris file to serialize into the buffer
  67.      * @param <C> type of the Cartesian coordinates
  68.      * @param <S> type of the segment
  69.      * @throws IOException
  70.      *             if any file writing operations fail or if the underlying
  71.      *             format doesn't support a configuration in the EphemerisFile
  72.      *             (for example having multiple satellites in one file, having
  73.      *             the origin at an unspecified celestial body, etc.)
  74.      */
  75.     default <C extends TimeStampedPVCoordinates, S extends EphemerisFile.EphemerisSegment<C>>
  76.         void write(final String outputFilePath, EphemerisFile<C, S> ephemerisFile)
  77.             throws IOException {
  78.         try (BufferedWriter writer =
  79.                         Files.newBufferedWriter(Paths.get(outputFilePath), StandardCharsets.UTF_8)) {
  80.             write(writer, ephemerisFile);
  81.         }
  82.     }

  83. }