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:gemlite.shell.commands.admin.ExecuteSql.java

@CliCommand(value = "execute sql", help = "execute sql")
public boolean execute(@CliOption(key = "sql", mandatory = false) String sql,
        @CliOption(key = "file", mandatory = false) String file) {
    if (StringUtils.isEmpty(sql) && StringUtils.isEmpty(file))
        return false;
    AsyncSqlProcessor processor = new AsyncSqlProcessor(new AntlrTableParser(), new SimpleMapperDao(),
            new GFDomainSender());
    Date nowtime = new Date();
    StringBuffer msgBuf = new StringBuffer();
    msgBuf.append("timestamp:::" + nowtime.getTime() + "\n");
    if (StringUtils.isNotEmpty(sql)) {
        msgBuf.append(sql);//ww  w .  j a  v a  2  s.  co m
        processor.parserOneMessage(msgBuf.toString());
        processor.remoteProcess();

        StringBuilder info = new StringBuilder(
                "ExecuteSql :" + msgBuf.toString() + "Time is:" + nowtime.toString());
        LogUtil.getCoreLog().info(info.toString());
        System.out.println(info.toString());
    } else if (StringUtils.isNotEmpty(file)) {
        try {
            LineNumberReader lr = new LineNumberReader(new FileReader(file));
            String sqlline = lr.readLine();
            int recvCount = 0;
            while (sqlline != null) {
                sqlline = sqlline.trim();
                if (StringUtils.isNotEmpty(sqlline)) {
                    if (sqlline.startsWith("insert") || sqlline.startsWith("update")
                            || sqlline.startsWith("delete") || sqlline.startsWith("INSERT")
                            || sqlline.startsWith("UPDATE") || sqlline.startsWith("DELETE")) {
                        msgBuf.append("\n" + sqlline);
                        recvCount++;
                    } else {
                        msgBuf.append(" " + sqlline);
                    }
                }
                sqlline = lr.readLine();
            }
            lr.close();
            StringBuilder info = new StringBuilder("Read file ok. The Sql Number is " + recvCount);
            LogUtil.getCoreLog().info(info.toString());
            System.out.println(info.toString());
            processor.parserOneMessage(msgBuf.toString());
            processor.remoteProcess();
        } catch (IOException e) {
            LogUtil.getCoreLog().error("execute error, file:" + file, e);
            return false;
        }
    }
    return true;
}

From source file:org.beangle.emsapp.system.action.FileAction.java

public String download() throws IOException {
    String path = get("path");
    FileMimeType fileMimeType = new FileMimeType(mimeTypeProvider);
    if (StringUtils.isNotBlank(path)) {
        File file = new File(path);
        if (!file.isFile()) {
            return null;
        }//from w w  w.  j  ava2 s  . co m
        boolean download = getBool("download");
        if (!download && fileMimeType.isTextType(file)) {
            List<String> lines = CollectUtils.newArrayList();
            LineNumberReader reader = new LineNumberReader(new FileReader(file));
            String line = reader.readLine();
            while (null != line) {
                lines.add(line);
                line = reader.readLine();
            }
            put("lines", lines);
            put("file", file);
            reader.close();
            return forward("content");
        } else {
            streamDownloader.download(getRequest(), getResponse(), file);
        }
    }
    return null;
}

From source file:edu.umn.msi.tropix.common.io.IOUtilsImpl.java

public String readLine(@Nonnull final LineNumberReader lineNumberReader) {
    try {/* w ww.ja va  2s .  c  o  m*/
        return lineNumberReader.readLine();
    } catch (final IOException e) {
        throw new IORuntimeException(e);
    }
}

From source file:org.apache.streams.rss.test.RssStreamProviderIT.java

