Example usage for java.io LineNumberReader LineNumberReader

List of usage examples for java.io LineNumberReader LineNumberReader

Introduction

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

Prototype

public LineNumberReader(Reader in) 

Source Link

Document

Create a new line-numbering reader, using the default input-buffer size.

Usage

From source file:org.getobjects.ofs.htaccess.HtConfigParser.java

public HtConfigParser(Reader _reader) {
    this(new LineNumberReader(_reader));
}

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

/**
 * Reads a log file into an array of (multi-)statuses.
 * <p>// w w  w . j  a v  a  2  s .  c  o m
 * The log file is parsed as follows:
 * <ul>
 * <li>All lines formatted as a log-message are parsed into a list of status object. (See {@link LoggerUtilities})</li>
 * <li>All statuses between two messages with code {@link LoggerUtilities#CODE_NEW_MSGBOX}go into a separate
 * MultiStatus.</li>
 * <li>Only messages with a code unequal to {@link LoggerUtilities#CODE_NONE}are considered.</li>
 * <li>The message text of each multi-status will be composed of all its statuses with code
 * {@link LoggerUtilities#CODE_SHOW_MSGBOX}</li>
 * </ul>
 *
 * @return The resulting stati. If problems are encountered while reading the file, instead an error status describing
 *         the io-problems is returned.
 */
public static IStatus[] logfileToStatus(final File file, final String charset) {
    InputStream inputStream = null;
    LineNumberReader lnr = null;
    try {
        inputStream = new FileInputStream(file);
        lnr = new LineNumberReader(new InputStreamReader(inputStream, charset));

        final IStatus[] result = readerToStatus(lnr);

        lnr.close();

        return result;
    } catch (final Throwable t) {
        final StringBuffer msg = new StringBuffer(
                Messages.getString("org.kalypso.commons.runtime.LogAnalyzer.0")); //$NON-NLS-1$
        if (lnr != null) {
            msg.append(Messages.getString("org.kalypso.commons.runtime.LogAnalyzer.1")); //$NON-NLS-1$
            msg.append(lnr.getLineNumber());
        }

        msg.append(Messages.getString("org.kalypso.commons.runtime.LogAnalyzer.2")); //$NON-NLS-1$
        msg.append(file.getAbsolutePath());

        final IStatus status = new Status(IStatus.ERROR, KalypsoCommonsPlugin.getID(),
                LoggerUtilities.CODE_SHOW_MSGBOX, msg.toString(), t);

        return new IStatus[] { status };
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:edu.stanford.muse.index.NER.java

public static void readLocationsFreebase() throws IOException {
    InputStream is = new GZIPInputStream(NER.class.getClassLoader().getResourceAsStream("locations.gz"));
    LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is, "UTF-8"));
    while (true) {
        String line = lnr.readLine();
        if (line == null)
            break;
        StringTokenizer st = new StringTokenizer(line, "\t");
        if (st.countTokens() == 3) {
            String locationName = st.nextToken();
            String canonicalName = locationName.toLowerCase();
            String lat = st.nextToken();
            String longi = st.nextToken();
            locations.put(canonicalName, new LocationInfo(locationName, lat, longi));
        }// w w w  .ja  v  a 2s.co m
    }
    lnr.close();
}

From source file:com.shmsoft.dmass.services.Util.java

public static int countLines(String filename) throws IOException {
    LineNumberReader reader = new LineNumberReader(new FileReader(filename));
    int cnt = 0;/*from ww w .  j av a2  s. co  m*/
    String lineRead = "";
    while ((lineRead = reader.readLine()) != null) {
    }
    cnt = reader.getLineNumber();
    reader.close();
    return cnt;
}

From source file:org.kalypso.model.wspm.tuhh.schema.simulation.BuildingPolygonReader.java

