List of usage examples for java.io LineNumberReader LineNumberReader
public LineNumberReader(Reader in)
From source file:com.feilong.tools.ant.plugin.jpa.ParseJPATest.java
/** * Aa./*from w ww .j a v a2 s. c om*/ * * @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.kuali.test.runner.execution.TestExecutionMonitor.java
private File getMergedPerformanceDataFile() { File retval = null;/*from www . j av a 2 s . c o m*/ PrintWriter pw = null; try { boolean headerWritten = false; for (TestExecutionContext tec : testExecutionList) { File f = tec.getPerformanceDataFile(); if (f != null) { if (pw == null) { int pos = f.getPath().lastIndexOf("_"); pw = new PrintWriter(retval = new File(f.getPath().substring(0, pos) + ".csv")); } LineNumberReader lnr = null; try { lnr = new LineNumberReader(new FileReader(f)); if (headerWritten) { lnr.readLine(); } String line = null; while ((line = lnr.readLine()) != null) { pw.println(line); } headerWritten = true; } catch (Exception ex) { LOG.error(ex.toString(), ex); } finally { if (lnr != null) { try { lnr.close(); FileUtils.deleteQuietly(f); } catch (Exception ex) { } ; } } } } } catch (Exception ex) { LOG.error(ex.toString(), ex); retval = null; } finally { if (pw != null) { pw.close(); } } return retval; }
From source file:mitm.common.postfix.PostfixLogParser.java
private void parseLog(Reader log) throws IOException { LineNumberReader lineReader = new LineNumberReader(log); index = 0;/* w ww.j a v a2 s . co m*/ stopParsing = false; activeItems = new HashMap<String, SortableLogItem>(); String line; while (!stopParsing && (line = lineReader.readLine()) != null) { parseLine(line); } /* * If stopParsing was false we came to the end of the log. There can however still be items * in activeItems. This happens when a message is still in one of the postfix queues * (message is not yet delivered). We will therefore 'force finish' the items still active * until stopParsing */ for (SortableLogItem logItem : activeItems.values()) { if (stopParsing) { break; } logItemComplete(logItem); } }
From source file:org.kalypso.model.hydrology.internal.postprocessing.LzsToGml.java
private void readLzsFile(final FileReader fileReader, final Catchment catchment, final Feature lzCatchmentFE) throws Exception { final LineNumberReader reader = new LineNumberReader(fileReader); final IFeatureType lzCatchmentFT = GMLSchemaUtilities .getFeatureTypeQuiet(new QName(NaModelConstants.NS_INIVALUES, "Catchment")); //$NON-NLS-1$ final IRelationType lzinitHydMemberRT = (IRelationType) lzCatchmentFT .getProperty(NaModelConstants.INI_CATCHMENT_LINK_HYD_PROP); final String iniDate = m_dateFormat.format(m_initialDate); int maxHydros = 0; int counterHydros = 0; // TODO: why compare the datum? IT would be more robust to just read all data that is in the lsz file, and append // it to the features! CatchmentStatus status = CatchmentStatus.SEARCH_HEADER; while (reader.ready()) { final String line = reader.readLine(); if (line == null) break; final String cleanLine = line.trim().replaceAll("\\s+", " "); //$NON-NLS-1$ //$NON-NLS-2$ switch (status) { case SEARCH_HEADER: final Matcher matcherBODF = PATTERN_HEADER_BODF.matcher(cleanLine); if (cleanLine.endsWith("snow") && cleanLine.startsWith(iniDate)) //$NON-NLS-1$ status = CatchmentStatus.READ_SNOW; else if (cleanLine.endsWith("gwsp") && cleanLine.startsWith(iniDate)) //$NON-NLS-1$ status = CatchmentStatus.READ_GWSP; else if (matcherBODF.matches() && cleanLine.startsWith(iniDate)) { status = CatchmentStatus.READ_BODF; maxHydros = Integer.parseInt(matcherBODF.group(2)); }//from ww w .j a v a 2 s.c o m break; case READ_BODF: { final Feature lzHydFE = m_lzWorkspace.createFeature(lzCatchmentFE, lzinitHydMemberRT, lzinitHydMemberRT.getTargetFeatureType()); m_lzWorkspace.addFeatureAsComposition(lzCatchmentFE, lzinitHydMemberRT, 0, lzHydFE); final String[] strings = cleanLine.split(" "); //$NON-NLS-1$ final int pos = Integer.parseInt(strings[0]) - 1; final String hydroID = m_hydroHash.getHydroFeatureId(catchment, pos); lzHydFE.setProperty(new QName(NaModelConstants.NS_INIVALUES, "featureId"), hydroID); //$NON-NLS-1$ final Double interception = Double.valueOf(strings[1]); final List<Double> bofs = new ArrayList<>(); for (int i = 2; i < strings.length; i++) { final Double bf = Double.valueOf(strings[i]); bofs.add(bf); } lzHydFE.setProperty(new QName(NaModelConstants.NS_INIVALUES, "bi"), interception); //$NON-NLS-1$ lzHydFE.setProperty(new QName(NaModelConstants.NS_INIVALUES, "bofs"), bofs); //$NON-NLS-1$ counterHydros++; if (counterHydros >= maxHydros) { status = CatchmentStatus.SEARCH_HEADER; counterHydros = 0; } } break; case READ_GWSP: { final String[] strings = cleanLine.split(" "); //$NON-NLS-1$ final Double hgws = Double.valueOf(strings[1]);// hoehe gw final Double qb = Double.valueOf(strings[2]);// basisabfluss lzCatchmentFE.setProperty(new QName(NaModelConstants.NS_INIVALUES, "hgws"), hgws); //$NON-NLS-1$ lzCatchmentFE.setProperty(new QName(NaModelConstants.NS_INIVALUES, "qb"), qb); //$NON-NLS-1$ status = CatchmentStatus.SEARCH_HEADER; } break; case READ_SNOW: final String[] strings = cleanLine.split(" "); //$NON-NLS-1$ final Double h = Double.valueOf(strings[1]);// hoehe schnee final Double ws = Double.valueOf(strings[2]);// wassergehalt lzCatchmentFE.setProperty(new QName(NaModelConstants.NS_INIVALUES, "h"), h); //$NON-NLS-1$ lzCatchmentFE.setProperty(new QName(NaModelConstants.NS_INIVALUES, "ws"), ws); //$NON-NLS-1$ status = CatchmentStatus.SEARCH_HEADER; break; } } // TODO: if we reach this line without any read data, something is wrong! }
From source file:massbank.BatchJobWorker.java
/** * Ytt@C???ieLXg`?j//from w w w.ja va 2 s.co m * @param time NGXg * @param resultFile t@C * @param textFile YtpeLXgt@C */ private void createTextFile(String time, File resultFile, File textFile) { NumberFormat nf = NumberFormat.getNumberInstance(); LineNumberReader in = null; PrintWriter out = null; try { in = new LineNumberReader(new FileReader(resultFile)); out = new PrintWriter(new BufferedWriter(new FileWriter(textFile))); // wb_?[?o String reqIonStr = "Both"; try { if (Integer.parseInt(this.ion) > 0) { reqIonStr = "Positive"; } else if (Integer.parseInt(this.ion) < 0) { reqIonStr = "Negative"; } } catch (NumberFormatException nfe) { nfe.printStackTrace(); } out.println("***** MassBank Batch Service Results *****"); out.println(); out.println("Request Date: " + time); out.println("# Instrument Type: " + this.inst); out.println("# Ion Mode: " + reqIonStr); out.println(); out.println(); // ?o String line; long queryCnt = 0; boolean readName = false; boolean readHit = false; boolean readNum = false; boolean isFinalLine = false; while ((line = in.readLine()) != null) { isFinalLine = false; if (in.getLineNumber() < 4) { continue; } if (!readName) { queryCnt++; out.println("### Query " + nf.format(queryCnt) + " ###"); out.println("# Name: " + line.trim()); readName = true; } else if (!readHit) { out.println("# Hit: " + nf.format(Integer.parseInt(line.trim()))); out.println(); readHit = true; } else if (!readNum) { out.println("Top " + line.trim() + " List"); out.println("Accession\tTitle\tFormula\tIon\tScore\tHit"); out.println(); readNum = true; } else { if (!line.trim().equals("")) { String[] data = formatLine(line); StringBuilder sb = new StringBuilder(); sb.append(data[0]).append("\t").append(data[1]).append("\t").append(data[2]).append("\t") .append(data[3]).append("\t").append(data[4]).append("\t").append(data[5]); out.println(sb.toString()); } else { out.println(); out.println(); readName = false; readHit = false; readNum = false; isFinalLine = true; } } } if (!isFinalLine) { out.println(); out.println(); } out.println("##### END #####"); out.println(); out.println("**********************************************************"); out.println("* MassBank.jp - High Resolution Mass Spectral Database *"); out.println("* URL: http://www.massbank.jp/ *"); out.println("**********************************************************"); out.println(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { } if (out != null) { out.flush(); out.close(); } } }
From source file:org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.java
/** * Read a script from the given resource and build a String containing the lines. * @param resource the resource to be read * @return {@code String} containing the script lines * @throws IOException in case of I/O errors */// ww w . ja v a2 s . c om private String readScript(EncodedResource resource) throws IOException { LineNumberReader lnr = new LineNumberReader(resource.getReader()); try { String currentStatement = lnr.readLine(); StringBuilder scriptBuilder = new StringBuilder(); while (currentStatement != null) { if (StringUtils.hasText(currentStatement) && (this.commentPrefix != null && !currentStatement.startsWith(this.commentPrefix))) { if (scriptBuilder.length() > 0) { scriptBuilder.append('\n'); } scriptBuilder.append(currentStatement); } currentStatement = lnr.readLine(); } maybeAddSeparatorToScript(scriptBuilder); return scriptBuilder.toString(); } finally { lnr.close(); } }
From source file:com.jkoolcloud.tnt4j.streams.inputs.ZipLineStream.java
private boolean hasNextEntry() throws IOException { if (zipStream instanceof ZipInputStream) { ZipInputStream zis = (ZipInputStream) zipStream; ZipEntry entry;//from w w w . j a v a 2 s .co m while ((entry = zis.getNextEntry()) != null) { String entryName = entry.getName(); if (entry.getSize() != 0 && (zipEntriesMask == null || entryName.matches(zipEntriesMask))) { totalBytesCount += entry.getSize(); lineReader = new LineNumberReader(new BufferedReader(new InputStreamReader(zis))); lineNumber = 0; logger().log(OpLevel.DEBUG, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ZipLineStream.opening.entry"), entryName); return true; } } } return false; }
From source file:com.l2jfree.gameserver.model.L2Manor.java
private void parseData() { LineNumberReader lnr = null;// w w w . j av a2 s. c om try { File seedData = new File(Config.DATAPACK_ROOT, "data/seeds.csv"); lnr = new LineNumberReader(new BufferedReader(new FileReader(seedData))); String line = null; while ((line = lnr.readLine()) != null) { if (line.trim().length() == 0 || line.startsWith("#")) continue; SeedData seed = parseList(line); _seeds.put(seed.getId(), seed); } _log.info("ManorManager: Loaded " + _seeds.size() + " seeds"); } catch (FileNotFoundException e) { _log.info("seeds.csv is missing in data folder", e); } catch (Exception e) { _log.info("error while loading seeds: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(lnr); } }
From source file:org.lockss.plugin.metapress.LocalRisMetadataExtractor.java
/** * Extract metadata from the content of the cu, which should be an RIS file. * Reads line by line inserting the 2 character code and value into the raw map. * The first line should be a material type witch if it is book or journal will * determine if we interpret the SN tag as IS beltSN or ISBN. * @param target// www . j a v a 2 s .co m * @param cu */ public final ArticleMetadata extract(MetadataTarget target, CachedUrl cu) throws IOException, PluginException { if (cu == null) { throw new IllegalArgumentException(); } log.debug2("Parsing " + cu.getUrl()); am = new ArticleMetadata(); refType = null; currentTag = null; currentValue = new StringBuilder(); boolean hasBegun = false; LineNumberReader reader = new LineNumberReader(cu.openForReading()); try { for (String line = reader.readLine(); line != null; line = reader.readLine()) { // Skip empty lines at beginning of file if (!hasBegun && line.trim().isEmpty()) { continue; } hasBegun = true; Matcher mat = risPattern.matcher(line); if (mat.find()) { // process old tag processTag(); // set up new tag currentTag = mat.group(1); currentValue = new StringBuilder(mat.group(2).trim()); } else { if (currentTag == null) { log.debug(String.format("%s line %d: ignoring continuation line in preamble", cu.getUrl(), reader.getLineNumber())); continue; } // process continuation of current tag String continuation = line.trim(); if (!continuation.isEmpty()) { currentValue.append(' '); currentValue.append(continuation); } } } processTag(); } finally { IOUtil.safeClose(reader); } am.cook(risTagToMetadataField); return am; }
From source file:be.jacobsvanroy.springsqlunit.util.ScriptUtils.java
/** * Read a script from the provided resource, using the supplied comment prefix * and statement separator, and build a {@code String} containing the lines. * <p>Lines <em>beginning</em> with the comment prefix are excluded from the * results; however, line comments anywhere else — for example, within * a statement — will be included in the results. * * @param resource the {@code EncodedResource} containing the script * to be processed/* w w w. j a v a 2 s . c o m*/ * @param commentPrefix the prefix that identifies comments in the SQL script — * typically "--" * @param separator the statement separator in the SQL script — typically ";" * @return a {@code String} containing the script lines * @throws IOException in case of I/O errors */ private static String readScript(EncodedResource resource, String commentPrefix, String separator) throws IOException { LineNumberReader lnr = new LineNumberReader(resource.getReader()); try { return readScript(lnr, commentPrefix, separator); } finally { lnr.close(); } }