Example usage for java.io LineNumberReader readLine

List of usage examples for java.io LineNumberReader readLine

Introduction

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

Prototype

public String readLine() throws IOException 

Source Link

Document

Read a line of text.

Usage

From source file:com.l2jfree.gameserver.datatables.StaticObjects.java

private void parseData() {
    LineNumberReader lnr = null;
    try {/*from   w w w  . j  a v a2 s  .  c o  m*/
        File doorData = new File(Config.DATAPACK_ROOT, "data/staticobjects.csv");
        lnr = new LineNumberReader(new BufferedReader(new FileReader(doorData)));

        String line = null;
        while ((line = lnr.readLine()) != null) {
            if (line.trim().length() == 0 || line.startsWith("#"))
                continue;

            L2StaticObjectInstance obj = parse(line);
            _staticObjects.put(obj.getStaticObjectId(), obj);
        }
    } catch (FileNotFoundException e) {
        _log.warn("staticobjects.csv is missing in data folder");
    } catch (Exception e) {
        _log.warn("error while creating StaticObjects table", e);
    } finally {
        try {
            if (lnr != null)
                lnr.close();
        } catch (Exception e) {
        }
    }
}

From source file:pl.otros.logview.api.io.UtilsTest.java

@Test
public void testLoadHttpNotGzippedBufferedReader() throws Exception {
    String url = HTTP_NOT_GZIPPED;
    LoadingInfo loadingInfo = Utils.openFileObject(fsManager.resolveFile(url));
    InputStream contentInputStream = loadingInfo.getContentInputStream();
    // byte[] expectedBytes =
    // IOUtils.toByteArray(fsManager.resolveFile(url).getContent().getInputStream());

    LineNumberReader bin = new LineNumberReader(new InputStreamReader(contentInputStream));

    int lines = 0;
    while (bin.readLine() != null) {
        lines++;//from  ww  w . ja  va 2s.c  o  m
    }

    AssertJUnit.assertEquals(2600, lines);
    // assertEquals(expected.length, actual.length);
    // assertArrayEquals(expected, actual);

}

From source file:org.kalypso.model.hydrology.internal.postprocessing.BlockTimeSeries.java

private BlockTimeStep searchTimeoffset(final LineNumberReader reader) throws ParseException, IOException {
    while (reader.ready()) {
        final String line = reader.readLine();
        if (line == null)
            break;

        if (line.startsWith("#")) //$NON-NLS-1$
            continue;

        // final Matcher m = pTime.matcher( line );
        final Matcher m = m_resultsFormat.getSimulationPeriodPattern().matcher(line);
        final Matcher synthM = pSynthTime.matcher(line);
        if (m.matches()) {
            final String sDate = m.group(1);
            final String sTime = m.group(2);
            final String sStep = m.group(3);

            final Calendar startCal = parseDate24(sDate, sTime);
            final Duration timestep = parseDuration(sStep);
            return new BlockTimeStep(startCal, timestep);
        } else if (synthM.matches()) {
            // synthetisches Ereignis hat kein Anfangsdatum, daher wird 01.01.2000 angenommen!
            final Calendar startCal = m_dateFormat.getCalendar();
            startCal.set(2000, 1, 1, 0, 0);

            final String sStep = synthM.group(3);
            final Duration timestep = parseDuration(sStep);
            return new BlockTimeStep(startCal, timestep);
        }/*from ww w  . j av a  2  s .com*/
    }

    return null;
}

From source file:org.kalypso.commons.runtime.LogStatusWrapper.java

/**
 * Constructor: summary is taken from the logfile. The file is parsed and each line which begins with '***' is
 * appended to the summary./*w  w  w  . j ava  2s  . c o  m*/
 */
public LogStatusWrapper(final File logFile, final String charsetName) {
    if (logFile == null)
        throw new IllegalStateException(Messages.getString("org.kalypso.commons.runtime.LogStatusWrapper.1")); //$NON-NLS-1$
    if (!logFile.exists())
        throw new IllegalStateException(
                Messages.getString("org.kalypso.commons.runtime.LogStatusWrapper.2", logFile.toString())); //$NON-NLS-1$

    m_logFile = logFile;
    m_charsetName = charsetName;

    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);

    LineNumberReader reader = null;
    try {
        reader = new LineNumberReader(
                new InputStreamReader(new BufferedInputStream(new FileInputStream(logFile)), charsetName));
        while (reader.ready()) {
            final String line = reader.readLine();
            if (line == null)
                break;

            if (line.startsWith(SUMMARY_BEGIN_TOKEN) && line.length() > 3)
                pw.println(line.substring(3));
        }

        pw.close();
    } catch (final IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(reader);
        pw.close();
        m_summary = sw.toString();
    }
}

From source file:org.onecmdb.core.utils.transform.csv.CSVDataSource.java

