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