List of usage examples for java.io LineNumberReader getLineNumber
public int getLineNumber()
From source file:nl.uva.illc.dataselection.InvitationModel.java
public static void readFiles() throws IOException, InterruptedException { log.info("Reading files"); src_codes = HashObjIntMaps.newMutableMap(); trg_codes = HashObjIntMaps.newMutableMap(); src_codes.put(null, 0);//from ww w . j a v a 2s . c o m trg_codes.put(null, 0); LineNumberReader lr = new LineNumberReader(new FileReader(IN + "." + SRC)); lr.skip(Long.MAX_VALUE); int indomain_size = lr.getLineNumber(); lr.close(); lr = new LineNumberReader(new FileReader(MIX + "." + SRC)); lr.skip(Long.MAX_VALUE); int mixdomain_size = lr.getLineNumber(); lr.close(); src_indomain = new int[indomain_size][]; trg_indomain = new int[indomain_size][]; src_mixdomain = new int[mixdomain_size][]; trg_mixdomain = new int[mixdomain_size][]; latch = new CountDownLatch(2); readFile(IN + "." + SRC, src_codes, src_indomain); readFile(IN + "." + TRG, trg_codes, trg_indomain); latch.await(); latch = new CountDownLatch(2); readFile(MIX + "." + SRC, src_codes, src_mixdomain); readFile(MIX + "." + TRG, trg_codes, trg_mixdomain); latch.await(); }
From source file:org.kalypso.commons.runtime.LogAnalyzer.java
/** * Reads a log file into an array of (multi-)statuses. * <p>/*from w w w.java2s . c o m*/ * The log file is parsed as follows: * <ul> * <li>All lines formatted as a log-message are parsed into a list of status object. (See {@link LoggerUtilities})</li> * <li>All statuses between two messages with code {@link LoggerUtilities#CODE_NEW_MSGBOX}go into a separate * MultiStatus.</li> * <li>Only messages with a code unequal to {@link LoggerUtilities#CODE_NONE}are considered.</li> * <li>The message text of each multi-status will be composed of all its statuses with code * {@link LoggerUtilities#CODE_SHOW_MSGBOX}</li> * </ul> * * @return The resulting stati. If problems are encountered while reading the file, instead an error status describing * the io-problems is returned. */ public static IStatus[] logfileToStatus(final File file, final String charset) { InputStream inputStream = null; LineNumberReader lnr = null; try { inputStream = new FileInputStream(file); lnr = new LineNumberReader(new InputStreamReader(inputStream, charset)); final IStatus[] result = readerToStatus(lnr); lnr.close(); return result; } catch (final Throwable t) { final StringBuffer msg = new StringBuffer( Messages.getString("org.kalypso.commons.runtime.LogAnalyzer.0")); //$NON-NLS-1$ if (lnr != null) { msg.append(Messages.getString("org.kalypso.commons.runtime.LogAnalyzer.1")); //$NON-NLS-1$ msg.append(lnr.getLineNumber()); } msg.append(Messages.getString("org.kalypso.commons.runtime.LogAnalyzer.2")); //$NON-NLS-1$ msg.append(file.getAbsolutePath()); final IStatus status = new Status(IStatus.ERROR, KalypsoCommonsPlugin.getID(), LoggerUtilities.CODE_SHOW_MSGBOX, msg.toString(), t); return new IStatus[] { status }; } finally { IOUtils.closeQuietly(inputStream); } }
From source file:org.kalypso.wspwin.core.WspWinZustand.java
private static ZustandSegmentBean[] readZustandSegments(final LineNumberReader reader, final int segmentCount, final String filename) throws ParseException, IOException { final List<ZustandSegmentBean> beans = new ArrayList<>(20); int readSegments = 0; while (reader.ready()) { final String line = reader.readLine(); /* Skip empty lines; we have WspWin projects with and without a separating empty line */ if (StringUtils.isBlank(line)) continue; final StringTokenizer tokenizer = new StringTokenizer(line); if (tokenizer.countTokens() != 7) throw new ParseException(Messages.getString("org.kalypso.wspwin.core.WspWinZustand.2", filename, //$NON-NLS-1$ reader.getLineNumber()), reader.getLineNumber()); try {// w ww . jav a 2 s. c om final BigDecimal stationFrom = new BigDecimal(tokenizer.nextToken()); final BigDecimal stationTo = new BigDecimal(tokenizer.nextToken()); final double distanceVL = Double.parseDouble(tokenizer.nextToken()); final double distanceHF = Double.parseDouble(tokenizer.nextToken()); final double distanceVR = Double.parseDouble(tokenizer.nextToken()); final String fileNameFrom = tokenizer.nextToken(); final String fileNameTo = tokenizer.nextToken(); final ZustandSegmentBean bean = new ZustandSegmentBean(stationFrom, stationTo, fileNameFrom, fileNameTo, distanceVL, distanceHF, distanceVR); beans.add(bean); readSegments++; } catch (final NumberFormatException e) { e.printStackTrace(); throw new ParseException(Messages.getString("org.kalypso.wspwin.core.WspWinZustand.3", filename, //$NON-NLS-1$ reader.getLineNumber()), reader.getLineNumber()); } } if (readSegments != segmentCount) throw new ParseException( Messages.getString("org.kalypso.wspwin.core.WspWinZustand.1", filename, reader.getLineNumber()), //$NON-NLS-1$ reader.getLineNumber()); return beans.toArray(new ZustandSegmentBean[beans.size()]); }
From source file:com.codecrate.shard.transfer.pcgen.PcgenObjectImporter.java
private int getNumberOfFileLines(File file) { int lines = 0; try {// ww w . j a v a2s. co m long lastByte = file.length(); LineNumberReader lineRead = new LineNumberReader(new FileReader(file)); lineRead.skip(lastByte); lines = lineRead.getLineNumber() - 1; lineRead.close(); } catch (IOException e) { LOG.warn("Error counting the number of lines in file: " + file, e); } return lines; }
From source file:com.l2jfree.tools.GPLLicenseChecker.java
private static List<String> read(File f) throws IOException { final List<String> list = new ArrayList<String>(); LineNumberReader lnr = null; try {/*from ww w .j a v a2 s.c om*/ lnr = new LineNumberReader(new FileReader(f)); for (String line; (line = lnr.readLine()) != null;) list.add(line); } finally { IOUtils.closeQuietly(lnr); } // to skip the script classes for (String line : list) if (line.startsWith("package com.sun.script.")) return null; int ln = 0; if (!CLEARED) { for (int j = 0; j < CONFIDENTIAL.length; j++, ln++) { if (!list.get(j).equals(CONFIDENTIAL[j])) { MODIFIED.add(f.getPath() + ":" + ln); return list; } } } for (int j = 0; j < LICENSE.length; j++, ln++) { if (!list.get(ln).equals(LICENSE[j])) { MODIFIED.add(f.getPath() + ":LI" + ln); return list; } } if (!startsWithPackageName(list.get(ln))) { MODIFIED.add(f.getPath() + ":" + lnr.getLineNumber()); return list; } return list; }
From source file:eu.eexcess.diversityasurement.wikipedia.RDFCategoryExtractor.java
private long getTotalNumberOfLines(File file) throws FileNotFoundException, IOException { long lines = 0; LineNumberReader lineNumberReader = new LineNumberReader(new FileReader(file)); lineNumberReader.skip(Long.MAX_VALUE); lines = lineNumberReader.getLineNumber(); lineNumberReader.close();/*from w w w .j a va 2 s . c om*/ return lines; }
From source file:org.apache.streams.rss.test.RssStreamProviderIT.java
@Test public void testRssStreamProvider() throws Exception { final String configfile = "./target/test-classes/RssStreamProviderIT.conf"; final String outfile = "./target/test-classes/RssStreamProviderIT.stdout.txt"; InputStream is = RssStreamProviderIT.class.getResourceAsStream("/top100.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); RssStreamConfiguration configuration = new RssStreamConfiguration(); List<FeedDetails> feedArray = new ArrayList<>(); try {//from w ww.j a va 2 s. c om while (br.ready()) { String line = br.readLine(); if (!StringUtils.isEmpty(line)) { feedArray.add(new FeedDetails().withUrl(line).withPollIntervalMillis(5000L)); } } configuration.setFeeds(feedArray); } catch (Exception ex) { ex.printStackTrace(); Assert.fail(); } org.junit.Assert.assertThat(configuration.getFeeds().size(), greaterThan(70)); OutputStream os = new FileOutputStream(configfile); OutputStreamWriter osw = new OutputStreamWriter(os); BufferedWriter bw = new BufferedWriter(osw); // write conf ObjectNode feedsNode = mapper.convertValue(configuration, ObjectNode.class); JsonNode configNode = mapper.createObjectNode().set("rss", feedsNode); bw.write(mapper.writeValueAsString(configNode)); bw.flush(); bw.close(); File config = new File(configfile); assert (config.exists()); assert (config.canRead()); assert (config.isFile()); RssStreamProvider.main(new String[] { configfile, outfile }); File out = new File(outfile); assert (out.exists()); assert (out.canRead()); assert (out.isFile()); FileReader outReader = new FileReader(out); LineNumberReader outCounter = new LineNumberReader(outReader); while (outCounter.readLine() != null) { } assert (outCounter.getLineNumber() >= 200); }
From source file:org.openmrs.module.initializer.AddressHierarchyMessagesLoadingTest.java
@Test @Verifies(value = "should load i18n messages specific to the address hierarchy configuration", method = "refreshCache()") public void refreshCache_shouldLoadAddressHierarchyMessages() throws IOException { // Replay/* w w w . ja v a 2 s. com*/ inizSrc.refreshCache(); AddressConfigurationLoader.loadAddressConfiguration(); AddressHierarchyService ahs = Context.getService(AddressHierarchyService.class); ahs.initI18nCache(); InitializerService iniz = Context.getService(InitializerService.class); File csvFile = (new ConfigDirUtil(iniz.getConfigDirPath(), iniz.getChecksumsDirPath(), iniz.getRejectionsDirPath(), InitializerConstants.DOMAIN_ADDR)) .getConfigFile("addresshierarchy.csv"); LineNumberReader lnr = new LineNumberReader(new FileReader(csvFile)); lnr.skip(Long.MAX_VALUE); int csvLineCount = lnr.getLineNumber() + 1; lnr.close(); Assert.assertTrue(csvLineCount < ahs.getAddressHierarchyEntryCount()); // there should be more entries than the // number of lines in CSV import // Working in km_KH Context.getUserContext().setLocale(new Locale("km", "KH")); PersonAddress address = new PersonAddress(); address.setStateProvince(""); address.setCountyDistrict(""); address.setAddress1("??"); // Looking for possible villages based on an address provided in km_KH AddressHierarchyLevel villageLevel = ahs.getAddressHierarchyLevelByAddressField(AddressField.CITY_VILLAGE); List<AddressHierarchyEntry> villageEntries = ahs.getPossibleAddressHierarchyEntries(address, villageLevel); Assert.assertFalse(CollectionUtils.isEmpty(villageEntries)); // Verifying that possible villages are provided as i18n message codes final Set<String> expectedVillageNames = new HashSet<String>(); // filled by looking at the test CSV expectedVillageNames.add("addresshierarchy.tangTonle"); expectedVillageNames.add("addresshierarchy.rumloung"); expectedVillageNames.add("addresshierarchy.thlokChheuTeal"); expectedVillageNames.add("addresshierarchy.trachChrum"); expectedVillageNames.add("addresshierarchy.paelHael"); expectedVillageNames.add("addresshierarchy.krangPhka"); expectedVillageNames.add("addresshierarchy.runloungPrakhleah"); expectedVillageNames.add("addresshierarchy.preyKanteach"); expectedVillageNames.add("addresshierarchy.snaoTiPir"); expectedVillageNames.add("addresshierarchy.roleangSangkae"); for (AddressHierarchyEntry entry : villageEntries) { Assert.assertTrue(expectedVillageNames.contains(entry.getName())); } // Pinpointing a specific village address.setCityVillage(""); // Looking for possible villages villageEntries = ahs.getPossibleAddressHierarchyEntries(address, villageLevel); // We should find our one village Assert.assertEquals(1, villageEntries.size()); String messageKey = villageEntries.get(0).getName(); Assert.assertEquals(messageKey, "addresshierarchy.paelHael"); Assert.assertEquals(Context.getMessageSourceService().getMessage(messageKey), ""); }
From source file:de.langmi.spring.batch.examples.complex.file.split.GetLineCountTasklet.java
/** * Short variant to get the line count of the file, there can be problems with files where * the last line has no content./* w ww. j a va2s .co m*/ * * @param file * @param chunkContext * @return the line count * @throws IOException * @throws FileNotFoundException */ private int getLineCount(File file) throws IOException, FileNotFoundException { LineNumberReader lnr = null; try { lnr = new LineNumberReader(new FileReader(file)); String line = null; int count = 0; while ((line = lnr.readLine()) != null) { count = lnr.getLineNumber(); } return count; } finally { if (lnr != null) { lnr.close(); } } }
From source file:org.apache.wookie.util.WidgetJavascriptSyntaxAnalyzer.java
/** * Find occurrences of incompatible setter syntax for Internet explorer * i.e. Widget.preferences.foo=bar;/*w w w.j a va 2s.c o m*/ * * @throws IOException */ private void parseIEIncompatibilities() throws IOException { // Pattern match on the syntax 'widget.preferemces.name=value' - including optional quotes & spaces around the value Pattern pattern = Pattern.compile("widget.preferences.\\w+\\s*=\\s*\\\"??\\'??.+\\\"??\\'??", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(""); // Search .js files, but also any html files Iterator<?> iter = FileUtils.iterateFiles(_searchFolder, new String[] { "js", "htm", "html" }, true); while (iter.hasNext()) { File file = (File) iter.next(); LineNumberReader lineReader = new LineNumberReader(new FileReader(file)); String line = null; while ((line = lineReader.readLine()) != null) { matcher.reset(line); if (matcher.find()) { String message = "\n(Line " + lineReader.getLineNumber() + ") in file " + file; message += "\n\t " + line + "\n"; message += "This file contains preference setter syntax which may not behave correctly in Internet Explorer version 8 and below.\n"; message += "See https://cwiki.apache.org/confluence/display/WOOKIE/FAQ#FAQ-ie8prefs for more information.\n"; FlashMessage.getInstance().message(formatWebMessage(message)); _logger.warn(message); } } } }