@Test
public void testRssStreamProvider() throws Exception {

    final String configfile = "./target/test-classes/RssStreamProviderIT.conf";
    final String outfile = "./target/test-classes/RssStreamProviderIT.stdout.txt";

    InputStream is = RssStreamProviderIT.class.getResourceAsStream("/top100.txt");
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);

    RssStreamConfiguration configuration = new RssStreamConfiguration();
    List<FeedDetails> feedArray = new ArrayList<>();
    try {/* www . j a va2s  .  c  om*/
        while (br.ready()) {
            String line = br.readLine();
            if (!StringUtils.isEmpty(line)) {
                feedArray.add(new FeedDetails().withUrl(line).withPollIntervalMillis(5000L));
            }
        }
        configuration.setFeeds(feedArray);
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail();
    }

    org.junit.Assert.assertThat(configuration.getFeeds().size(), greaterThan(70));

    OutputStream os = new FileOutputStream(configfile);
    OutputStreamWriter osw = new OutputStreamWriter(os);
    BufferedWriter bw = new BufferedWriter(osw);

    // write conf
    ObjectNode feedsNode = mapper.convertValue(configuration, ObjectNode.class);
    JsonNode configNode = mapper.createObjectNode().set("rss", feedsNode);

    bw.write(mapper.writeValueAsString(configNode));
    bw.flush();
    bw.close();

    File config = new File(configfile);
    assert (config.exists());
    assert (config.canRead());
    assert (config.isFile());

    RssStreamProvider.main(new String[] { configfile, outfile });

    File out = new File(outfile);
    assert (out.exists());
    assert (out.canRead());
    assert (out.isFile());

    FileReader outReader = new FileReader(out);
    LineNumberReader outCounter = new LineNumberReader(outReader);

    while (outCounter.readLine() != null) {
    }

    assert (outCounter.getLineNumber() >= 200);

}

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

private void read(final File aFile) throws IOException {
    LineNumberReader reader = null;
    try {//from w  ww.  j a  va 2 s. c o m
        reader = new LineNumberReader(new FileReader(aFile));
        String line = null;
        while ((line = reader.readLine()) != null) {
            if (line.length() > 0) {
                final String[] s = line.split("\t");
                final String[] t = new String[s.length - 1];
                System.arraycopy(s, 1, t, 0, t.length);

                // get absolute path for stored relative path
                for (int i = 0; i < t.length; i++) {
                    t[i] = new File(indexFile.getParent(), t[i]).getAbsolutePath();
                }

                map.put(s[0], t);
            }
        }
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

From source file:org.seqdoop.hadoop_bam.TestVCFOutputFormat.java

private void skipHeader(LineNumberReader reader) throws IOException {
    String line = reader.readLine();
    while (line.startsWith("#")) {
        reader.mark(1000);//from   ww  w .j  a va 2  s  .c o m
        line = reader.readLine();
    }
    reader.reset();
}

From source file:eu.fbk.utils.analysis.stemmer.AbstractStemmer.java

/**
 * Stems a list of terms read from the specified reader.
 *
 * @param r the reader//  w w  w  .  ja va  2s.  c om
 */
public void process(Reader r) throws IOException {
    long begin = 0, end = 0, time = 0;
    int count = 0;
    LineNumberReader lnr = new LineNumberReader(r);
    String line = null;
    String s = null;
    while ((line = lnr.readLine()) != null) {
        begin = System.nanoTime();
        s = stem(line);
        end = System.nanoTime();
        time += end - begin;
        count++;
    } // end while
    lnr.close();
    logger.info(count + " total " + df.format(time) + " ns");
    logger.info("avg " + df.format((double) time / count) + " ns");
}

From source file:codingchallenge.SortableChallenge.java

private void processListings() throws IOException, JSONException {
    try {//w w w. j a va  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:org.beangle.ems.system.web.action.FileAction.java

public String download() throws IOException {
    String path = get("path");
    FileMimeType fileMimeType = new FileMimeType(mimeTypeProvider);
    if (Strings.isNotBlank(path)) {
        File file = new File(path);
        if (!file.isFile()) {
            return null;
        }/*from  w w  w.  java 2 s  . co m*/
        boolean download = getBool("download");
        if (!download && fileMimeType.isTextType(file)) {
            List<String> lines = CollectUtils.newArrayList();
            LineNumberReader reader = new LineNumberReader(new FileReader(file));
            String line = reader.readLine();
            while (null != line) {
                lines.add(line);
                line = reader.readLine();
            }
            put("lines", lines);
            put("file", file);
            reader.close();
            return forward("content");
        } else {
            streamDownloader.download(getRequest(), getResponse(), file);
        }
    }
    return null;
}

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

/**
 * Find occurrences of incompatible setter syntax for Internet explorer
 * i.e. Widget.preferences.foo=bar;/*  w  w  w.j  ava  2s .c  om*/
 * 
 * @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);
            }
        }
    }
}