List of usage examples for com.google.common.io LineProcessor LineProcessor
LineProcessor
From source file:net.sourceforge.vaticanfetcher.model.Daemon.java
/** Checks if the daemon has detected changes in the indexed folders and runs index updates on all changed folders. */ public void enqueueUpdateTasks() { if (!indexesFile.exists()) return; // Happens when we're inside the IDE final IndexingQueue queue = indexRegistry.getQueue(); try {//from w w w .j ava 2s . c om Files.readLines(indexesFile, Charsets.UTF_8, new LineProcessor<Void>() { public boolean processLine(String line) throws IOException { // Ignore comment lines if (line.startsWith("//")) //$NON-NLS-1$ return true; // Ignore unchanged directories if (!line.startsWith("#")) //$NON-NLS-1$ return true; String rootPath = line.substring(1); LuceneIndex index = findIndex(rootPath); if (index == null) return true; // Unknown directory? queue.addTask(index, IndexAction.UPDATE); return true; } public Void getResult() { return null; } }); } catch (Exception e) { // Don't show stacktrace window here, GUI might not be available Util.printErr(e); } }
From source file:org.spongepowered.tools.obfuscation.mapping.mcp.MappingProviderSrg.java
@Override public void read(final File input) throws IOException { // Locally scoped to avoid synthetic accessor final BiMap<String, String> packageMap = this.packageMap; final BiMap<String, String> classMap = this.classMap; final BiMap<MappingField, MappingField> fieldMap = this.fieldMap; final BiMap<MappingMethod, MappingMethod> methodMap = this.methodMap; Files.readLines(input, Charset.defaultCharset(), new LineProcessor<String>() { @Override/* w w w. j a v a 2s.c om*/ public String getResult() { return null; } @Override public boolean processLine(String line) throws IOException { if (Strings.isNullOrEmpty(line) || line.startsWith("#")) { return true; } String type = line.substring(0, 2); String[] args = line.substring(4).split(" "); if (type.equals("PK")) { packageMap.forcePut(args[0], args[1]); } else if (type.equals("CL")) { classMap.forcePut(args[0], args[1]); } else if (type.equals("FD")) { fieldMap.forcePut(new MappingFieldSrg(args[0]).copy(), new MappingFieldSrg(args[1]).copy()); } else if (type.equals("MD")) { methodMap.forcePut(new MappingMethod(args[0], args[1]), new MappingMethod(args[2], args[3])); } else { throw new MixinException("Invalid SRG file: " + input); } return true; } }); }
From source file:org.nmdp.validation.tools.ValidateLdGlstrings.java
static ListMultimap<String, SubjectMug> read(final File file) throws IOException { BufferedReader reader = null; final ListMultimap<String, SubjectMug> subjectmugs = ArrayListMultimap.create(); final SubjectMug.Builder builder = SubjectMug.builder(); try {/* w w w . j a v a2s . c o m*/ reader = reader(file); CharStreams.readLines(reader, new LineProcessor<Void>() { private int count = 0; @Override public boolean processLine(final String line) throws IOException { String[] tokens = line.split("\t"); if (tokens.length < 2) { throw new IOException("illegal format, expected at least 2 columns, found " + tokens.length + "\nline=" + line); } String fullyQualified = GLStringUtilities.fullyQualifyGLString(tokens[1]); MultilocusUnphasedGenotype mug = GLStringUtilities.convertToMug(fullyQualified); DetectedLinkageFindings findings = LinkageDisequilibriumAnalyzer.detectLinkages(mug); Float minimumDifference = findings.getMinimumDifference(Locus.FIVE_LOCUS); minimumDifference = minimumDifference == null ? 0 : minimumDifference; SubjectMug subjectMug = builder.reset().withSample(tokens[0]).withGlstring(tokens[1]) .withMug(mug).withFindings(findings).withMinimumDifference(minimumDifference).build(); subjectmugs.put(subjectMug.sample(), subjectMug); count++; return true; } @Override public Void getResult() { return null; } }); return subjectmugs; } finally { try { reader.close(); } catch (Exception e) { // ignore } } }
From source file:com.facebook.buck.android.relinker.Symbols.java
public static ImmutableSet<String> getDtNeeded(ProcessExecutor executor, Tool objdump, SourcePathResolver resolver, Path lib) throws IOException, InterruptedException { final ImmutableSet.Builder<String> builder = ImmutableSet.builder(); final Pattern re = Pattern.compile("^ *NEEDED *(\\S*)$"); runObjdump(executor, objdump, resolver, lib, ImmutableList.of("-p"), new LineProcessor<Void>() { @Override// www. ja va 2 s.co m public boolean processLine(String line) throws IOException { Matcher m = re.matcher(line); if (!m.matches()) { return true; } builder.add(m.group(1)); return true; } @Override public Void getResult() { return null; } }); return builder.build(); }
From source file:eu.numberfour.n4js.analysis.PositiveAnalyser.java
private String withLineNumbers(String code) { try {//w ww . j av a 2 s . co m return CharStreams.readLines(new StringReader(code), new LineProcessor<String>() { private final StringBuilder lines = new StringBuilder(); private int lineNo = 1; @Override public boolean processLine(String line) throws IOException { lines.append(Strings.padStart(String.valueOf(lineNo++), 3, ' ')).append(": ").append(line) .append("\n"); return true; } @Override public String getResult() { return lines.toString(); } }); } catch (IOException e) { throw new IllegalStateException(e.getMessage()); } }
From source file:reflex.DefaultReflexIOHandler.java
@Override public ReflexValue forEachLine(ReflexStreamValue fileValue, final IReflexLineCallback iReflexLineCallback) { InputStream is = null;/*from ww w . j a v a 2 s .com*/ InputStreamReader isr = null; final ReflexValue ret = new ReflexVoidValue(); try { is = fileValue.getInputStream(); isr = new InputStreamReader(is, fileValue.getEncoding()); CharStreams.readLines(isr, new LineProcessor<String>() { @Override public boolean processLine(String line) throws IOException { ReflexValue v = iReflexLineCallback.callback(line); if (v.getValue() == ReflexValue.Internal.BREAK) { return false; } return true; } @Override public String getResult() { return null; } }); } catch (FileNotFoundException e) { } catch (IOException e) { } finally { if (is != null) { try { is.close(); isr.close(); } catch (Exception e) { } } } return ret; }
From source file:org.glassfish.jersey.tests.memleaks.maven.rule.PatternNotMatchedInFileRule.java
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { if (file == null || !file.exists()) { return;//from ww w.j ava2s.c om } final Pattern patternCompiled = Pattern.compile(pattern); try { final List<String> lines = Files.readLines(file, Charset.defaultCharset(), new LineProcessor<List<String>>() { private List<String> matchedLines = new LinkedList<>(); @Override public boolean processLine(final String line) throws IOException { if (patternCompiled.matcher(line).matches()) { matchedLines.add(line); if (maxMatchedLines != 0 && maxMatchedLines <= matchedLines.size()) { return false; } } return true; } @Override public List<String> getResult() { return matchedLines; } }); if (lines.size() > 0) { throw new EnforcerRuleException("Found lines matching pattern: '" + pattern + "'! Lines matched: " + Arrays.toString(lines.toArray()) + " in file: " + file.getAbsolutePath()); } } catch (IOException e) { throw new EnforcerRuleException( "I/O Error occurred during processing of file: " + file.getAbsolutePath(), e); } }
From source file:org.glassfish.jersey.test.memleak.common.MemoryLeakUtils.java
/** * Scans the file denoted by {@link #JERSEY_CONFIG_TEST_CONTAINER_LOGFILE} for {@link OutOfMemoryError} records. * * @throws IOException In case of I/O error. * @throws IllegalStateException In case the {@link OutOfMemoryError} record was found. */// w w w.ja v a2s . co m public static void verifyNoOutOfMemoryOccurred() throws IOException { final String logFileName = System.getProperty(JERSEY_CONFIG_TEST_CONTAINER_LOGFILE); System.out.println("Verifying whether OutOfMemoryError occurred in log file: " + logFileName); if (logFileName == null) { return; } final File logFile = new File(logFileName); if (!logFile.exists()) { return; } final List<String> lines = Files.readLines(logFile, Charset.defaultCharset(), new LineProcessor<List<String>>() { private List<String> matchedLines = new LinkedList<>(); @Override public boolean processLine(final String line) throws IOException { if (PATTERN.matcher(line).matches()) { matchedLines.add(line); } return true; } @Override public List<String> getResult() { return matchedLines; } }); if (lines.size() > 0) { throw new IllegalStateException( "OutOfMemoryError detected in '" + logFileName + "': " + Arrays.toString(lines.toArray())); } }
From source file:org.locationtech.geogig.storage.fs.FileConflictsDatabase.java
/** * Gets all conflicts that match the specified path filter. * /*from w w w.j a v a 2 s . c o m*/ * @param namespace the namespace of the conflict * @param pathFilter the path filter, if this is not defined, all conflicts will be returned * @return the list of conflicts */ @Override public List<Conflict> getConflicts(@Nullable String namespace, @Nullable final String pathFilter) { final Object monitor = resolveConflictsMonitor(namespace); if (null == monitor) { return ImmutableList.of(); } synchronized (monitor) { final File file = resolveConflictsFile(namespace); if (null == file || !file.exists() || file.length() == 0) { return ImmutableList.of(); } List<Conflict> conflicts; try { conflicts = Files.readLines(file, Charsets.UTF_8, new LineProcessor<List<Conflict>>() { List<Conflict> conflicts = Lists.newArrayList(); @Override public List<Conflict> getResult() { return conflicts; } @Override public boolean processLine(String s) throws IOException { Conflict c = Conflict.valueOf(s); if (pathFilter == null) { conflicts.add(c); } else if (c.getPath().startsWith(pathFilter)) { conflicts.add(c); } return true; } }); } catch (IOException e) { throw Throwables.propagate(e); } return conflicts; } }
From source file:com.davidbracewell.wordnet.WordNetLemmatizer.java
/** * Instantiates a new English lemmatizer. *///from ww w .ja va 2 s . c o m protected WordNetLemmatizer() { rules.put(WordNetPOS.NOUN, new DetachmentRule("s", "")); rules.put(WordNetPOS.NOUN, new DetachmentRule("ses", "s")); rules.put(WordNetPOS.NOUN, new DetachmentRule("xes", "x")); rules.put(WordNetPOS.NOUN, new DetachmentRule("zes", "z")); rules.put(WordNetPOS.NOUN, new DetachmentRule("ies", "y")); rules.put(WordNetPOS.NOUN, new DetachmentRule("shes", "sh")); rules.put(WordNetPOS.NOUN, new DetachmentRule("ches", "ch")); rules.put(WordNetPOS.NOUN, new DetachmentRule("men", "man")); loadException(WordNetPOS.NOUN); rules.put(WordNetPOS.VERB, new DetachmentRule("s", "")); rules.put(WordNetPOS.VERB, new DetachmentRule("ies", "y")); rules.put(WordNetPOS.VERB, new DetachmentRule("es", "s")); rules.put(WordNetPOS.VERB, new DetachmentRule("es", "")); rules.put(WordNetPOS.VERB, new DetachmentRule("ed", "e")); rules.put(WordNetPOS.VERB, new DetachmentRule("ed", "")); rules.put(WordNetPOS.VERB, new DetachmentRule("ing", "e")); rules.put(WordNetPOS.VERB, new DetachmentRule("ing", "")); loadException(WordNetPOS.VERB); rules.put(WordNetPOS.ADJECTIVE, new DetachmentRule("er", "")); rules.put(WordNetPOS.ADJECTIVE, new DetachmentRule("est", "")); rules.put(WordNetPOS.ADJECTIVE, new DetachmentRule("er", "e")); rules.put(WordNetPOS.ADJECTIVE, new DetachmentRule("est", "e")); loadException(WordNetPOS.ADJECTIVE); loadException(WordNetPOS.ADVERB); try { this.lemmas = Config.get(WordNetLemmatizer.class, "dictionary").asResource() .read(new LineProcessor<PatriciaTrie<Boolean>>() { private PatriciaTrie<Boolean> lemmas = new PatriciaTrie<>(); @Override public boolean processLine(String line) throws IOException { if (!Strings.isNullOrEmpty(line) && !line.trim().startsWith("#")) { lemmas.put(line.trim().toLowerCase(), true); } return true; } @Override public PatriciaTrie<Boolean> getResult() { return lemmas; } }); } catch (IOException e) { throw Throwables.propagate(e); } }