Example usage for java.io BufferedReader mark

List of usage examples for java.io BufferedReader mark

Introduction

In this page you can find the example usage for java.io BufferedReader mark.

Prototype

public void mark(int readAheadLimit) throws IOException 

Source Link

Document

Marks the present position in the stream.

Usage

From source file:org.orekit.files.ccsds.OEMParser.java

/**
 * Parse an ephemeris data line and add its content to the ephemerides
 * block./*from  ww  w  . jav a2 s  .  c  om*/
 *
 * @param reader the reader
 * @param pi the parser info
 * @exception IOException if an error occurs while reading from the stream
 * @exception OrekitException if a date cannot be parsed
 */
private void parseEphemeridesDataLines(final BufferedReader reader, final ParseInfo pi)
        throws OrekitException, IOException {

    for (String line = reader.readLine(); line != null; line = reader.readLine()) {

        ++pi.lineNumber;
        if (line.trim().length() > 0) {
            pi.keyValue = new KeyValue(line, pi.lineNumber, pi.fileName);
            if (pi.keyValue.getKeyword() == null) {
                Scanner sc = null;
                try {
                    sc = new Scanner(line);
                    final AbsoluteDate date = parseDate(sc.next(),
                            pi.lastEphemeridesBlock.getMetaData().getTimeSystem());
                    final Vector3D position = new Vector3D(Double.parseDouble(sc.next()) * 1000,
                            Double.parseDouble(sc.next()) * 1000, Double.parseDouble(sc.next()) * 1000);
                    final Vector3D velocity = new Vector3D(Double.parseDouble(sc.next()) * 1000,
                            Double.parseDouble(sc.next()) * 1000, Double.parseDouble(sc.next()) * 1000);
                    final CartesianOrbit orbit = new CartesianOrbit(new PVCoordinates(position, velocity),
                            pi.lastEphemeridesBlock.getMetaData().getFrame(), date, pi.file.getMuUsed());
                    Vector3D acceleration = null;
                    if (sc.hasNext()) {
                        acceleration = new Vector3D(Double.parseDouble(sc.next()) * 1000,
                                Double.parseDouble(sc.next()) * 1000, Double.parseDouble(sc.next()) * 1000);
                    }
                    final OEMFile.EphemeridesDataLine epDataLine = new OEMFile.EphemeridesDataLine(orbit,
                            acceleration);
                    pi.lastEphemeridesBlock.getEphemeridesDataLines().add(epDataLine);
                } catch (NumberFormatException nfe) {
                    throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, pi.lineNumber,
                            pi.fileName, line);
                } finally {
                    if (sc != null) {
                        sc.close();
                    }
                }
            } else {
                switch (pi.keyValue.getKeyword()) {
                case META_START:
                    pi.lastEphemeridesBlock.setEphemeridesDataLinesComment(pi.commentTmp);
                    pi.commentTmp.clear();
                    pi.lineNumber--;
                    reader.reset();
                    return;
                case COVARIANCE_START:
                    pi.lastEphemeridesBlock.setEphemeridesDataLinesComment(pi.commentTmp);
                    pi.commentTmp.clear();
                    pi.lineNumber--;
                    reader.reset();
                    return;
                case COMMENT:
                    pi.commentTmp.add(pi.keyValue.getValue());
                    break;
                default:
                    throw new OrekitException(OrekitMessages.CCSDS_UNEXPECTED_KEYWORD, pi.lineNumber,
                            pi.fileName, line);
                }
            }
        }
        reader.mark(300);

    }
}