List of usage examples for org.apache.commons.io FileUtils lineIterator
public static LineIterator lineIterator(File file, String encoding) throws IOException
File
. From source file:playground.staheale.preprocess.AgentInteractionEnterpriseCensusParser.java
private final void readHectareAggregations(AgentInteractionEnterpriseCensus ec) { log.info("Reading the hectare aggregation file..."); String separator = ","; String filename = inputHectareAggregationFile; File file = new File(filename); LineIterator it = null;/*from ww w. j a v a 2 s .c o m*/ String line = null; String[] tokens = null; String reli = null; int lineCounter = 0, skip = 1; try { it = FileUtils.lineIterator(file, "UTF-8"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { while (it.hasNext()) { line = it.nextLine(); tokens = line.split(separator); if (lineCounter == 0) { log.info("Processing header line..."); for (String token : tokens) { ec.addhectareAggregationNOGAType(token.replaceAll("\"", "")); } log.info("Processing header line...done."); } else { reli = tokens[0]; for (int pos = 0; pos < tokens.length; pos++) { if (!Pattern.matches("0", tokens[pos])) { ec.addHectareAggregationInformation(reli, ec.getHectareAggregationNOGAType(pos), Double.parseDouble(tokens[pos])); } } } lineCounter++; if (lineCounter % skip == 0) { log.info("Processed hectares: " + Integer.toString(lineCounter)); skip *= 2; } } } finally { LineIterator.closeQuietly(it); } log.info("Processed hectares: " + Integer.toString(lineCounter)); log.info("Reading the hectare aggregation file...done."); }
From source file:se.inera.intyg.rehabstod.integration.it.stub.PersonnummerLoaderImpl.java
@Override public List<String> readTestPersonnummer() throws IOException { Resource resource = getResource(testPersonnummerFile); LineIterator it = FileUtils.lineIterator(resource.getFile(), "UTF-8"); List<String> personnummerList = new ArrayList<>(); try {//w w w . j a va 2 s . c om // Skip CSV column name if (it.hasNext()) { it.nextLine(); } while (it.hasNext()) { String line = it.nextLine(); personnummerList.add(line); } } finally { LineIterator.closeQuietly(it); } return personnummerList; }
From source file:se.inera.intyg.rehabstod.service.diagnos.DiagnosGruppLoaderImpl.java
private List<DiagnosGrupp> getDiagnosGrupperInternal(Resource resource) throws IOException { LineIterator it = FileUtils.lineIterator(resource.getFile(), "UTF-8"); List<DiagnosGrupp> list = new ArrayList<>(); try {/*from www . j a v a 2 s.c o m*/ while (it.hasNext()) { String line = it.nextLine(); list.add(new DiagnosGrupp(line)); } } finally { LineIterator.closeQuietly(it); } return list; }
From source file:se.inera.intyg.rehabstod.service.diagnos.DiagnosKapitelLoaderImpl.java
@Override public List<DiagnosKapitel> loadDiagnosKapitel() throws IOException { LineIterator it = FileUtils.lineIterator(diagnosKapitelFile.getFile(), "UTF-8"); List<DiagnosKapitel> list = new ArrayList<>(); try {// ww w . j a va 2 s . c o m while (it.hasNext()) { String line = it.nextLine(); list.add(new DiagnosKapitel(line)); } } finally { LineIterator.closeQuietly(it); } return list; }
From source file:se.inera.intyg.rehabstod.service.diagnos.DiagnosKoderFileTest.java
private List<String> loadDiagnosFile(String fileName) throws IOException { String filePath = getClass().getClassLoader().getResource(fileName).getFile(); LineIterator it = FileUtils.lineIterator(new File(filePath), "ISO-8859-1"); List<String> koder = new ArrayList<>(); try {/*from w ww. j a v a 2 s. c o m*/ while (it.hasNext()) { String line = it.nextLine(); String kod = line.substring(0, DiagnosKod.KOD_LENGTH).trim(); koder.add(kod); } } finally { LineIterator.closeQuietly(it); } return koder; }
From source file:se.inera.intyg.rehabstod.service.diagnos.DiagnosKoderLoaderImpl.java
private Map<String, String> loadDiagnosFile(Resource resource) throws IOException { LineIterator it = FileUtils.lineIterator(resource.getFile(), "ISO-8859-1"); Map<String, String> map = new HashMap<>(); try {/* w w w .j a v a 2s. com*/ while (it.hasNext()) { String line = it.nextLine(); DiagnosKod kod = new DiagnosKod(line); if (kod.getCleanedCode() != null) { map.put(kod.getCleanedCode(), kod.getName()); } } } finally { LineIterator.closeQuietly(it); } return map; }
From source file:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java
private void showFile(final File file, final boolean addIt) { locationTextField.setText(file.getAbsolutePath()); refreshReplacements();//w w w .java2 s .c om try { StringBuilder sb = new StringBuilder(10 * 1024); sb.append("<html><head><title>" + file.getName() + "</title><style>body {font-size: 1em;}pre {margin: 0;}</style></head><body>"); String parent = file.getParent(); LineIterator lines = FileUtils.lineIterator(file, "UTF-8"); while (lines.hasNext()) { String line = StringEscapeUtils.escapeHtml4(lines.next()); sb.append("<pre>"); if (line.startsWith(LINK_LINE_START)) { String href = getFileLocation(parent, line); sb.append("<a href=\"").append(href).append("\">").append(line).append("</a>"); } else { sb.append(line); } sb.append("</pre>"); } sb.append("</body></html>"); lines.close(); sourceEditorPane.setText(sb.toString()); sourceEditorPane.setCaretPosition(0); if (addIt) { int listSize = pageList.size(); if (listSize > 0) { int pageIndex = pageList.indexOf(currentFile); if (pageIndex < listSize - 1) { for (int i = listSize - 1; i > pageIndex; i--) { pageList.remove(i); } } } pageList.add(file); } currentFile = file; updateButtons(); if (paths.containsKey(file)) { currentSelectionPath = new TreePath(paths.get(file)); documentTree.setSelectionPath(currentSelectionPath); } } catch (IOException e) { showError("Error in file handling: " + e); } }
From source file:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java
private Collection<FileWrapper> getChildren(final se.nawroth.asciidoc.browser.FileWrapper parent) { List<FileWrapper> children = new ArrayList<FileWrapper>(); String directory = parent.getParent(); LineIterator lines;/*from www. j a v a 2s . c o m*/ try { lines = FileUtils.lineIterator(parent, "UTF-8"); while (lines.hasNext()) { String line = lines.next(); if (line.startsWith(LINK_LINE_START)) { String href = getFileLocation(directory, line); FileWrapper fileWrapper = new FileWrapper(href); if (fileWrapper.exists()) { children.add(fileWrapper); } else { // System.out.println( href ); } } } } catch (IOException e) { e.printStackTrace(); } return children; }
From source file:setexpansion.util.MapUtility.java
public static void readFile(String fileName) throws IOException { File file = new File(fileName); LineIterator iterator = FileUtils.lineIterator(file, "UTF-8"); long startTime = System.currentTimeMillis(); System.out.println("Starting.."); while (iterator.hasNext()) { iterator.next();/*from www . j a v a2 s . c o m*/ } long endTime = System.currentTimeMillis(); System.out.println(endTime - startTime); }