public void read(final File buildingFile) throws IOException {
    LineNumberReader reader = null;
    try {//from w w  w  . j a v  a 2s . c o m
        reader = new LineNumberReader(new FileReader(buildingFile));

        /* Ingore first line */
        if (reader.ready())
            reader.readLine();

        while (reader.ready()) {
            final String line = reader.readLine();
            if (line == null)
                break;

            try {
                readBuildingLine(line.trim(), buildingFile);
            } catch (final NumberFormatException nfe) {
                /* A good line but bad content. Give user a hint that something might be wrong. */
                m_log.log(false,
                        Messages.getString(
                                "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.25"), //$NON-NLS-1$
                        buildingFile.getName(), reader.getLineNumber(), nfe.getLocalizedMessage());
            } catch (final Throwable e) {
                // should never happen
                m_log.log(e,
                        Messages.getString(
                                "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.25"), //$NON-NLS-1$
                        buildingFile.getName(), reader.getLineNumber(), e.getLocalizedMessage());
            }

        }
        reader.close();
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

From source file:org.apache.wookie.util.WidgetJavascriptSyntaxAnalyzer.java

/**
 * Find occurrences of incompatible setter syntax for Internet explorer
 * i.e. Widget.preferences.foo=bar;//  www .j av a2s.  com
 * 
 * @throws IOException
 */
private void parseIEIncompatibilities() throws IOException {
    // Pattern match on the syntax 'widget.preferemces.name=value' - including optional quotes & spaces around the value
    Pattern pattern = Pattern.compile("widget.preferences.\\w+\\s*=\\s*\\\"??\\'??.+\\\"??\\'??",
            Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher("");
    // Search .js files, but also any html files
    Iterator<?> iter = FileUtils.iterateFiles(_searchFolder, new String[] { "js", "htm", "html" }, true);
    while (iter.hasNext()) {
        File file = (File) iter.next();
        LineNumberReader lineReader = new LineNumberReader(new FileReader(file));
        String line = null;
        while ((line = lineReader.readLine()) != null) {
            matcher.reset(line);
            if (matcher.find()) {
                String message = "\n(Line " + lineReader.getLineNumber() + ") in file " + file;
                message += "\n\t " + line + "\n";
                message += "This file contains preference setter syntax which may not behave correctly in Internet Explorer version 8 and below.\n";
                message += "See https://cwiki.apache.org/confluence/display/WOOKIE/FAQ#FAQ-ie8prefs for more information.\n";
                FlashMessage.getInstance().message(formatWebMessage(message));
                _logger.warn(message);
            }
        }
    }
}

From source file:ch.cyberduck.core.socket.HttpProxyAwareSocket.java

@Override
public void connect(final SocketAddress endpoint, final int timeout) throws IOException {
    if (proxy.type() == Proxy.Type.HTTP) {
        super.connect(proxy.address(), timeout);
        final InetSocketAddress address = (InetSocketAddress) endpoint;
        final OutputStream out = this.getOutputStream();
        IOUtils.write(String.format("CONNECT %s:%d HTTP/1.0\n\n", address.getHostName(), address.getPort()),
                out, Charset.defaultCharset());
        final InputStream in = this.getInputStream();
        final String response = new LineNumberReader(new InputStreamReader(in)).readLine();
        if (null == response) {
            throw new SocketException(String.format("Empty response from HTTP proxy %s",
                    ((InetSocketAddress) proxy.address()).getHostName()));
        }/*ww  w  . j  a  v a  2  s.  co m*/
        if (response.contains("200")) {
            in.skip(in.available());
        } else {
            throw new SocketException(String.format("Invalid response %s from HTTP proxy %s", response,
                    ((InetSocketAddress) proxy.address()).getHostName()));
        }
    } else {
        super.connect(endpoint, timeout);
    }
}

From source file:com.googlecode.jweb1t.JWeb1TSearcherInMemory.java

private void fillMap(final File aFile, final int aLevel) throws IOException {
    final LineNumberReader reader = new LineNumberReader(new FileReader(aFile));
    String line;//from   w ww  .  j  a  va  2s  .  c  o  m
    while ((line = reader.readLine()) != null) {
        final String[] parts = line.split("\t");

        if (parts.length != 2) {
            continue;
        }

        ngramLevelMap.get(aLevel).addSample(parts[0], Long.parseLong(parts[1]));
    }
    reader.close();
}

From source file:codingchallenge.SortableChallenge.java

private void processListings() throws IOException, JSONException {
    try {/*from  w w w. j a v a  2 s  . c  o m*/
        LineNumberReader llistingsReader = new LineNumberReader(listingsReader);
        for (String line = llistingsReader.readLine(); line != null; line = llistingsReader.readLine()) {
            line = line.trim();
            if (line.length() == 0) {
                continue;
            }
            JSONTokener tokener = new JSONTokener(line);
            Object token = tokener.nextValue();
            if (!(token instanceof JSONObject)) {
                throw new BadInputException("Bad listing data: " + token);
            }
            JSONObject listingJSON = (JSONObject) token;
            String title = getStringProp("title", listingJSON);
            String manufacturer = getStringProp("manufacturer", listingJSON);
            String currency = getStringProp("currency", listingJSON);
            String price = getStringProp("price", listingJSON);
            Listing listing = new Listing(title, manufacturer, currency, price);
            listingToJSON.put(listing, listingJSON);
            Set<Product> matchingProducts = matcher.getMatches(listing);
            addMatch(listing, matchingProducts);
        }
    } finally {
        listingsReader.close();
    }
}

From source file:pl.nask.hsn2.service.scdbg.ScdbgTool.java

private void processInput(ScdbgResultBuilder builder, InputStream input) throws ResourceException {
    LineNumberReader reader = null;
    try {//from   w ww.j a va2  s  .c o  m
        reader = new LineNumberReader(new InputStreamReader(input));
        String line = null;
        while ((line = reader.readLine()) != null) {
            LOGGER.debug("Got line: {}", line);
            builder.scanOutputLine(line);
        }
    } catch (IOException e) {
        throw new ResourceException("Error reading output from scdbg", e);
    } finally {
        IOUtils.closeQuietly(reader);
    }
}