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 19 import java.io.BufferedWriter; 20 import java.io.IOException; 21 import java.nio.charset.StandardCharsets; 22 import java.nio.file.Files; 23 import java.nio.file.Paths; 24 25 import org.orekit.utils.TimeStampedPVCoordinates; 26 27 /** 28 * An interface for writing out ephemeris files to disk. 29 * 30 * <p> 31 * An {@link EphemerisFile} consists of one or more satellites each an ID unique 32 * within the file. The ephemeris for each satellite consists of one or more 33 * segments. 34 * 35 * <p> 36 * Ephemeris file formats may have additional settings that need to be 37 * configured to be compliant with their formats. 38 * 39 * @author Hank Grabowski 40 * @since 9.0 41 * 42 */ 43 public interface EphemerisFileWriter { 44 45 /** 46 * Write the passed in {@link EphemerisFile} using the passed in 47 * {@link Appendable}. 48 * 49 * @param writer 50 * a configured Appendable to feed with text 51 * @param ephemerisFile 52 * a populated ephemeris file to serialize into the buffer 53 * @param <C> type of the Cartesian coordinates 54 * @param <S> type of the segment 55 * @throws IOException 56 * if any buffer writing operations fail or if the underlying 57 * format doesn't support a configuration in the EphemerisFile 58 * (for example having multiple satellites in one file, having 59 * the origin at an unspecified celestial body, etc.) 60 */ 61 <C extends TimeStampedPVCoordinates, S extends EphemerisFile.EphemerisSegment<C>> 62 void write(Appendable writer, EphemerisFile<C, S> ephemerisFile) throws IOException; 63 64 /** 65 * Write the passed in {@link EphemerisFile} to a file at the output path 66 * specified. 67 * 68 * @param outputFilePath 69 * a file path that the corresponding file will be written to 70 * @param ephemerisFile 71 * a populated ephemeris file to serialize into the buffer 72 * @param <C> type of the Cartesian coordinates 73 * @param <S> type of the segment 74 * @throws IOException 75 * if any file writing operations fail or if the underlying 76 * format doesn't support a configuration in the EphemerisFile 77 * (for example having multiple satellites in one file, having 78 * the origin at an unspecified celestial body, etc.) 79 */ 80 default <C extends TimeStampedPVCoordinates, S extends EphemerisFile.EphemerisSegment<C>> 81 void write(final String outputFilePath, EphemerisFile<C, S> ephemerisFile) 82 throws IOException { 83 try (BufferedWriter writer = 84 Files.newBufferedWriter(Paths.get(outputFilePath), StandardCharsets.UTF_8)) { 85 write(writer, ephemerisFile); 86 } 87 } 88 89 }