public synchronized List<String> load() throws IOException {
    if (loaded) {
        return (lines);
    }/*from w  ww  .j a v  a 2  s .c  om*/

    lines = new ArrayList<String>();
    int lineIndex = 0;
    for (URL url : urls) {
        URL nUrl = url;
        if (rootPath != null) {
            nUrl = new URL(nUrl.getProtocol(), nUrl.getHost(), nUrl.getPort(), rootPath + "/" + nUrl.getFile());
        }
        InputStream in = nUrl.openStream();
        try {
            LineNumberReader lin = new LineNumberReader(new InputStreamReader(in));
            boolean eof = false;
            while (!eof) {

                String line = lin.readLine();
                if (line == null) {
                    eof = true;
                    continue;
                }
                // Check if line is not terminated due to nl in fields.
                line = handleEndOfLine(lin, line);
                lineIndex++;
                if (lineIndex < headerLines) {
                    log.debug("Add Header:" + line);
                    headers.add(line);
                    continue;
                }
                log.debug("Add Line:[" + lineIndex + "]" + line);
                lines.add(line);
            }
        } catch (IOException de) {
            IOException e = new IOException("Parse error in <" + url.toExternalForm() + ">, ");
            e.initCause(de);
            throw e;
        } finally {
            if (in != null) {
                in.close();
            }
        }
    }
    loaded = true;

    String header = getHeaderData();
    if (headers != null) {
        String headers[] = header.split(getColDelimiter());
        for (int i = 0; i < headers.length; i++) {
            headerMap.put(headers[i], i);
        }
    }
    return (lines);
}

From source file:org.guzz.config.LocalFileConfigServer.java

/**
 * A file contains the paths of all resource files separated by new lines.
 * A resource file name starts with a star(*) makes it a optional one.
 * Lines start with # is treated as comments.
 *//*  w  w w  .  j  a  v a 2  s . c om*/
public void setResourceList(Resource r) {
    LineNumberReader lr = null;
    try {
        lr = new LineNumberReader(new InputStreamReader(r.getInputStream(), "UTF-8"));
        String line = null;

        while ((line = lr.readLine()) != null) {
            line = line.trim();

            if (line.length() == 0)
                continue;
            if (line.startsWith("#"))
                continue;

            boolean resourceMustBeValid = true;

            if (line.charAt(0) == '*') {
                line = line.substring(1);
                resourceMustBeValid = false;
            }

            this.addResource(new FileResource(r, line), resourceMustBeValid);
        }
    } catch (UnsupportedEncodingException e) {
        throw new InvalidConfigurationException(r.toString(), e);
    } catch (IOException e) {
        throw new InvalidConfigurationException(r.toString(), e);
    } finally {
        CloseUtil.close(lr);
    }
}

From source file:org.kalypso.model.hydrology.internal.postprocessing.BlockTimeSeries.java

private Entry<String, Integer> searchBlockHeader(final LineNumberReader reader)
        throws NumberFormatException, IOException {
    while (reader.ready()) {
        final String line = reader.readLine();
        if (line == null)
            break;

        if (line.startsWith("#")) //$NON-NLS-1$
            continue;

        final Matcher m = PATTERN_BLOCK_HEADER.matcher(line);
        if (m.matches()) {
            final String key = m.group(1);
            final int valuesCount = Integer.parseInt(m.group(3));

            // HACK: create singleton map in order to create entry
            return Collections.singletonMap(key, valuesCount).entrySet().iterator().next();
        }/*  w  w  w.j a  v a2  s . c  o  m*/
    }

    return null;
}

From source file:org.chenillekit.demo.components.LeftSideMenu.java

/**
 * build the menu item list.//w  w w  . java2  s .  c om
 *
 * @return list of menu items
 */
private List<MenuConfiguration> buildMenuItemList() {
    List<MenuConfiguration> menuEntryList = CollectionFactory.newList();
    LineNumberReader lineNumberReader = null;

    try {
        lineNumberReader = new LineNumberReader(new FileReader(new File(configFile.toURL().toURI())));

        String readedLine;
        while ((readedLine = lineNumberReader.readLine()) != null) {
            String[] values = StringUtils.split(readedLine, '|');
            if (!values[0].equalsIgnoreCase("separator")) {
                Object[] contextParameters = null;
                if (values.length == 4 && parameters != null) {
                    String[] placeHolders = values[3].split(",");
                    contextParameters = new Object[placeHolders.length];
                    for (int i = 0; i < placeHolders.length; i++) {
                        String placeHolder = placeHolders[i];
                        contextParameters[i] = parameters.get(placeHolder);
                    }
                }

                menuEntryList.add(new MenuConfiguration(values[0].trim(), values[1].trim(), values[2].trim(),
                        contextParameters));
            } else
                menuEntryList.add(new MenuConfiguration());
        }

        return menuEntryList;
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            if (lineNumberReader != null)
                lineNumberReader.close();
        } catch (IOException e) {
        }
    }
}

From source file:org.kuali.test.runner.execution.FileOperationExecution.java

private List<File> findFilesContainingText(List<File> inputFiles, String txt) {
    List<File> retval = new ArrayList<File>();
    LineNumberReader lnr = null;

    for (File f : inputFiles) {
        try {//from  ww  w .  j av  a  2 s .  c o m
            lnr = new LineNumberReader(new FileReader(f));
            String line = null;
            while ((line = lnr.readLine()) != null) {
                if (line.contains(txt)) {
                    retval.add(f);
                    break;
                }
            }
        }

        catch (Exception ex) {

        }

        finally {
            try {
                if (lnr != null) {
                    lnr.close();
                }
            }

            catch (Exception ex) {
            }
            ;
        }
    }

    return retval;
}

From source file:com.espertech.esper.example.trivia.TriviaMain.java

private List<String> parseLines(String testdata) {
    List<String> result = new ArrayList<String>();
    StringReader buf = new StringReader(testdata);
    LineNumberReader reader = new LineNumberReader(buf);
    try {/*from ww  w .  j  a  v a2  s.  c o  m*/
        while (true) {
            String line = reader.readLine();
            if (line == null) {
                break;
            }
            result.add(line);
        }
    } catch (IOException ex) {
        throw new RuntimeException("Failed to parse lines: " + ex.getMessage(), ex);
    }
    return result;
}