Example usage for java.io LineNumberReader ready

List of usage examples for java.io LineNumberReader ready

Introduction

In this page you can find the example usage for java.io LineNumberReader ready.

Prototype

public boolean ready() throws IOException 

Source Link

Document

Tells whether this stream is ready to be read.

Usage

From source file:org.kalypso.wspwin.core.ProfileBean.java

public static ProfileBean[] readProfiles(final LineNumberReader reader, final int profilCount)
        throws IOException, ParseException {
    final List<ProfileBean> beans = new ArrayList<>(20);
    for (int i = 0; i < profilCount; i++) {
        if (!reader.ready())
            throw new ParseException(
                    Messages.getString("org.kalypso.wspwin.core.ProfileBean.0") + reader.getLineNumber(), //$NON-NLS-1$
                    reader.getLineNumber());

        final String line = reader.readLine();
        if (line == null || line.trim().length() == 0)
            throw new ParseException(
                    Messages.getString("org.kalypso.wspwin.core.ProfileBean.1") + reader.getLineNumber(), //$NON-NLS-1$
                    reader.getLineNumber());

        final StringTokenizer tokenizer = new StringTokenizer(line);
        if (tokenizer.countTokens() != 6)
            throw new ParseException(
                    Messages.getString("org.kalypso.wspwin.core.ProfileBean.2") + reader.getLineNumber(), //$NON-NLS-1$
                    reader.getLineNumber());

        try {// ww  w. j  a  v  a2s  .  c om
            final String waterName = tokenizer.nextToken();
            final BigDecimal station = new BigDecimal(tokenizer.nextToken());
            final String mfb = tokenizer.nextToken(); // Mehrfeldbrckenkennung
            final int vzk = parseVZK(tokenizer.nextToken()); // Verzweigungskennung
            final String zustandName = tokenizer.nextToken();
            final String fileName = tokenizer.nextToken();

            final ProfileBean bean = new ProfileBean(waterName, zustandName, station, fileName, mfb, vzk);
            beans.add(bean);
        } catch (final NumberFormatException e) {
            throw new ParseException(
                    Messages.getString("org.kalypso.wspwin.core.ProfileBean.6") + reader.getLineNumber(), //$NON-NLS-1$
                    reader.getLineNumber());
        }
    }

    return beans.toArray(new ProfileBean[beans.size()]);
}

From source file:org.kalypso.wspwin.core.WspWinZustand.java

private static ZustandSegmentBean[] readZustandSegments(final LineNumberReader reader, final int segmentCount,
        final String filename) throws ParseException, IOException {
    final List<ZustandSegmentBean> beans = new ArrayList<>(20);

    int readSegments = 0;
    while (reader.ready()) {
        final String line = reader.readLine();
        /* Skip empty lines; we have WspWin projects with and without a separating empty line */
        if (StringUtils.isBlank(line))
            continue;

        final StringTokenizer tokenizer = new StringTokenizer(line);
        if (tokenizer.countTokens() != 7)
            throw new ParseException(Messages.getString("org.kalypso.wspwin.core.WspWinZustand.2", filename, //$NON-NLS-1$
                    reader.getLineNumber()), reader.getLineNumber());

        try {//www.  j  a va2  s  .c  o  m
            final BigDecimal stationFrom = new BigDecimal(tokenizer.nextToken());
            final BigDecimal stationTo = new BigDecimal(tokenizer.nextToken());
            final double distanceVL = Double.parseDouble(tokenizer.nextToken());
            final double distanceHF = Double.parseDouble(tokenizer.nextToken());
            final double distanceVR = Double.parseDouble(tokenizer.nextToken());

            final String fileNameFrom = tokenizer.nextToken();
            final String fileNameTo = tokenizer.nextToken();

            final ZustandSegmentBean bean = new ZustandSegmentBean(stationFrom, stationTo, fileNameFrom,
                    fileNameTo, distanceVL, distanceHF, distanceVR);
            beans.add(bean);

            readSegments++;
        } catch (final NumberFormatException e) {
            e.printStackTrace();
            throw new ParseException(Messages.getString("org.kalypso.wspwin.core.WspWinZustand.3", filename, //$NON-NLS-1$
                    reader.getLineNumber()), reader.getLineNumber());
        }
    }

    if (readSegments != segmentCount)
        throw new ParseException(
                Messages.getString("org.kalypso.wspwin.core.WspWinZustand.1", filename, reader.getLineNumber()), //$NON-NLS-1$
                reader.getLineNumber());

    return beans.toArray(new ZustandSegmentBean[beans.size()]);
}