List of usage examples for java.io LineNumberReader LineNumberReader
public LineNumberReader(Reader in)
From source file:org.lenskit.eval.temporal.TemporalEvaluatorTest.java
/** * Test that we can run it, and it produces enough data. *//*from w w w . j av a 2s . c o m*/ @Test public void ExecuteTest() throws IOException, RecommenderBuildException { tempEval.execute(); assertTrue(predictOutputFile.isFile()); try (FileReader reader = new FileReader(predictOutputFile)) { try (LineNumberReader lnr = new LineNumberReader(reader)) { lnr.skip(Long.MAX_VALUE); int lines = lnr.getLineNumber(); assertThat(lines, equalTo(RATING_COUNT + 1)); } } }
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//from w w w . ja v a 2 s .co m 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:net.sourceforge.pmd.lang.java.rule.strings.AvoidDuplicateLiteralsRule.java
private LineNumberReader getLineReader() throws FileNotFoundException { return new LineNumberReader(new BufferedReader(new FileReader(getProperty(EXCEPTION_FILE_DESCRIPTOR)))); }
From source file:org.kalypso.wspwin.core.WspWinProfProj.java
/** * Reads the file profproj.txt/*from w w w. j av a 2 s .c om*/ */ public void read(final File wspwinDir) throws IOException, ParseException { final WspWinProject wspWinProject = new WspWinProject(wspwinDir); final File profprojFile = wspWinProject.getProfProjFile(); try (LineNumberReader reader = new LineNumberReader(new FileReader(profprojFile));) { final int[] counts = readStrHeader(reader); final int profilCount = counts[0]; final int relationCount = counts[1]; if (relationCount == 0) { // ignore for now; later we may do sanity checks, if there are unused profiles } final ProfileBean[] profiles = ProfileBean.readProfiles(reader, profilCount); m_profiles.addAll(Arrays.asList(profiles)); } catch (final ParseException pe) { final String msg = Messages.getString("org.kalypso.wspwin.core.WspCfg.6") //$NON-NLS-1$ + profprojFile.getAbsolutePath() + " \n" + pe.getLocalizedMessage(); //$NON-NLS-1$ final ParseException newPe = new ParseException(msg, pe.getErrorOffset()); newPe.setStackTrace(pe.getStackTrace()); throw newPe; } }
From source file:de.ks.flatadocdb.defaults.DefaultEntityPersister.java
@Override public boolean canParse(Path path, EntityDescriptor descriptor) { if (path.toFile().exists()) { try (FileInputStream stream = new FileInputStream(path.toFile())) { try (LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream))) { String line1 = reader.readLine(); String line2 = reader.readLine(); line1 = line1 == null ? "" : line1.trim(); line2 = line2 == null ? "" : line2.trim(); boolean valid = checkLine(line1, line2, descriptor.getEntityClass()); if (valid) { log.debug("Found valid file {} to parse as {}", path, descriptor.getEntityClass().getSimpleName()); }// w ww . jav a2 s . co m return valid; } } catch (IOException e) { log.debug("Unable to parse {} as {}", path, descriptor.getEntityClass(), e); return false; } } return false; }
From source file:org.seqdoop.hadoop_bam.TestVCFOutputFormat.java
@Test public void testSimple() throws Exception { VariantContextBuilder vctx_builder = new VariantContextBuilder(); ArrayList<Allele> alleles = new ArrayList<Allele>(); alleles.add(Allele.create("A", false)); alleles.add(Allele.create("C", true)); vctx_builder.alleles(alleles);/*from w w w. ja v a 2s . co m*/ GenotypesContext genotypes = GenotypesContext.NO_GENOTYPES; vctx_builder.genotypes(genotypes); HashSet<String> filters = new HashSet<String>(); vctx_builder.filters(filters); HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("NS", new Integer(4)); vctx_builder.attributes(attributes); vctx_builder.loc("20", 2, 2); vctx_builder.log10PError(-8.0); String[] expected = new String[] { "20", "2", ".", "C", "A", "80", "PASS", "NS=4" }; VariantContext ctx = vctx_builder.make(); writable.set(ctx); writer.write(1L, writable); writer.close(taskAttemptContext); LineNumberReader reader = new LineNumberReader(new FileReader(test_vcf_output)); skipHeader(reader); String[] fields = Arrays.copyOf(reader.readLine().split("\t"), expected.length); Assert.assertArrayEquals("comparing VCF single line", expected, fields); }
From source file:codingchallenge.SortableChallenge.java
private void initProductsMatcher() throws IOException, JSONException { List<Product> products = new ArrayList<Product>(); LineNumberReader lproductsReader = new LineNumberReader(productsReader); try {/*w w w . j a va2 s.c o m*/ for (String line = lproductsReader.readLine(); line != null; line = lproductsReader.readLine()) { line = line.trim(); if (line.length() == 0) { continue; } JSONTokener tokener = new JSONTokener(line); Object token = tokener.nextValue(); if (!(token instanceof JSONObject)) { throw new BadInputException("Bad product data: " + token); } JSONObject productJSON = (JSONObject) token; String name = getStringProp("product_name", productJSON); String manufacturer = getStringProp("manufacturer", productJSON); String family = getStringProp("family", productJSON); String model = getStringProp("model", productJSON); String announcedDate = getStringProp("announced-date", productJSON); products.add(new Product(name, manufacturer, family, model, announcedDate)); } } finally { lproductsReader.close(); } matcher.initProducts(products); }
From source file:com.bce.gis.io.zweidm.SmsParser.java
private void parse(final Reader reader) throws IOException { Assert.isNotNull(reader);//w w w.j a v a 2 s .c om final LineNumberReader lnReader = new LineNumberReader(reader); for (String line = lnReader.readLine(); line != null; line = lnReader.readLine()) { try { if (line.startsWith("ND")) //$NON-NLS-1$ interpreteNodeLine(line, lnReader); else if (line.startsWith("E3T")) //$NON-NLS-1$ interpreteE3TLine(line, lnReader); else if (line.startsWith("E4Q")) //$NON-NLS-1$ interpreteE4QLine(line, lnReader); } catch (final NumberFormatException e) { addStatus(lnReader, IStatus.ERROR, Messages.getString("SmsParser_2"), e.getLocalizedMessage()); //$NON-NLS-1$ } /* Abort after too many problems, */ final int maxProblemCount = 100; if (m_stati.size() > maxProblemCount) { m_stati.add(IStatus.ERROR, Messages.getString("SmsParser_3")); //$NON-NLS-1$ return; } } }
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 ww .j a v a 2 s. co m*/ 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:com.indoqa.lang.util.StringUtils.java
/** * Count the lines of the passed test. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return * ('\r'), or a carriage return followed immediately by a linefeed. * * @param content The text whose lines are to be counted. * @return The number of lines.// w ww . ja v a 2 s . co m */ public static int countLines(String content) { if (org.apache.commons.lang3.StringUtils.isEmpty(content)) { return 0; } LineNumberReader lnr = new LineNumberReader(new StringReader(content)); int count = 0; try { while (lnr.readLine() != null) { count++; } } catch (IOException ioe) { return -1; } return count; }