List of usage examples for java.io LineNumberReader getLineNumber
public int getLineNumber()
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 va2 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:com.bce.gis.io.zweidm.SmsParser.java
private void addStatus(final LineNumberReader lnReader, final int severity, final String message, final Object... args) { final String format = Messages.getString("SmsParser_8") + message; //$NON-NLS-1$ final Object[] arguments = ArrayUtils.addAll(new Object[] { lnReader.getLineNumber() }, args); final String msg = String.format(format, arguments); m_stati.add(severity, msg);//from w ww. ja v a 2 s. c o m }
From source file:com.gettextresourcebundle.GettextResourceBundle.java
/** * initialize the ResourceBundle from a PO file * /*from www .j a v a2 s . c om*/ * if * * @param reader the reader to read the contents of the PO file from */ private void init(LineNumberReader reader) { if (reader != null) { String line = null; String key = null; String value = null; try { while ((line = reader.readLine()) != null) { if (line.startsWith("#")) { LOG.trace(reader.getLineNumber() + ": Parsing PO file, comment skipped [" + line + "]"); } else if (line.trim().length() == 0) { LOG.trace(reader.getLineNumber() + ": Parsing PO file, whitespace line skipped"); } else { Matcher matcher = LINE_PATTERN.matcher(line); if (matcher.matches()) { String type = matcher.group(1); String str = matcher.group(2); if ("msgid".equals(type)) { if (key != null && value != null) { LOG.debug( "Parsing PO file, key,value pair found [" + key + " => " + value + "]"); resources.put(StringEscapeUtils.unescapeJava(key), StringEscapeUtils.unescapeJava(value)); key = null; value = null; } key = str; LOG.trace(reader.getLineNumber() + ": Parsing PO file, msgid found [" + key + "]"); } else if ("msgstr".equals(type)) { value = str; LOG.trace( reader.getLineNumber() + ": Parsing PO file, msgstr found [" + value + "]"); } else if (type == null || type.length() == 0) { if (value == null) { LOG.trace(reader.getLineNumber() + ": Parsing PO file, addition to msgid found [" + str + "]"); key += str; } else { LOG.trace(reader.getLineNumber() + ": Parsing PO file, addition to msgstr found [" + str + "]"); value += str; } } } else { LOG.error(reader.getLineNumber() + ": Parsing PO file, invalid syntax [" + line + "]"); } } } if (key != null && value != null) { LOG.debug("Parsing PO file, key,value pair found [" + key + " => " + value + "]"); resources.put(StringEscapeUtils.unescapeJava(key), StringEscapeUtils.unescapeJava(value)); key = null; value = null; } } catch (IOException e) { LOG.error("GettextResourceBundle could not be initialized", e); } } else { LOG.warn("GettextResourceBundle could not be initialized, input was null"); } LOG.info("GettextResourceBundle initialization complete, " + resources.size() + " resources loaded"); }
From source file:com.feilong.tools.ant.plugin.jpa.ParseJPATest.java
/** * Aa./*from w w w .j a v a 2 s .co m*/ * * @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:com.liferay.portal.scripting.internal.ScriptingImpl.java
protected String getErrorMessage(String script, Exception e) { StringBundler sb = new StringBundler(); sb.append(e.getMessage());/*from www.j a v a 2 s . co m*/ sb.append(StringPool.NEW_LINE); try { LineNumberReader lineNumberReader = new LineNumberReader(new UnsyncStringReader(script)); while (true) { String line = lineNumberReader.readLine(); if (line == null) { break; } sb.append("Line "); sb.append(lineNumberReader.getLineNumber()); sb.append(": "); sb.append(line); sb.append(StringPool.NEW_LINE); } } catch (IOException ioe) { sb.setIndex(0); sb.append(e.getMessage()); sb.append(StringPool.NEW_LINE); sb.append(script); } return sb.toString(); }
From source file:com.github.nlloyd.hornofmongo.action.MongoScriptAction.java
private boolean isOneLine(final String script) { LineNumberReader lnr = new LineNumberReader(new StringReader(script)); try {/*ww w . j a va 2 s . c o m*/ @SuppressWarnings("unused") int lastRead; while ((lastRead = lnr.read()) != -1) { } } catch (IOException e) { } // 0 lines just means no line terminator in the string return lnr.getLineNumber() <= 1; }
From source file:com.liferay.portal.scripting.ScriptingImpl.java
protected String getErrorMessage(String script, Exception e) { StringBundler sb = new StringBundler(); sb.append(getErrorMessage(e));// ww w .j av a2 s . c o m sb.append(StringPool.NEW_LINE); try { LineNumberReader lineNumberReader = new LineNumberReader(new UnsyncStringReader(script)); while (true) { String line = lineNumberReader.readLine(); if (line == null) { break; } sb.append("Line "); sb.append(lineNumberReader.getLineNumber()); sb.append(": "); sb.append(line); sb.append(StringPool.NEW_LINE); } } catch (IOException ioe) { sb.setIndex(0); sb.append(getErrorMessage(e)); sb.append(StringPool.NEW_LINE); sb.append(script); } return sb.toString(); }
From source file:org.kalypso.model.wspm.core.imports.ImportTrippleHelper.java
/** * Imports the profile trippel data and converts it into IProfils * /*from w w w .j a va 2 s. c o m*/ * @param trippleFile * file with profile tripples */ public static IProfile[] importTrippelData(final File trippleFile, final String separator, final String profileType, final String crs) throws CoreException { final IProfilePointPropertyProvider provider = KalypsoModelWspmCoreExtensions .getPointPropertyProviders(profileType); final IComponent rechtswert = provider.getPointProperty(IWspmPointProperties.POINT_PROPERTY_RECHTSWERT); final IComponent hochwert = provider.getPointProperty(IWspmPointProperties.POINT_PROPERTY_HOCHWERT); if (trippleFile == null) return new IProfile[0]; /* read profiles, show warnings */ final List<IProfile> profiles = new ArrayList<>(); IProfile currentProfile = null; /* file loading */ LineNumberReader fileReader = null; try (InputStreamReader inputReader = new InputStreamReader(new FileInputStream(trippleFile))) { fileReader = new LineNumberReader(inputReader); /* File Header */ fileReader.readLine(); IProfileRecord lastPoint = null; while (fileReader.ready()) { final String line = fileReader.readLine(); if (line == null) { break; } /* ignore empty lines */ if (StringUtils.isBlank(line)) { continue; } /* trippel-format should be: station, x, y, z */ final String[] tokens = StringUtils.split(line, separator); /* continue just if there are enough values in the trippel file */ if (tokens.length != 4) { // FIXME: better error handling // inform the user that his profile has not enough values... final String message = Messages.getString( "org.kalypso.model.wspm.core.imports.ImportTrippleHelper.0", //$NON-NLS-1$ fileReader.getLineNumber()); final IStatus status = new Status(IStatus.ERROR, KalypsoModelWspmCorePlugin.getID(), message); throw new CoreException(status); } try { /* first value = profile station */ final double station = NumberUtils.parseDouble(tokens[0]); final BigDecimal currentStation = ProfileUtil.stationToBigDecimal(station); final BigDecimal currentProfileStation = currentProfile == null ? null : ProfileUtil.stationToBigDecimal(currentProfile.getStation()); if (!ObjectUtils.equals(currentStation, currentProfileStation)) { lastPoint = null; currentProfile = ProfileFactory.createProfil(profileType, null); currentProfile.setStation(station); currentProfile.setName( Messages.getString("org.kalypso.model.wspm.core.imports.ImportTrippleHelper.1")); //$NON-NLS-1$ currentProfile.setDescription( Messages.getString("org.kalypso.model.wspm.core.imports.ImportTrippleHelper.2")); //$NON-NLS-1$ currentProfile.setSrsName(crs); currentProfile.addPointProperty(rechtswert); currentProfile.addPointProperty(hochwert); profiles.add(currentProfile); } final IProfileRecord point = ImportTrippleHelper.createProfilePoint(currentProfile, tokens, lastPoint); if (point != null) { currentProfile.addPoint(point); } lastPoint = point; } catch (final NumberFormatException e) { e.printStackTrace(); final String message = Messages.getString( "org.kalypso.model.wspm.core.imports.ImportTrippleHelper.3", //$NON-NLS-1$ fileReader.getLineNumber()); final IStatus status = new Status(IStatus.ERROR, KalypsoModelWspmCorePlugin.getID(), message, e); throw new CoreException(status); } } fileReader.close(); } catch (final IOException e) { e.printStackTrace(); final int lineNumber = fileReader == null ? 0 : fileReader.getLineNumber(); final String message = Messages.getString("org.kalypso.model.wspm.core.imports.ImportTrippleHelper.4", //$NON-NLS-1$ lineNumber); final IStatus status = new Status(IStatus.ERROR, KalypsoModelWspmCorePlugin.getID(), message, e); throw new CoreException(status); } return profiles.toArray(new IProfile[profiles.size()]); }
From source file:org.kalypso.model.wspm.core.profil.sobek.parser.SobekLineParser.java
public SobekLineParser(final LineNumberReader reader) throws IOException, CoreException { final String line = reader.readLine(); if (line == null) throw SobekParsing.throwError(format(Messages.getString("SobekLineParser_0"))); //$NON-NLS-1$ m_tokenizer = new StrTokenizer(line, StrMatcher.spaceMatcher(), StrMatcher.singleQuoteMatcher()); m_lineNumber = reader.getLineNumber(); }
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 {/* w w w . j a v a 2 s .c o 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); } }