Example usage for java.io LineNumberReader close

List of usage examples for java.io LineNumberReader close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Usage

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

private void initialize(final File baseDir) throws NumberFormatException, IOException {
    ngramCountMap = new HashMap<Integer, Long>();
    ngramDistinctCountMap = new HashMap<Integer, Long>();

    final File countFile = new File(baseDir, JWeb1TAggregator.AGGREGATED_COUNTS_FILE);
    if (countFile.exists()) {
        final LineNumberReader lineReader = new LineNumberReader(new FileReader(countFile));
        String line;/*from   w ww. jav  a  2 s . c o  m*/
        while ((line = lineReader.readLine()) != null) {
            final String[] parts = line.split("\t");

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

            final int ngramSize = Integer.valueOf(parts[0]);
            final long ngramDistinctCount = Long.valueOf(parts[1]);
            final long ngramCount = Long.valueOf(parts[2]);

            ngramCountMap.put(ngramSize, ngramCount);
            ngramDistinctCountMap.put(ngramSize, ngramDistinctCount);
        }
        lineReader.close();
    }

}

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

private void initialize(final File baseDir) throws NumberFormatException, IOException {
    indexMap = new HashMap<Integer, FileMap>();
    ngramCountMap = new HashMap<Integer, Long>();
    ngramDistinctCountMap = new HashMap<Integer, Long>();

    final File countFile = new File(baseDir, JWeb1TAggregator.AGGREGATED_COUNTS_FILE);
    if (countFile.exists()) {
        final LineNumberReader lineReader = new LineNumberReader(new FileReader(countFile));
        String line;//from ww  w. ja  v  a2s. c  o m
        while ((line = lineReader.readLine()) != null) {
            final String[] parts = line.split("\t");

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

            final int ngramSize = Integer.valueOf(parts[0]);
            final long ngramDistinctCount = Long.valueOf(parts[1]);
            final long ngramCount = Long.valueOf(parts[2]);

            ngramCountMap.put(ngramSize, ngramCount);
            ngramDistinctCountMap.put(ngramSize, ngramDistinctCount);
        }
        lineReader.close();
    }

}

From source file:com.bigdata.rdf.sail.webapp.AbstractTestNanoSparqlClient.java

/**
 * Read the contents of a file./*from   w w  w  .j a v  a  2  s  . co m*/
 * 
 * @param file
 *            The file.
 * @return It's contents.
 */
protected static String readFromFile(final File file) throws IOException {

    final LineNumberReader r = new LineNumberReader(new FileReader(file));

    try {

        final StringBuilder sb = new StringBuilder();

        String s;
        while ((s = r.readLine()) != null) {

            if (r.getLineNumber() > 1)
                sb.append("\n");

            sb.append(s);

        }

        return sb.toString();

    } finally {

        r.close();

    }

}

From source file:com.saptarshidebnath.lib.processrunner.process.RunnerFactoryTest.java

private int getFileLineNumber(final File fileToCountLineNumber) throws IOException {
    LineNumberReader lnr = null;
    int lineNumber;
    try {/* w  w w .  j  av a  2  s . c om*/
        lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(fileToCountLineNumber)));
        long skipValue = Long.MAX_VALUE;
        while (skipValue != 0) {
            skipValue = lnr.skip(Long.MAX_VALUE);
        }
        lineNumber = lnr.getLineNumber() + 1; // Add 1 because line index starts at 0
    } finally {
        if (lnr != null) {
            lnr.close();
        }
    }
    return lineNumber;
}

From source file:org.apache.axis.security.simple.SimpleSecurityProvider.java

