List of usage examples for org.apache.commons.io LineIterator hasNext
public boolean hasNext()
Reader
has more lines. From source file:nl.knaw.huygens.timbuctoo.tools.importer.neww.WomenWritersImporter.java
private int importPersons(Set<String> collaboratorIds) throws Exception { int initialSize = references.size(); ckccMap = ckccConcordance();//from www . ja v a 2 s. c o m LineIterator iterator = getLineIterator("persons.json"); String line = ""; try { while (iterator.hasNext()) { line = preprocessJson(iterator.nextLine()); if (!line.isEmpty()) { handlePerson(preprocessPerson(line), collaboratorIds); } } } catch (JsonMappingException e) { System.out.println(line); throw e; } finally { LineIterator.closeQuietly(iterator); } for (String type : types) { System.out.printf("type %s%n", type); } lines.clear(); return references.size() - initialSize; }
From source file:nl.knaw.huygens.timbuctoo.tools.importer.neww.WomenWritersImporter.java
private Set<String> collectCollaborators() throws Exception { Set<String> ids = Sets.newHashSet(); LineIterator iterator = getLineIterator("relations.json"); String line = ""; try {/*from w w w . j ava 2 s . co m*/ while (iterator.hasNext()) { line = preprocessJson(iterator.nextLine()); if (!line.isEmpty()) { XRelation object = objectMapper.readValue(line, XRelation.class); String relationType = filterField(object.relation_type); if ("collaborated_with".equals(relationType)) { String leftObject = verifyNonEmptyField(line, "leftObject", filterField(object.leftObject)); String leftId = verifyNonEmptyField(line, "leftId", filterField(object.leftId)); if ("Person".equals(leftObject)) { ids.add(leftId); } } } } } catch (Exception e) { throw e; } finally { LineIterator.closeQuietly(iterator); } return ids; }
From source file:nl.knaw.huygens.timbuctoo.tools.importer.neww.WomenWritersImporter.java
private void importRelations() throws Exception { relationTypeConcordance = getRelationTypeConcordance(); LineIterator iterator = getLineIterator("relations.json"); String line = ""; try {//from w w w .j ava2 s.c o m while (iterator.hasNext()) { line = preprocessJson(iterator.nextLine()); if (!line.isEmpty()) { handleRelation(line); } } } catch (Exception e) { System.out.println(line); throw e; } finally { LineIterator.closeQuietly(iterator); relationTypeConcordance = null; } }
From source file:nl.opengeogroep.safetymaps.server.admin.stripes.LayerActionBean.java
@Before(stages = LifecycleStage.BindingAndValidation) private void findMapfiles() { try {/* www .j a v a 2 s . c o m*/ JSONArray a = new JSONArray(); File search = Cfg.getPath("static_mapserver_searchdirs"); if (search != null) { for (File f : FileUtils.listFiles(search, new String[] { "map" }, true)) { JSONObject m = new JSONObject(); m.put("path", f.getPath().substring(search.getPath().length() + 1)); a.put(m); // Naive mapfile parser. Perhaps replace by JavaScript client-side // GetCap parsing JSONArray l = new JSONArray(); m.put("layers", l); LineIterator it = FileUtils.lineIterator(f, "US-ASCII"); try { while (it.hasNext()) { String line = it.nextLine().trim(); if (line.equals("LAYER")) { String n = it.nextLine().trim(); n = n.substring(6, n.length() - 1); l.put(n); } } } finally { it.close(); } } } mapFilesJson = a.toString(4); } catch (Exception e) { } }
From source file:nl.ru.cmbi.vase.tools.util.ToolBox.java
public static StringBuilder getStringBuilderFromFile(final String fileName) throws IOException { // int STRINGBUILDER_SIZE = 403228383; // big! File file = new File(fileName); LineIterator it = FileUtils.lineIterator(file); StringBuilder sb = new StringBuilder(); // STRINGBUILDER_SIZE while (it.hasNext()) { sb.append(it.nextLine());// w w w . j a va 2 s. c om sb.append("\n"); } it.close(); return sb; }
From source file:org.adf.emg.sonar.ojaudit.JavaMetricsDecorator.java
@Override public void decorate(Resource resource, DecoratorContext context) { if (!(Qualifiers.isFile(resource) && resource.getName().endsWith(".java"))) { // only process .java files return;//w w w .j av a 2 s.c om } ProjectFileSystem fileSystem = context.getProject().getFileSystem(); File file = lookup(resource, fileSystem); LineIterator iterator = null; int numLines = 0; int numBlankLines = 0; int numCommentLines = 0; try { Charset charset = fileSystem.getSourceCharset(); iterator = charset == null ? FileUtils.lineIterator(file) : FileUtils.lineIterator(file, charset.name()); boolean inComment = false; while (iterator.hasNext()) { String trimmedLine = iterator.nextLine().trim(); numLines++; boolean lineHasCode = false; boolean lineHasComment = false; while (!trimmedLine.isEmpty()) { if (inComment) { // in a comment. try to find end marker int endIndex = trimmedLine.indexOf(END_COMMENT); if (endIndex == -1) { // (rest of) line is comment lineHasComment = true; trimmedLine = ""; // remove comment } else { // remove comment to see if there is code after it lineHasComment = true; trimmedLine = trimmedLine.substring(endIndex + END_COMMENT.length()); inComment = false; } } else { // not in a comment if (trimmedLine.startsWith("//")) { trimmedLine = ""; continue; } // try to find begin comment marker int startIndex = trimmedLine.indexOf(START_COMMENT); if (startIndex == -1) { // (rest of) line is non-comment lineHasCode = true; trimmedLine = ""; // remove non-comment } else if (startIndex == 0) { // line starts with start marker inComment = true; trimmedLine = trimmedLine.substring(startIndex + START_COMMENT.length()); } else { // line contains start marker lineHasCode = true; inComment = true; trimmedLine = trimmedLine.substring(startIndex + START_COMMENT.length()); } } trimmedLine = trimmedLine.trim(); } if (!lineHasCode) { if (lineHasComment) { numCommentLines++; } else { numBlankLines++; } } } } catch (IOException e) { LOG.warn("error reading " + file + " to collect metrics", e); } finally { LineIterator.closeQuietly(iterator); } context.saveMeasure(CoreMetrics.LINES, (double) numLines); // Lines context.saveMeasure(CoreMetrics.COMMENT_LINES, (double) numCommentLines); // Non Commenting Lines of Code context.saveMeasure(CoreMetrics.NCLOC, (double) numLines - numBlankLines - numCommentLines); // Comment Lines }
From source file:org.adf.emg.sonar.ojaudit.XmlMetricsDecorator.java
@Override public void decorate(Resource resource, DecoratorContext context) { if (!Qualifiers.isFile(resource)) { return;//from w w w . java 2 s .c o m } ProjectFileSystem fileSystem = context.getProject().getFileSystem(); File file = lookup(resource, fileSystem); try { if (readFirstByte(file) != '<') { return; } } catch (IOException e) { throw new SonarException(e); } int numCommentLines; CountCommentParser commentCounter = new CountCommentParser(); try { numCommentLines = commentCounter.countLinesOfComment(FileUtils.openInputStream(file)); if (numCommentLines == -1) { return; } } catch (IOException e) { throw new SonarException(e); } LineIterator iterator = null; int numLines = 0; int numBlankLines = 0; try { Charset charset = fileSystem.getSourceCharset(); iterator = charset == null ? FileUtils.lineIterator(file) : FileUtils.lineIterator(file, charset.name()); while (iterator.hasNext()) { String line = iterator.nextLine(); numLines++; if (line.trim().isEmpty()) { numBlankLines++; } } } catch (IOException e) { LOG.warn("error reading " + file + " to collect metrics", e); } finally { LineIterator.closeQuietly(iterator); } context.saveMeasure(CoreMetrics.LINES, (double) numLines); // Lines context.saveMeasure(CoreMetrics.COMMENT_LINES, (double) numCommentLines); // Non Commenting Lines of Code context.saveMeasure(CoreMetrics.NCLOC, (double) numLines - numBlankLines - numCommentLines); // Comment Lines }
From source file:org.aludratest.service.gitclient.GitClient.java
/** Provides the status. * @param data//from w ww. ja v a2 s .c om * @return a reference to this */ public GitClient status(StatusData data) { // clear status object for supporting data object reuse data.getUntrackedFiles().clear(); data.getUnmodifiedFiles().clear(); data.getModifiedFiles().clear(); data.getAddedFiles().clear(); data.getDeletedFiles().clear(); data.getRenamedFiles().clear(); data.getCopiedFiles().clear(); data.getUpdatedFiles().clear(); // invoke git String output = invokeGenerically(GIT_STATUS_PROCESS_NAME, true, "status", "--short", "--branch"); LineIterator iterator = new LineIterator(new StringReader(output)); while (iterator.hasNext()) { String line = iterator.next(); if (line.startsWith("##")) { data.setCurrentBranch(line.substring(3)); } else { StringData filePath = new StringData(line.substring(3)); char statusCode = line.substring(0, 2).trim().charAt(0); switch (statusCode) { case '?': data.getUntrackedFiles().add(filePath); break; case '\'': data.getUnmodifiedFiles().add(filePath); break; case 'M': data.getModifiedFiles().add(filePath); break; case 'A': data.getAddedFiles().add(filePath); break; case 'D': data.getDeletedFiles().add(filePath); break; case 'R': data.getRenamedFiles().add(parseRename(filePath.getValue())); break; case 'C': data.getCopiedFiles().add(filePath); break; case 'U': data.getUpdatedFiles().add(filePath); break; default: throw new TechnicalException("Unknown status '" + statusCode + "' in git output: " + line); } } } return this; }
From source file:org.aludratest.service.gitclient.GitClient.java
/** Provides the git log. * @param data/*from w w w .j a va 2 s .c o m*/ * @return */ public GitClient log(LogData data) { ArrayBuilder<String> builder = new ArrayBuilder<String>(String.class).add("log"); if (data.getMaxCount() != null) { builder.add("--max-count=" + data.getMaxCount()); } String output = invokeGenerically(GIT_LOG_PROCESS_NAME, true, builder.toArray()); LineIterator iterator = new LineIterator(new StringReader(output)); while (iterator.hasNext()) { parseLogItem(iterator, data); } return this; }
From source file:org.aludratest.service.gitclient.GitClient.java
/** Lists branches. * @param data/*from ww w .j a v a2s .co m*/ * @return a reference to this */ public GitClient listBranches(BranchListData data) { String output = invokeGenerically(GIT_LIST_BRANCHES_PROCESS_NAME, true, "branch", "--list"); LineIterator iterator = new LineIterator(new StringReader(output)); while (iterator.hasNext()) { String line = iterator.next(); boolean current = line.startsWith("*"); String branch = line.substring(2).trim(); data.getBranches().add(new StringData(branch)); if (current) { data.setCurrentBranch(branch); } } return this; }