Example usage for java.io LineNumberReader skip

List of usage examples for java.io LineNumberReader skip

Introduction

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

Prototype

public long skip(long n) throws IOException 

Source Link

Document

Skip characters.

Usage

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

private int getFileLineNumber(final File fileToCountLineNumber) throws IOException {
    LineNumberReader lnr = null;
    int lineNumber;
    try {/*from  w ww.j  a va 2 s.  co m*/
        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:core.Inject.java

private String[] loadPayloadsFromfile(String pathTo_payloads) {
    String[] _payloads = null;// ww w.  ja  va 2s  .  co  m

    try {
        FileInputStream fstream = new FileInputStream(pathTo_payloads);
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        int i = 0;

        LineNumberReader lnr = new LineNumberReader(new FileReader(pathTo_payloads));
        lnr.skip(Long.MAX_VALUE);

        _payloads = new String[lnr.getLineNumber()];

        while ((strLine = br.readLine()) != null) {
            _payloads[i] = strLine;
            i++;
        }

        in.close();
    } catch (Exception e) {
        Debug.printError("ERROR: unable to load the attack payloads");
        HaltHandler.quit_nok();
    }

    return _payloads;
}

From source file:com.jkoolcloud.tnt4j.streams.utils.Utils.java

/**
 * Counts text lines available in input.
 *
 * @param reader/* w  ww  . j a va2 s  . co m*/
 *            a {@link java.io.Reader} object to provide the underlying input stream
 * @return number of lines currently available in input
 * @throws java.io.IOException
 *             If an I/O error occurs
 * @deprecated use {@link #countLines(java.io.InputStream)} instead
 */
@Deprecated
public static int countLines(Reader reader) throws IOException {
    int lCount = 0;
    LineNumberReader lineReader = null;
    try {
        lineReader = new LineNumberReader(reader);
        lineReader.skip(Long.MAX_VALUE);
        // NOTE: Add 1 because line index starts at 0
        lCount = lineReader.getLineNumber() + 1;
    } finally {
        close(lineReader);
    }

    return lCount;
}

From source file:net.flamefeed.ftb.modpackupdater.FileOperator.java

/**
 * This method will download the hash-file from the server and
 * will extract data from it and populate the remoteHashes 2d array.
 *
 * @throws java.lang.IOException/*from  w w w .  j a  va2  s  .co m*/
 */

private void parseHashfile() throws IOException {
    int numRemoteFiles;
    String[] currentLine;
    FileReader fr;
    BufferedReader br;
    LineNumberReader lnr;

    downloadFile(HASHFILE_NAME);

    /*
     * Compute the number of lines in the hash-file. This corresponds to the
     * number of files on the remote server, and therefore the length of the 
     * hashFiles outer array.
     */

    fr = new FileReader(pathMinecraft + "/" + HASHFILE_NAME);
    lnr = new LineNumberReader(fr);
    lnr.skip(Long.MAX_VALUE);
    numRemoteFiles = lnr.getLineNumber();
    fr.close();

    /*
     * Populate the remoteHashes[][] array with data from the hash file
     */

    remoteHashes = new String[numRemoteFiles][2];

    fr = new FileReader(pathMinecraft + "/" + HASHFILE_NAME);
    br = new BufferedReader(fr);

    /*
     * The hash-file format is as follows:
     * <MD5 hash><tab character><relative filename><newline character>
     * Splitting each line using a tab character "\t" separates the filename
     * from the MD5 hash.
     */

    for (int i = 0; i < numRemoteFiles; i++) {
        currentLine = br.readLine().split("\t", 2);
        remoteHashes[i][MD5HASH] = currentLine[MD5HASH];
        remoteHashes[i][FILENAME] = currentLine[FILENAME];
    }

    fr.close();
}

From source file:org.silverpeas.core.silvertrace.DefaultSilverpeasTrace.java

@Deprecated
@Override// w w  w .  j a  v  a2  s  . c o m
public String[] getEndFileTrace(String nbLines) {
    LineNumberReader lnr = null;
    File theFile = new File(errorDir + "/traces.txt");
    List<String> ar = new ArrayList<String>();
    try {
        // Get file length
        long fileLength = theFile.length();
        if (fileLength == 0L) {
            return ArrayUtils.EMPTY_STRING_ARRAY;
        }
        int nbl = Integer.parseInt(nbLines);
        lnr = new LineNumberReader(new FileReader(theFile));
        if (nbl > 0) {
            if ((nbl + 1) * 100 < fileLength) {
                lnr.skip(fileLength - ((nbl + 1) * 100));
            }
        }
        String line = lnr.readLine();
        while (line != null) {
            line = lnr.readLine();
            if (line != null) {
                ar.add(line);
            }
        }
        return ar.toArray(new String[ar.size()]);
    } catch (Exception e) {
        error("silvertrace", "SilverTrace.getEndFileTrace()", "silvertrace.ERR_RUNTIME_ERROR_OCCUR",
                "File NOT FOUND :" + errorDir + "/traces.txt", e);
        return ArrayUtils.EMPTY_STRING_ARRAY;
    } finally {
        IOUtils.closeQuietly(lnr);
    }
}

From source file:com.stratelia.silverpeas.silvertrace.SilverTrace.java

static public String[] getEndFileTrace(String nbLines) {
    LineNumberReader lnr = null;
    File theFile = new File(errorDir + "/traces.txt");
    List<String> ar = new ArrayList<String>();
    try {/*from www  . ja  v  a2  s  .c  om*/
        // Get file length
        long fileLength = theFile.length();
        if (fileLength == 0L) {
            return ArrayUtils.EMPTY_STRING_ARRAY;
        }
        int nbl = Integer.parseInt(nbLines);
        lnr = new LineNumberReader(new FileReader(theFile));
        if (nbl > 0) {
            if ((nbl + 1) * 100 < fileLength) {
                lnr.skip(fileLength - ((nbl + 1) * 100));
            }
        }
        String line = lnr.readLine();
        while (line != null) {
            line = lnr.readLine();
            if (line != null) {
                ar.add(line);
            }
        }
        return ar.toArray(new String[ar.size()]);
    } catch (Exception e) {
        SilverTrace.error("silvertrace", "SilverTrace.getEndFileTrace()", "silvertrace.ERR_RUNTIME_ERROR_OCCUR",
                "File NOT FOUND :" + errorDir + "/traces.txt", e);
        return ArrayUtils.EMPTY_STRING_ARRAY;
    } finally {
        IOUtils.closeQuietly(lnr);
    }
}

From source file:org.agnitas.beans.impl.MailingImpl.java

@Override
public DynamicTag findNextDynTag(String aTemplate, ApplicationContext con) throws Exception {
    int valueTagStartPos;
    int oldPos;//from w  w  w.  java  2 s .c o  m
    DynamicTag aDynTag = null;
    TagDetails aStartTag = null;
    TagDetails aEndTag = null;
    TagDetails aValueTag = null;

    aStartTag = getOneTag(aTemplate, "agnDYN", searchPos, con);
    if (aStartTag == null)
        return null;

    aStartTag.analyzeParameters();
    aStartTag.findTagParameters();

    searchPos = aStartTag.getEndPos();

    aDynTag = (DynamicTag) con.getBean("DynamicTag");
    aDynTag.setCompanyID(companyID);
    aDynTag.setMailingID(id);
    aDynTag.setComplex(aStartTag.isComplex());
    aDynTag.setDynName(aStartTag.getName());
    int group = 0;

    Map<String, String> params = aStartTag.getTagParameters();

    if (params != null) {
        String gname = (String) params.get("group");

        if (gname != null) {
            DynamicTagDao dao = (DynamicTagDao) con.getBean("DynamicTagDao");
            group = dao.getIdForName(this.id, gname);
        }
    }
    aDynTag.setGroup(group);

    if (aStartTag.isComplex()) {
        oldPos = searchPos;
        do {
            aEndTag = getOneTag(aTemplate, "/agnDYN", searchPos, con);
            if (aEndTag == null) {
                LineNumberReader aReader = new LineNumberReader(new StringReader(aTemplate));
                aReader.skip(searchPos);
                throw new Exception("NoEndTag$" + aReader.getLineNumber() + "$" + aStartTag.getName());
            }
            searchPos = aEndTag.getEndPos();
            aEndTag.analyzeParameters();
        } while (aStartTag.getName().compareTo(aEndTag.getName()) != 0);
        String valueArea = aTemplate.substring(aStartTag.getEndPos(), aEndTag.getStartPos());
        valueTagStartPos = 0;
        do {
            aValueTag = getOneTag(valueArea, "agnDVALUE", valueTagStartPos, con);
            if (aValueTag == null) {
                LineNumberReader aReader = new LineNumberReader(new StringReader(aTemplate));
                aReader.skip(searchPos);
                throw new Exception("NoValueTag$" + aReader.getLineNumber() + "$" + aStartTag.getName());
            }
            valueTagStartPos = aValueTag.getEndPos();
            aValueTag.analyzeParameters();
        } while (aStartTag.getName().compareTo(aValueTag.getName()) != 0);
        searchPos = oldPos;
        aDynTag.setStartTagStart(aStartTag.getStartPos());
        aDynTag.setStartTagEnd(aStartTag.getEndPos());
        aDynTag.setValueTagStart(aStartTag.getEndPos() + aValueTag.getStartPos());
        aDynTag.setValueTagEnd(aStartTag.getEndPos() + aValueTag.getEndPos());
        aDynTag.setEndTagStart(aEndTag.getStartPos());
        aDynTag.setEndTagEnd(aEndTag.getEndPos());
    } else {
        aDynTag.setStartTagStart(aStartTag.getStartPos());
        aDynTag.setStartTagEnd(aStartTag.getEndPos());
    }

    return aDynTag;
}

From source file:org.ngrinder.perftest.service.PerfTestService.java

private int getRecordInterval(int imageWidth, File dataFile) {
    int pointCount = Math.max(imageWidth, MAX_POINT_COUNT);
    FileInputStream in = null;// w  ww . ja v  a  2  s  . co m
    InputStreamReader isr = null;
    LineNumberReader lnr = null;
    int interval = 0;
    try {
        in = new FileInputStream(dataFile);
        isr = new InputStreamReader(in);
        lnr = new LineNumberReader(isr);
        lnr.skip(dataFile.length());
        interval = Math.max((lnr.getLineNumber() + 1) / pointCount, 1);
    } catch (FileNotFoundException e) {
        LOGGER.error("data file not exist:{}", dataFile);
        LOGGER.error(e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.error("Error while getting data file:{}", dataFile);
        LOGGER.error(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(lnr);
        IOUtils.closeQuietly(isr);
        IOUtils.closeQuietly(in);
    }
    return interval;
}

From source file:org.ngrinder.perftest.service.PerfTestService.java

/**
 * Get the monitor data interval value. In the normal, the image width is 700, and if the data count is too big,
 * there will be too many points in the chart. So we will calculate the interval to get appropriate count of data to
 * display. For example, interval value "2" means, get one record for every "2" records.
 *
 * @param testId     test id// w  w  w . ja v  a 2 s  .  c o  m
 * @param targetIP   ip address of monitor target
 * @param imageWidth image with of the chart.
 * @return interval value.
 */
public int getMonitorGraphInterval(long testId, String targetIP, int imageWidth) {
    File monitorDataFile = new File(config.getHome().getPerfTestReportDirectory(String.valueOf(testId)),
            MONITOR_FILE_PREFIX + targetIP + ".data");

    int pointCount = Math.max(imageWidth, MAX_POINT_COUNT);
    FileInputStream in = null;
    InputStreamReader isr = null;
    LineNumberReader lnr = null;
    int interval = 0;
    try {
        in = new FileInputStream(monitorDataFile);
        isr = new InputStreamReader(in);
        lnr = new LineNumberReader(isr);
        lnr.skip(monitorDataFile.length());
        int lineNumber = lnr.getLineNumber() + 1;
        interval = Math.max(lineNumber / pointCount, 1);
    } catch (FileNotFoundException e) {
        LOGGER.info("Monitor data file does not exist at {}", monitorDataFile);
    } catch (IOException e) {
        LOGGER.info("Error while getting monitor:{} data file:{}", targetIP, monitorDataFile);
    } finally {
        IOUtils.closeQuietly(lnr);
        IOUtils.closeQuietly(isr);
        IOUtils.closeQuietly(in);
    }
    return interval;
}

From source file:org.ngrinder.perftest.service.PerfTestService.java

/**
 * get the data point interval of report data. Use dataPointCount / imgWidth as the interval. if interval is 1, it
 * means we will get all point from report. If interval is 2, it means we will get 1 point from every 2 data.
 *
 * @param testId   test id/*from ww w . jav a 2s .  com*/
 * @param dataType data type
 * @param imgWidth image width
 * @return interval interval value
 */
public int getReportDataInterval(long testId, String dataType, int imgWidth) {
    int pointCount = Math.max(imgWidth, MAX_POINT_COUNT);
    File reportFolder = config.getHome().getPerfTestReportDirectory(String.valueOf(testId));
    int interval = 0;
    File targetFile = new File(reportFolder, dataType + DATA_FILE_EXTENSION);
    if (!targetFile.exists()) {
        LOGGER.warn("Report {} for test {} does not exist.", dataType, testId);
        return 0;
    }
    LineNumberReader lnr = null;

    FileInputStream in = null;
    InputStreamReader isr = null;
    try {
        in = new FileInputStream(targetFile);
        isr = new InputStreamReader(in);
        lnr = new LineNumberReader(isr);
        lnr.skip(targetFile.length());
        int lineNumber = lnr.getLineNumber() + 1;
        interval = Math.max(lineNumber / pointCount, 1);
    } catch (Exception e) {
        LOGGER.error("Failed to get report data for {}", dataType, e);
    } finally {
        IOUtils.closeQuietly(lnr);
        IOUtils.closeQuietly(isr);
        IOUtils.closeQuietly(in);
    }

    return interval;
}