List of usage examples for java.io LineNumberReader readLine
public String readLine() throws IOException
From source file:org.kalypso.model.hydrology.internal.postprocessing.LzsToGml.java
private double readLzgFile(final FileReader fileReader) throws NumberFormatException, IOException { final LineNumberReader reader = new LineNumberReader(fileReader); ChannelStatus status = ChannelStatus.SEARCH_HEADER; final String iniDate = m_dateFormat.format(m_initialDate); 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: if (cleanLine.endsWith("qgs") && cleanLine.startsWith(iniDate)) //$NON-NLS-1$ // 19960521 00 h 1 qgs // 1 0.000 status = ChannelStatus.READ_QGS; break; case READ_QGS: // Gesamtabfluss final String[] strings = cleanLine.split(" "); //$NON-NLS-1$ return Double.valueOf(strings[1]); }/*from w w w .ja v a2 s.c o m*/ } return Double.NaN; }
From source file:com.quartzdesk.executor.common.db.DatabaseScriptExecutor.java
/** * Read a script from the given resource and build a String containing the lines. * * @param scriptUrl the SQL script URL to be read from. * @return {@code String} containing the script lines. * @throws IOException in case of I/O errors. */// w w w . ja v a 2 s .co m private String readScript(URL scriptUrl) throws IOException { String statementSeparatorStart = commentPrefix + ' ' + STATEMENT_SEPARATOR_START; String statementSeparatorEnd = commentPrefix + ' ' + STATEMENT_SEPARATOR_END; LineNumberReader lnr = new LineNumberReader( new InputStreamReader(scriptUrl.openStream(), sqlScriptEncoding)); try { String currentStatement = lnr.readLine(); StringBuilder scriptBuilder = new StringBuilder(); while (currentStatement != null) { if (StringUtils.isNotBlank(currentStatement)) { if (commentPrefix != null && !currentStatement.startsWith(commentPrefix)) { if (scriptBuilder.length() > 0) { scriptBuilder.append('\n'); } scriptBuilder.append(currentStatement); } if (commentPrefix != null && (currentStatement.startsWith(statementSeparatorStart) || currentStatement.startsWith(statementSeparatorEnd))) { if (scriptBuilder.length() > 0) { scriptBuilder.append('\n'); } scriptBuilder.append(currentStatement); } } currentStatement = lnr.readLine(); } maybeAddSeparatorToScript(scriptBuilder); return scriptBuilder.toString(); } finally { IOUtils.close(lnr); } }
From source file:org.pentaho.platform.dataaccess.datasource.wizard.csv.CsvUtils.java
protected List<String> getLinesList(String fileLocation, int rows, String encoding) throws IOException { List<String> lines = new ArrayList<String>(); try {/*w w w.jav a 2 s. co m*/ File file = new File(fileLocation); FileInputStream fis = new FileInputStream(file); InputStreamReader isr = new InputStreamReader(fis, encoding); LineNumberReader reader = new LineNumberReader(isr); String line; int lineNumber = 0; while ((line = reader.readLine()) != null && lineNumber < rows) { lines.add(line); lineNumber++; } reader.close(); } catch (Exception e) { log.equals(e); } return lines; }
From source file:com.l2jfree.gameserver.model.L2Manor.java
private void parseData() { LineNumberReader lnr = null; try {//from w w w .java 2 s. c om 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.marketcetera.strategyagent.StrategyAgent.java
/** * Parses the commands from the supplied commands file. * * @param inFile the file path/* w w w . j ava2 s . c o m*/ * * @throws IOException if there were errors parsing the file. * * @return the number of errors encountered when parsing the command file. */ private int parseCommands(String inFile) throws IOException { int numErrors = 0; LineNumberReader reader = new LineNumberReader(new UnicodeFileReader(inFile)); try { String line; while ((line = reader.readLine()) != null) { if (line.startsWith("#") || line.trim().isEmpty()) { //$NON-NLS-1$ //Ignore comments and empty lines. continue; } int idx = line.indexOf(';'); //$NON-NLS-1$ if (idx > 0) { String key = line.substring(0, idx); CommandRunner runner = sRunners.get(key); if (runner == null) { numErrors++; Messages.INVALID_COMMAND_NAME.error(this, key, reader.getLineNumber()); continue; } mCommands.add(new Command(runner, line.substring(++idx), reader.getLineNumber())); } else { numErrors++; Messages.INVALID_COMMAND_SYNTAX.error(this, line, reader.getLineNumber()); } } return numErrors; } finally { reader.close(); } }
From source file:com.ggvaidya.scinames.ui.DatasetImporterController.java
private void displayPreview() { filePreviewTextArea.setText(""); if (currentFile == null) return;/* www . j a v a2 s .c o m*/ if (currentFile.getName().endsWith("xls") || currentFile.getName().endsWith("xlsx")) { // Excel files are special! We need to load it special and then preview it. ExcelImporter imp; String excelPreviewText; try { imp = new ExcelImporter(currentFile); List<Sheet> sheets = imp.getWorksheets(); StringBuffer preview = new StringBuffer(); preview.append("Excel file version " + imp.getWorkbook().getSpreadsheetVersion() + " containing " + sheets.size() + " sheets.\n"); for (Sheet sh : sheets) { preview.append( " - " + sh.getSheetName() + " contains " + sh.getPhysicalNumberOfRows() + " rows.\n"); // No rows? if (sh.getPhysicalNumberOfRows() == 0) continue; // Header row? Row headerRow = sh.getRow(0); boolean headerEmitted = false; for (int rowIndex = 1; rowIndex < sh.getPhysicalNumberOfRows(); rowIndex++) { if (rowIndex >= 10) break; Row row = sh.getRow(rowIndex); if (!headerEmitted) { preview.append( " - " + String.join("\t", ExcelImporter.getCellsAsValues(headerRow)) + "\n"); headerEmitted = true; } preview.append(" - " + String.join("\t", ExcelImporter.getCellsAsValues(row)) + "\n"); } preview.append("\n"); } excelPreviewText = preview.toString(); } catch (IOException ex) { excelPreviewText = "Could not open '" + currentFile + "': " + ex; } filePreviewTextArea.setText(excelPreviewText); return; } // If we're here, then this is some sort of text file, so let's preview the text content directly. try { LineNumberReader reader = new LineNumberReader(new BufferedReader(new FileReader(currentFile))); // Load the first ten lines. StringBuffer head = new StringBuffer(); for (int x = 0; x < 10; x++) { head.append(reader.readLine()); head.append('\n'); } reader.close(); filePreviewTextArea.setText(head.toString()); } catch (IOException ex) { filePreviewTextArea.setBackground(BACKGROUND_RED); filePreviewTextArea.setText("ERROR: Could not load file '" + currentFile + "': " + ex); } }
From source file:org.mitre.xcoord.TestScript.java
/** * This will accomodate any test file that has at least the following style: * * FAMILY-XXX COORDINATE TEXT "FAIL"/* www . j a v a2 s. c om*/ * * Where the first FAMILY token is * * @param coordfile */ public void fileTestByLines(String coordfile) { xcoord.match_UTM(true); xcoord.match_MGRS(true); xcoord.match_DD(true); xcoord.match_DMS(true); xcoord.match_DM(true); try { String _file = coordfile.trim(); String fname = FilenameUtils.getBaseName(_file); TestUtility tester = new TestUtility("./results/xcoord_" + fname + "-lines.csv"); java.io.LineNumberReader in = FileUtility.getLineReader(coordfile); String line = null; while ((line = in.readLine()) != null) { String text = line.trim(); if (text.startsWith("#")) { continue; } if (text.isEmpty()) { continue; } String fam = find_family(line); int famx = XConstants.get_CCE_family(fam); if (famx == XConstants.UNK_PATTERN) { log.error("Unknown test pattern TEXT=" + text); continue; } TestCase tst = new TestCase("#" + in.getLineNumber(), fam, text); TextMatchResultSet results = xcoord.extract_coordinates(tst.text, tst.id); /** * tst.family_id */ results.add_trace("Test Payload: " + tst.text); if (!results.evaluated) { continue; } log.info("=========FILE TEST " + tst.id + " FOUND:" + (results.matches.isEmpty() ? "NOTHING" : results.matches.size())); tester.save_result(tst, results); } tester.close_report(); log.info("=== FILE TESTS DONE ==="); } catch (Exception err) { log.error("TEST BY LINES", err); } }
From source file:io.fabric8.ConnectorMojo.java
private List<String> loadFile(File file) throws Exception { List<String> lines = new ArrayList<>(); LineNumberReader reader = new LineNumberReader(new FileReader(file)); String line;/*w w w . j av a 2s. c om*/ do { line = reader.readLine(); if (line != null) { lines.add(line); } } while (line != null); reader.close(); return lines; }
From source file:com.pactera.edg.am.metamanager.extractor.adapter.extract.db.impl.DbFromFileExtractServiceImpl.java
private Catalog getCatalog(InputStream input) { LineNumberReader br = new LineNumberReader(new InputStreamReader(input)); boolean isTable = false, isColumn = false, isProcedure = false, isTrigger = false; String line;// w w w . j a va 2 s.c om try { while ((line = br.readLine()) != null) { if (line.startsWith(TABLE_FLAG)) { // isTable = true; isColumn = false; isProcedure = false; isTrigger = false; // continue; } else if (line.startsWith(COLUMN_FLAG)) { // isColumn = true; isTable = false; isProcedure = false; isTrigger = false; // continue; } else if (line.startsWith(PROCEDURE_FLAG)) { // isProcedure = true; isTable = false; isColumn = false; isTrigger = false; // continue; } else if (line.startsWith(TRIGGER_FLAG)) { // ? isTrigger = true; isTable = false; isColumn = false; isProcedure = false; // continue; } if (isColumn) { // ?COLUMN-->??, genColumn(line); } else if (isTable) { // ?TABLEVIEW genTable(line); } else if (isProcedure) { // ?PROCEUDRE genProcedure(line); } else if (isTrigger) { // ?TRIGGER genTrigger(line); } } return genCatalog(); } catch (IOException e) { e.printStackTrace(); } finally { // ? if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } schemaCache.clear(); columnSetCache.clear(); } return null; }
From source file:org.beanfuse.struts2.action.EntityDrivenAction.java
/** * // www . j a v a 2s . c o m * * @param upload * @param clazz * @return */ protected EntityImporter buildEntityImporter(String upload, Class clazz) { try { File[] files = (File[]) ActionContext.getContext().getParameters().get(upload); if (files == null || files.length < 1) { logger.error("cannot get {} file.", upload); } String fileName = get(upload + "FileName"); InputStream is = new FileInputStream(files[0]); if (fileName.endsWith(".xls")) { HSSFWorkbook wb = new HSSFWorkbook(is); if (wb.getNumberOfSheets() < 1 || wb.getSheetAt(0).getLastRowNum() == 0) { return null; } EntityImporter importer = (clazz == null) ? new DefaultEntityImporter() : new DefaultEntityImporter(clazz); importer.setReader(new ExcelItemReader(wb, 1)); put("importer", importer); return importer; } else { LineNumberReader reader = new LineNumberReader(new InputStreamReader(is)); if (null == reader.readLine()) return null; reader.reset(); EntityImporter importer = (clazz == null) ? new DefaultEntityImporter() : new DefaultEntityImporter(clazz); importer.setReader(new CSVReader(reader)); return importer; } } catch (Exception e) { logger.error("error", e); return null; } }