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:com.gettextresourcebundle.GettextResourceBundle.java

public GettextResourceBundle(Reader reader) {
    init(new LineNumberReader(reader));
}

From source file:com.hs.mail.web.util.DataImporter.java

public void importAccount(UserManager manager, InputStream is) throws IOException {
    LineNumberReader reader = new LineNumberReader(new InputStreamReader(is));
    String line;//from   w ww  .j a  v  a 2 s. c om
    while ((line = reader.readLine()) != null) {
        try {
            User user = parseAccount(line);
            manager.addUser(user);
        } catch (Exception e) {
            addError(reader.getLineNumber(), line, e);
        }
    }
}

From source file:org.kuali.test.proxyserver.MultiPartHandler.java

public MultiPartHandler(MultipartStream multipartStream) throws IOException {
    LineNumberReader lnr = null;/*from  ww  w.  j a  va 2s  . co m*/
    try {
        lnr = new LineNumberReader(new StringReader(multipartStream.readHeaders()));
        String line;

        while ((line = lnr.readLine()) != null) {
            if (line.startsWith(Constants.CONTENT_DISPOSITION)) {
                for (String param : PARAMETER_NAMES) {
                    int pos = line.indexOf(param);
                    if (pos > -1) {
                        pos += (param.length() + 2);
                        int pos2 = line.indexOf("\"", pos);

                        if ((pos > -1) && (pos2 > -1) && (pos2 > pos)) {
                            parameters.put(param, line.substring(pos, pos2));
                        }
                    }
                }
            }

            if (line.startsWith(Constants.HTTP_RESPONSE_CONTENT_TYPE)) {
                int pos = line.indexOf(Constants.SEPARATOR_COLON);

                if (pos > -1) {
                    contentType = line.substring(pos + 1).trim();
                }
            }
        }

        ByteArrayOutputStream bos = new ByteArrayOutputStream(512);
        multipartStream.readBodyData(bos);
        bytes = bos.toByteArray();
    }

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

        catch (Exception ex) {
        }
        ;
    }
}

From source file:org.latticesoft.util.common.FileIterator.java

public FileIterator(String filename) {
    try {//  ww w  .  j  a  va  2  s . c o  m
        File file = new File(filename);
        is = new FileInputStream(file);
        isr = new InputStreamReader(is);
        lnr = new LineNumberReader(isr);
        active = true;
    } catch (Exception e) {
        if (log.isErrorEnabled()) {
            log.error(e);
        }
    }
}

From source file:mitm.common.fetchmail.FetchmailConfigBuilder.java

/**
 * Writes the new config to targetConfig. Lines between START_TOKEN and END_TOKEN are replaced with the 
 * new config from FetchmailConfig.// www  . j  a  v  a 2  s  .c  o m
 */
public static void createConfig(FetchmailConfig config, InputStream sourceConfig, OutputStream targetConfig)
        throws IOException {
    LineNumberReader reader = new LineNumberReader(new InputStreamReader(sourceConfig, "US-ASCII"));

    StrBuilder outputBuilder = new StrBuilder();

    boolean inBlock = false;
    boolean blockInjected = false;

    String line;

    do {
        line = reader.readLine();

        if (line != null) {
            if (inBlock) {
                if (line.startsWith(END_TOKEN)) {
                    inBlock = false;
                    blockInjected = true;

                    injectConfig(config, outputBuilder);

                    outputBuilder.appendln(line);
                }
            } else {
                if (!blockInjected && line.startsWith(START_TOKEN)) {
                    inBlock = true;
                }

                outputBuilder.appendln(line);
            }
        }
    } while (line != null);

    targetConfig.write(MiscStringUtils.toAsciiBytes(outputBuilder.toString()));
}

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

