List of usage examples for java.io LineNumberReader readLine
public String readLine() throws IOException
From source file:eu.qualimaster.coordination.profiling.SimpleParser.java
/** * Parses the control file./*from www . j a v a 2 s .c o m*/ * * @param file the file to read * @param considerImport whether imports shall be considered or ignored * @param profile the profile to be built * @return the actual data file (from {@link IProfile#getDataFile()} if not changed by imports) * @throws IOException if loading/parsing the control file fails */ private ParseResult parseControlFile(File file, boolean considerImport, IProfile profile) throws IOException { ParseResult result = new ParseResult(); List<Integer> tmpTasks = new ArrayList<Integer>(); List<Integer> tmpExecutors = new ArrayList<Integer>(); List<Integer> tmpWorkers = new ArrayList<Integer>(); result.addDataFile(profile.getDataFile()); addDataFiles(profile.getDataFile().getParentFile(), result, profile, false); if (file.exists()) { LineNumberReader reader = new LineNumberReader(new FileReader(file)); String line; do { line = reader.readLine(); if (null != line) { line = line.trim(); if (line.startsWith(IMPORT)) { if (considerImport) { handleImport(line, result, profile); } } else if (line.startsWith(PROCESSING)) { line = line.substring(PROCESSING.length()).trim(); parseList(line, TASKS, tmpTasks, INT_HELPER); parseList(line, EXECUTORS, tmpExecutors, INT_HELPER); parseList(line, WORKERS, tmpWorkers, INT_HELPER); } else if (line.startsWith(PARAMETER)) { line = line.substring(PARAMETER.length()).trim(); parseParameter(line, profile, result); } } } while (null != line); reader.close(); } result.merge(tmpTasks, tmpExecutors, tmpWorkers); return result; }
From source file:FinalProject.Employee_Login.java
private void Submit_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Submit_ButtonActionPerformed String Password = Arrays.toString(Password_Input.getPassword()); String password = Password.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\, ", ""); String username = Employee_Input.getText(); try {/*from w w w. j av a 2 s.c om*/ File user = new File("Username.txt"); File pass = new File("Password.txt"); Scanner scanner = new Scanner(user); FileReader frU = new FileReader(user); LineNumberReader u = new LineNumberReader(frU); FileReader frP = new FileReader(pass); LineNumberReader p = new LineNumberReader(frP); int linenumberU = 0; while (scanner.hasNextLine() && u.readLine() != null) { linenumberU++; String lineFromFile = scanner.nextLine(); if (lineFromFile.contains(username)) // a match! { break; } } String pssLine = (String) FileUtils.readLines(pass).get(linenumberU - 1); String usrLine = (String) FileUtils.readLines(user).get(linenumberU - 1); if (username.equals(usrLine) && password.equals(pssLine)) { this.setVisible(false); Employee_Interface f = new Employee_Interface(); f.setVisible(true); f.ID_Number.setText(usrLine + "!"); } else { Error_Message.setVisible(true); } } catch (FileNotFoundException ex) { } catch (IOException ex) { } }
From source file:org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeReader.java
public void read(final File polyFile) throws IOException { LineNumberReader reader = null; try {//from w w w.j a va2 s. c o m reader = new LineNumberReader(new FileReader(polyFile)); while (reader.ready()) { final String line = reader.readLine(); if (line == null) break; final String trimmedLine = line.trim().replaceAll(" \\(h\\)", "\\(h\\)"); //$NON-NLS-1$ //$NON-NLS-2$ final String[] tokens = trimmedLine.split(" +"); //$NON-NLS-1$ if (tokens.length < 8) continue; /* Determine if this is a good line: good lines are lines whos first token is a number */ final BigDecimal station; try { station = new BigDecimal(tokens[0]); } catch (final NumberFormatException nfe) { /* Just ignore this line */ continue; } try { final String description = tokens[1]; // final String whatIsN = tokens[2]; final char type = tokens[3].charAt(0); final int order = Integer.parseInt(tokens[4]); final double rangeMin = Double.parseDouble(tokens[5].replace('D', 'E')); final double rangeMax = Double.parseDouble(tokens[6].replace('D', 'E')); if (tokens.length < 7 + order + 1) { /* A good line but bad content. Give user a hint that something might be wrong. */ m_log.log(false, Messages.getString( "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.22"), //$NON-NLS-1$ polyFile.getName(), reader.getLineNumber()); continue; } final List<Double> coefficients = new ArrayList<>(order); for (int i = 7; i < 7 + order + 1; i++) { final double coeff = Double.parseDouble(tokens[i].replace('D', 'E')); coefficients.add(coeff); } final Double[] doubles = coefficients.toArray(new Double[coefficients.size()]); final double[] coeffDoubles = ArrayUtils.toPrimitive(doubles); final String domainId; final String rangeId = IWspmTuhhQIntervallConstants.DICT_PHENOMENON_WATERLEVEL; switch (type) { case 'Q': domainId = IWspmTuhhQIntervallConstants.DICT_PHENOMENON_RUNOFF; break; case 'A': domainId = IWspmTuhhQIntervallConstants.DICT_PHENOMENON_AREA; break; case 'a': domainId = IWspmTuhhQIntervallConstants.DICT_PHENOMENON_ALPHA; break; default: m_log.log(false, Messages.getString( "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.23"), //$NON-NLS-1$ station); continue; } /* find feature for station */ final QIntervallResult qresult = m_intervalIndex.get(station); if (qresult == null) m_log.log(false, Messages.getString( "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.24"), //$NON-NLS-1$ station, line); else { /* create new polynome */ final IPolynomial1D poly1d = qresult.createPolynomial(); poly1d.setName(description); poly1d.setDescription(description); poly1d.setCoefficients(coeffDoubles); poly1d.setRange(rangeMin, rangeMax); poly1d.setDomainPhenomenon(domainId); poly1d.setRangePhenomenon(rangeId); } } catch (final NumberFormatException nfe) { /* A good line but bad content. Give user a hint that something might be wrong. */ m_log.log(false, Messages.getString( "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.25"), //$NON-NLS-1$ polyFile.getName(), reader.getLineNumber(), nfe.getLocalizedMessage()); } catch (final Exception e) { // should never happen m_log.log(e, Messages.getString( "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.25"), //$NON-NLS-1$ polyFile.getName(), reader.getLineNumber(), e.getLocalizedMessage()); } } reader.close(); } finally { IOUtils.closeQuietly(reader); } }
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 *//* w w w . j av a 2s.co m*/ 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:org.kalypso.model.wspm.tuhh.schema.simulation.QRelationFileReader.java
public void read(final File inputFile) throws IOException { final String filename = inputFile.getName(); LineNumberReader reader = null; try {/*from w w w. j a va2s .co m*/ reader = new LineNumberReader(new FileReader(inputFile)); while (reader.ready()) { final String line = reader.readLine(); if (line == null) break; final int lineNumber = reader.getLineNumber(); readLine(line, lineNumber, filename); } reader.close(); m_qresult.setPointsObservation(m_observation); } finally { IOUtils.closeQuietly(reader); } }
From source file:com.l2jfree.gameserver.instancemanager.BoatManager.java
private final void load() { if (!Config.ALLOW_BOAT) { return;// w w w . j a v a 2 s.co m } LineNumberReader lnr = null; try { File doorData = new File(Config.DATAPACK_ROOT, "data/boat.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; L2BoatInstance boat = parseLine(line); boat.spawn(); _staticItems.put(boat.getObjectId(), boat); if (_log.isDebugEnabled()) { _log.info("Boat ID : " + boat.getObjectId()); } } } catch (FileNotFoundException e) { _log.warn("boat.csv is missing in data folder"); } catch (Exception e) { _log.warn("error while creating boat table ", e); } finally { IOUtils.closeQuietly(lnr); } }
From source file:stroom.util.StreamGrepTool.java
private void processFile(final StreamStore streamStore, final long streamId, final String match) { try {/*from w w w. j av a2 s . c o m*/ final StreamSource streamSource = streamStore.openStreamSource(streamId); if (streamSource != null) { final InputStream inputStream = streamSource.getInputStream(); // Build up 2 buffers so we can output the content either side // of // the matching line final ArrayDeque<String> preBuffer = new ArrayDeque<>(); final ArrayDeque<String> postBuffer = new ArrayDeque<>(); final LineNumberReader lineNumberReader = new LineNumberReader( new InputStreamReader(inputStream, StreamUtil.DEFAULT_CHARSET)); String aline = null; while ((aline = lineNumberReader.readLine()) != null) { String lines[] = new String[] { aline }; if (addLineBreak != null) { lines = aline.split(addLineBreak); } for (final String line : lines) { if (match == null) { System.out.println(lineNumberReader.getLineNumber() + ":" + line); } else { postBuffer.add(lineNumberReader.getLineNumber() + ":" + line); if (postBuffer.size() > 5) { final String searchLine = postBuffer.pop(); checkMatch(match, preBuffer, postBuffer, searchLine); preBuffer.add(searchLine); if (preBuffer.size() > 5) { preBuffer.pop(); } } } } } // Look at the end while (postBuffer.size() > 0) { final String searchLine = postBuffer.pop(); checkMatch(match, preBuffer, postBuffer, searchLine); preBuffer.add(searchLine); if (preBuffer.size() > 5) { preBuffer.pop(); } } inputStream.close(); streamStore.closeStreamSource(streamSource); } } catch (final Exception ex) { ex.printStackTrace(); } }
From source file:mitm.common.security.ca.handlers.comodo.CollectCustomClientCert.java
private void handleResponse(int statusCode, HttpMethod httpMethod) throws IOException { if (statusCode != HttpStatus.SC_OK) { throw new IOException("Error Collecting certificate. Message: " + httpMethod.getStatusLine()); }/* w w w .j av a 2 s . co m*/ InputStream input = httpMethod.getResponseBodyAsStream(); if (input == null) { throw new IOException("Response body is null."); } /* * we want to set a max on the number of bytes to download. We do not want a rogue server to return 1GB. */ InputStream limitInput = new SizeLimitedInputStream(input, MAX_HTTP_RESPONSE_SIZE); String response = IOUtils.toString(limitInput, CharEncoding.US_ASCII); if (logger.isDebugEnabled()) { logger.debug("Response:\r\n" + response); } LineNumberReader lineReader = new LineNumberReader(new StringReader(response)); String statusParameter = lineReader.readLine(); errorCode = CustomClientStatusCode.fromCode(statusParameter); if (errorCode.getID() < CustomClientStatusCode.SUCCESSFUL.getID()) { error = true; errorMessage = lineReader.readLine(); } else { error = false; if (errorCode == CustomClientStatusCode.CERTIFICATES_ATTACHED) { /* * The certificate is base64 encoded between -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- */ StrBuilder base64 = new StrBuilder(4096); /* * Skip -----BEGIN CERTIFICATE----- */ String line = lineReader.readLine(); if (!"-----BEGIN CERTIFICATE-----".equalsIgnoreCase(line)) { throw new IOException("-----BEGIN CERTIFICATE----- expected but got: " + line); } do { line = lineReader.readLine(); if ("-----END CERTIFICATE-----".equalsIgnoreCase(line)) { break; } if (line != null) { base64.append(line); } } while (line != null); try { byte[] decoded = Base64.decodeBase64(MiscStringUtils.toAsciiBytes(base64.toString())); Collection<X509Certificate> certificates = CertificateUtils .readX509Certificates(new ByteArrayInputStream(decoded)); if (certificates != null && certificates.size() > 0) { certificate = certificates.iterator().next(); } } catch (CertificateException e) { throw new IOException(e); } catch (NoSuchProviderException e) { throw new IOException(e); } } } }
From source file:org.apache.cocoon.generation.TextGenerator.java
/** * Generate XML data./*from w w w.j av a 2 s . co m*/ * * @throws IOException * @throws ProcessingException * @throws SAXException */ public void generate() throws IOException, SAXException, ProcessingException { InputStreamReader in = null; try { final InputStream sis = this.inputSource.getInputStream(); if (sis == null) { throw new ProcessingException("Source '" + this.inputSource.getURI() + "' not found"); } if (encoding != null) { in = new InputStreamReader(sis, encoding); } else { in = new InputStreamReader(sis); } } catch (SourceException se) { throw new ProcessingException("Error during resolving of '" + this.source + "'.", se); } LocatorImpl locator = new LocatorImpl(); locator.setSystemId(this.inputSource.getURI()); locator.setLineNumber(1); locator.setColumnNumber(1); contentHandler.setDocumentLocator(locator); contentHandler.startDocument(); contentHandler.startPrefixMapping("", URI); AttributesImpl atts = new AttributesImpl(); if (localizable) { atts.addAttribute("", "source", "source", "CDATA", locator.getSystemId()); atts.addAttribute("", "line", "line", "CDATA", String.valueOf(locator.getLineNumber())); atts.addAttribute("", "column", "column", "CDATA", String.valueOf(locator.getColumnNumber())); } contentHandler.startElement(URI, "text", "text", atts); LineNumberReader reader = new LineNumberReader(in); String line; String newline = null; while (true) { if (newline == null) { line = convertNonXmlChars(reader.readLine()); } else { line = newline; } if (line == null) { break; } newline = convertNonXmlChars(reader.readLine()); if (newline != null) { line += SystemUtils.LINE_SEPARATOR; } locator.setLineNumber(reader.getLineNumber()); locator.setColumnNumber(1); contentHandler.characters(line.toCharArray(), 0, line.length()); if (newline == null) { break; } } reader.close(); contentHandler.endElement(URI, "text", "text"); contentHandler.endPrefixMapping(""); contentHandler.endDocument(); }
From source file:org.kalypso.model.wspm.tuhh.core.wspwin.prf.PrfWriter.java
private void writeComment() { final String comment = m_profil.getComment(); final DataBlockHeader dbh = PrfHeaders.createHeader(IWspmPointProperties.POINT_PROPERTY_COMMENT); //$NON-NLS-1$ final TextDataBlock db = new TextDataBlock(dbh); final StringReader stringReader = new StringReader(comment); final LineNumberReader lineNumberReader = new LineNumberReader(stringReader); try {// ww w . j av a2 s . c o m for (String line = lineNumberReader.readLine(); line != null; line = lineNumberReader.readLine()) { db.addLine("CC " + line); //$NON-NLS-1$ } if (db.getCoordCount() > 0) { db.setThirdLine("0 0 0 0 0 0 0 " + Integer.toString(db.getCoordCount()) + " " //$NON-NLS-1$//$NON-NLS-2$ + IWspWinConstants.SPEZIALPROFIL_COMMENT); m_dbWriter.addDataBlock(db); } } catch (final IOException e) { KalypsoCommonsPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, KalypsoCommonsPlugin.getID(), 0, Messages.getString("org.kalypso.model.wspm.tuhh.core.wspwin.prf.PrfSink.8"), e)); //$NON-NLS-1$ } }