private synchronized void initialize(MessageContext msgContext) {
    if (initialized)
        return;/*  www .j av a2  s .  c  om*/

    String configPath = msgContext.getStrProp(Constants.MC_CONFIGPATH);
    if (configPath == null) {
        configPath = "";
    } else {
        configPath += File.separator;
    }
    File userFile = new File(configPath + "users.lst");
    if (userFile.exists()) {
        users = new HashMap();

        try {

            FileReader fr = new FileReader(userFile);
            LineNumberReader lnr = new LineNumberReader(fr);
            String line = null;

            // parse lines into user and passwd tokens and add result to hash table
            while ((line = lnr.readLine()) != null) {
                StringTokenizer st = new StringTokenizer(line);
                if (st.hasMoreTokens()) {
                    String userID = st.nextToken();
                    String passwd = (st.hasMoreTokens()) ? st.nextToken() : "";

                    if (log.isDebugEnabled()) {
                        log.debug(Messages.getMessage("fromFile00", userID, passwd));
                    }

                    users.put(userID, passwd);
                }
            }

            lnr.close();

        } catch (Exception e) {
            log.error(Messages.getMessage("exception00"), e);
            return;
        }
    }
    initialized = true;
}

From source file:org.springframework.xd.jdbc.SingleTableDatabaseInitializer.java

private Resource substitutePlaceholdersForResource(Resource resource) {

    StringBuilder script = new StringBuilder();

    try {/*from  w w  w.  ja  v  a2  s. c o  m*/
        EncodedResource er = new EncodedResource(resource);
        LineNumberReader lnr = new LineNumberReader(er.getReader());
        String line = lnr.readLine();
        while (line != null) {
            if (tableName != null && line.contains(TABLE_PLACEHOLDER)) {
                logger.debug(
                        "Substituting '" + TABLE_PLACEHOLDER + "' with '" + tableName + "' in '" + line + "'");
                line = line.replace(TABLE_PLACEHOLDER, tableName);
            }
            if (line.contains(COLUMNS_PLACEHOLDER)) {
                logger.debug(
                        "Substituting '" + COLUMNS_PLACEHOLDER + "' with '" + columns + "' in '" + line + "'");
                line = line.replace(COLUMNS_PLACEHOLDER, columns);
            }
            script.append(line + "\n");
            line = lnr.readLine();
        }
        lnr.close();
        return new ByteArrayResource(script.toString().getBytes());
    } catch (IOException e) {
        throw new InvalidDataAccessResourceUsageException("Unable to read script " + resource, e);
    }
}

From source file:com.feilong.tools.ant.plugin.jpa.ParseJPATest.java

/**
 * Aa.//from  w  w  w . j  a  v  a 2  s.c  o m
 *
 * @param longTextFile
 *            the long text file
 * @return the list< column>
 * @throws FileNotFoundException
 *             the file not found exception
 * @throws IOException
 *             the IO exception
 */
private List<Column> aa(String longTextFile) throws FileNotFoundException, IOException {
    Reader reader = new FileReader(longTextFile);
    LineNumberReader lineNumberReader = new LineNumberReader(reader);

    String line = null;

    List<Column> columnlist = new ArrayList<Column>();

    while ((line = lineNumberReader.readLine()) != null) {
        int lineNumber = lineNumberReader.getLineNumber();
        //         if (log.isDebugEnabled()){
        //            log.debug("the param lineNumber:{}", lineNumber);
        //         }

        String[] split = line.split("\t");

        Column column = new Column();

        column.setTableName(split[0]);
        column.setColumnName(split[1]);
        //column.setLength(columnName);
        column.setType(split[2]);
        columnlist.add(column);
    }

    lineNumberReader.close();

    return columnlist;

}

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

/**
 * imports all ts from given blockfile//from w  w  w .  j a  va  2 s.  c  om
 */
public void importBlockFile(final File blockFile) {
    LineNumberReader reader = null;
    try {
        reader = new LineNumberReader(new FileReader(blockFile));

        final BlockTimeStep timeStep = searchTimeoffset(reader);

        while (reader.ready()) {
            final Entry<String, Integer> blockInfo = searchBlockHeader(reader);
            if (blockInfo == null)
                break;

            final String key = blockInfo.getKey();
            final int valuesCount = blockInfo.getValue();

            // Add values to existing block
            final Block block = getOrCreateBlock(key, timeStep);
            block.readValues(reader, valuesCount);
        }
        reader.close();
    } catch (final Exception e) {
        e.printStackTrace();
        System.out.println("could not read blockfile "); //$NON-NLS-1$
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

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

private void parseData() {
    LineNumberReader lnr = null;
    try {// w  ww  .  j a va2  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: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);/*  w  w  w.  ja  va 2 s . c  o  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;
}