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

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

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