CommonLineReader.java

  1. /* Copyright 2002-2024 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. package org.orekit.models.earth.atmosphere.data;

  18. import java.io.BufferedReader;
  19. import java.io.IOException;


  20. /**
  21.  * Helper class to parse line data.
  22.  * @since 11.2
  23.   */
  24. class CommonLineReader {

  25.     /** The input stream. */
  26.     private final BufferedReader in;

  27.     /** The last line read from the file. */
  28.     private String line;

  29.     /** The number of the last line read from the file. */
  30.     private long lineNo;

  31.     /**
  32.      * Create a line reader.
  33.      *
  34.      * @param in   the input data stream.
  35.      */
  36.     CommonLineReader(final BufferedReader in) {
  37.         this.in = in;
  38.         this.line = null;
  39.         this.lineNo = 0;
  40.     }

  41.     /**
  42.      * Read a line from the input data stream.
  43.      *
  44.      * @return the next line without the line termination character, or {@code null}
  45.      *         if the end of the stream has been reached.
  46.      * @throws IOException if an I/O error occurs.
  47.      * @see BufferedReader#readLine()
  48.      */
  49.     public String readLine() throws IOException {
  50.         line = in.readLine();
  51.         lineNo++;
  52.         return line;
  53.     }

  54.     /**
  55.      * Check if the last line read is empty.
  56.      *
  57.      * @return whether a line is empty or not
  58.      */
  59.     public boolean isEmptyLine() {
  60.         return line.length() == 0;
  61.     }


  62.     /**
  63.      * Get the last line read from the stream.
  64.      *
  65.      * @return May be {@code null} if no lines have been read or the end of stream
  66.      *         has been reached.
  67.      */
  68.     public String getLine() {
  69.         return line;
  70.     }

  71.     /**
  72.      * Get the line number of the last line read from the file.
  73.      *
  74.      * @return the line number.
  75.      */
  76.     public long getLineNumber() {
  77.         return lineNo;
  78.     }
  79. }