1   /* Copyright 2002-2025 CS GROUP
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  
18  
19  package org.orekit.models.earth.atmosphere.data;
20  
21  import java.io.BufferedReader;
22  import java.io.IOException;
23  
24  
25  /**
26   * Helper class to parse line data.
27   * @since 11.2
28    */
29  class CommonLineReader {
30  
31      /** The input stream. */
32      private final BufferedReader in;
33  
34      /** The last line read from the file. */
35      private String line;
36  
37      /** The number of the last line read from the file. */
38      private long lineNo;
39  
40      /**
41       * Create a line reader.
42       *
43       * @param in   the input data stream.
44       */
45      CommonLineReader(final BufferedReader in) {
46          this.in = in;
47          this.line = null;
48          this.lineNo = 0;
49      }
50  
51      /**
52       * Read a line from the input data stream.
53       *
54       * @return the next line without the line termination character, or {@code null}
55       *         if the end of the stream has been reached.
56       * @throws IOException if an I/O error occurs.
57       * @see BufferedReader#readLine()
58       */
59      public String readLine() throws IOException {
60          line = in.readLine();
61          lineNo++;
62          return line;
63      }
64  
65      /**
66       * Check if the last line read is empty.
67       *
68       * @return whether a line is empty or not
69       */
70      public boolean isEmptyLine() {
71          return line.length() == 0;
72      }
73  
74  
75      /**
76       * Get the last line read from the stream.
77       *
78       * @return May be {@code null} if no lines have been read or the end of stream
79       *         has been reached.
80       */
81      public String getLine() {
82          return line;
83      }
84  
85      /**
86       * Get the line number of the last line read from the file.
87       *
88       * @return the line number.
89       */
90      public long getLineNumber() {
91          return lineNo;
92      }
93  }