private void read(final File aFile) throws IOException {
    LineNumberReader reader = null;
    try {/*from  ww w. j a va  2 s.com*/
        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.kawanfw.sql.jdbc.util.CallableUtil.java

public static CallableStatementHolder fromRsFile(File file, ConnectionHttp connectionHttp) throws SQLException {
    if (!file.exists()) {
        String message = Tag.PRODUCT_PRODUCT_FAIL + "Internal File does not exists: " + file;
        throw new SQLException(message, new IOException(message));
    }/*from  w  w  w . j  a v a  2s  . c o m*/

    String line = null;
    LineNumberReader lineNumberReader = null;

    try {
        lineNumberReader = new LineNumberReader(new FileReader(file));
        line = lineNumberReader.readLine();
    } catch (FileNotFoundException e) {
        String message = Tag.PRODUCT_PRODUCT_FAIL + "Internal File does not exists: " + file;
        throw new SQLException(message, new IOException(message));
    } catch (IOException e) {
        String message = Tag.PRODUCT_PRODUCT_FAIL + "I/O Error when reading file: " + file;
        throw new SQLException(message, new IOException(message));
    } finally {
        IOUtils.closeQuietly(lineNumberReader);
    }

    if (line == null) {
        String message = Tag.PRODUCT_PRODUCT_FAIL + "Internal File is empty: " + file;
        throw new SQLException(message, new IOException(message));
    }

    line = JsonLineDecryptor.decrypt(line, connectionHttp);

    return CallableStatementHolderTransportJson.fromJson(line);
}

From source file:com.acmeair.loader.FlightLoader.java

public void loadFlights() throws Exception {
    InputStream csvInputStream = FlightLoader.class.getResourceAsStream("/mileage.csv");

    LineNumberReader lnr = new LineNumberReader(new InputStreamReader(csvInputStream));
    String line1 = lnr.readLine();
    StringTokenizer st = new StringTokenizer(line1, ",");
    ArrayList<AirportCodeMapping> airports = new ArrayList<AirportCodeMapping>();

    // read the first line which are airport names
    while (st.hasMoreTokens()) {
        AirportCodeMapping acm = new AirportCodeMapping();
        acm.setAirportName(st.nextToken());
        airports.add(acm);//from  ww  w . j a v a  2  s  .c  o  m
    }
    // read the second line which contains matching airport codes for the first line
    String line2 = lnr.readLine();
    st = new StringTokenizer(line2, ",");
    int ii = 0;
    while (st.hasMoreTokens()) {
        String airportCode = st.nextToken();
        airports.get(ii).setAirportCode(airportCode);
        ii++;
    }
    // read the other lines which are of format:
    // airport name, aiport code, distance from this airport to whatever airport is in the column from lines one and two
    String line;
    int flightNumber = 0;
    while (true) {
        line = lnr.readLine();
        if (line == null || line.trim().equals("")) {
            break;
        }
        st = new StringTokenizer(line, ",");
        String airportName = st.nextToken();
        String airportCode = st.nextToken();
        if (!alreadyInCollection(airportCode, airports)) {
            AirportCodeMapping acm = new AirportCodeMapping();
            acm.setAirportName(airportName);
            acm.setAirportCode(airportCode);
            airports.add(acm);
        }
        int indexIntoTopLine = 0;
        while (st.hasMoreTokens()) {
            String milesString = st.nextToken();
            if (milesString.equals("NA")) {
                indexIntoTopLine++;
                continue;
            }
            int miles = Integer.parseInt(milesString);
            String toAirport = airports.get(indexIntoTopLine).getAirportCode();
            String flightId = "AA" + flightNumber;
            FlightSegment flightSeg = new FlightSegment(flightId, airportCode, toAirport, miles);
            flightService.storeFlightSegment(flightSeg);
            Date now = new Date();
            for (int daysFromNow = 0; daysFromNow < MAX_FLIGHTS_PER_SEGMENT; daysFromNow++) {
                Calendar c = Calendar.getInstance();
                c.setTime(now);
                c.set(Calendar.HOUR_OF_DAY, 0);
                c.set(Calendar.MINUTE, 0);
                c.set(Calendar.SECOND, 0);
                c.set(Calendar.MILLISECOND, 0);
                c.add(Calendar.DATE, daysFromNow);
                Date departureTime = c.getTime();
                Date arrivalTime = getArrivalTime(departureTime, miles);
                flightService.createNewFlight(flightId, departureTime, arrivalTime, new BigDecimal(500),
                        new BigDecimal(200), 10, 200, "B747");

            }
            flightNumber++;
            indexIntoTopLine++;
        }
    }

    for (int jj = 0; jj < airports.size(); jj++) {
        flightService.storeAirportMapping(airports.get(jj));
    }
    lnr.close();
}

From source file:org.sonar.graph.DsmScanner.java

private DsmScanner(Reader reader) {
    this.reader = new LineNumberReader(reader);
}

From source file:com.marklogic.contentpump.GzipDelimitedJSONReader.java

@Override
protected void initFileStream(InputSplit inSplit) throws IOException, InterruptedException {
    setFile(((FileSplit) inSplit).getPath());
    configFileNameAsCollection(conf, file);
    fileIn = fs.open(file);/*from  w w w.j av  a 2s .  co m*/
    gzipIn = new GZIPInputStream(fileIn);
    instream = new InputStreamReader(gzipIn, encoding);
    reader = new LineNumberReader(instream);
}