List of usage examples for com.google.common.io LineProcessor LineProcessor
LineProcessor
From source file:net.minecraftforge.gradle.util.mcp.ReobfExceptor.java
private Map<String, String> createClassMap(Map<String, String> markerMap, final List<String> interfaces) throws IOException { Map<String, String> excMap = Files.readLines(excConfig, Charset.defaultCharset(), new LineProcessor<Map<String, String>>() { Map<String, String> tmp = Maps.newHashMap(); @Override/*from www . j a va 2s. c om*/ public boolean processLine(String line) throws IOException { if (line.contains(".") || !line.contains("=") || line.startsWith("#")) return true; String[] s = line.split("="); if (!interfaces.contains(s[0])) tmp.put(s[0], s[1] + "_"); return true; } @Override public Map<String, String> getResult() { return tmp; } }); Map<String, String> map = Maps.newHashMap(); for (Entry<String, String> e : excMap.entrySet()) { String renamed = markerMap.get(e.getValue()); if (renamed != null) { map.put(e.getKey(), renamed); } } return map; }
From source file:org.locationtech.geogig.storage.fs.FileConflictsDatabase.java
/** * Gets the specified conflict from the database. * //from www .j ava 2s . c o m * @param namespace the namespace of the conflict * @param path the conflict to retrieve * @return the conflict, or {@link Optional#absent()} if it was not found */ @Override public Optional<Conflict> getConflict(@Nullable String namespace, final String path) { final Object monitor = resolveConflictsMonitor(namespace); if (null == monitor) { return Optional.absent(); } synchronized (monitor) { File file = resolveConflictsFile(namespace); if (file == null || !file.exists()) { return Optional.absent(); } Conflict conflict = null; try { conflict = Files.readLines(file, Charsets.UTF_8, new LineProcessor<Conflict>() { Conflict conflict = null; @Override public Conflict getResult() { return conflict; } @Override public boolean processLine(String s) throws IOException { Conflict c = Conflict.valueOf(s); if (c.getPath().equals(path)) { conflict = c; return false; } else { return true; } } }); } catch (IOException e) { throw Throwables.propagate(e); } return Optional.fromNullable(conflict); } }
From source file:io.takari.m2e.jdt.core.internal.JavaConfigurator.java
protected static Collection<String> parseExportPackage(InputStream is) throws IOException { LineProcessor<List<String>> processor = new LineProcessor<List<String>>() { final List<String> result = new ArrayList<String>(); @Override//from ww w. j a v a2 s .c om public boolean processLine(String line) throws IOException { result.add(line.replace('.', '/')); return true; // keep reading } @Override public List<String> getResult() { return result; } }; return CharStreams.readLines(new InputStreamReader(is, Charsets.UTF_8), processor); }
From source file:net.minecraftforge.gradle.tasks.DeobfuscateJar.java
public void applyExceptor(File inJar, File outJar, File config, File log, Set<File> ats) throws IOException { String json = null;/*w w w . java 2 s .c o m*/ File getJson = getExceptorJson(); if (getJson != null) { final Map<String, MCInjectorStruct> struct = JsonFactory.loadMCIJson(getJson); for (File at : ats) { getLogger().info("loading AT: " + at.getCanonicalPath()); Files.readLines(at, Charset.defaultCharset(), new LineProcessor<Object>() { @Override public boolean processLine(String line) throws IOException { if (line.indexOf('#') != -1) line = line.substring(0, line.indexOf('#')); line = line.trim().replace('.', '/'); if (line.isEmpty()) return true; String[] s = line.split(" "); if (s.length == 2 && s[1].indexOf('$') > 0) { String parent = s[1].substring(0, s[1].indexOf('$')); for (MCInjectorStruct cls : new MCInjectorStruct[] { struct.get(parent), struct.get(s[1]) }) { if (cls != null && cls.innerClasses != null) { for (InnerClass inner : cls.innerClasses) { if (inner.inner_class.equals(s[1])) { int access = fixAccess(inner.getAccess(), s[0]); inner.access = (access == 0 ? null : Integer.toHexString(access)); } } } } } return true; } @Override public Object getResult() { return null; } }); } // Remove unknown classes from configuration removeUnknownClasses(inJar, struct); File jsonTmp = new File(this.getTemporaryDir(), "transformed.json"); json = jsonTmp.getCanonicalPath(); Files.write(JsonFactory.GSON.toJson(struct).getBytes(), jsonTmp); } getLogger().debug("INPUT: " + inJar); getLogger().debug("OUTPUT: " + outJar); getLogger().debug("CONFIG: " + config); getLogger().debug("JSON: " + json); getLogger().debug("LOG: " + log); getLogger().debug("PARAMS: true"); MCInjectorImpl.process(inJar.getCanonicalPath(), outJar.getCanonicalPath(), config.getCanonicalPath(), log.getCanonicalPath(), null, 0, json, isApplyMarkers(), true); }
From source file:org.apache.druid.cli.validate.DruidJsonValidator.java
private Void readData(final StringInputRowParser parser, final CharSource source) throws IOException { return source.readLines(new LineProcessor<Void>() { private final StringBuilder builder = new StringBuilder(); @Override//from w w w .ja v a2s . c o m public boolean processLine(String line) throws IOException { InputRow parsed = parser.parse(line); builder.append(parsed.getTimestamp()); for (String dimension : parsed.getDimensions()) { builder.append('\t'); builder.append(parsed.getRaw(dimension)); } logWriter.write(builder.toString()); builder.setLength(0); return true; } @Override public Void getResult() { return null; } }); }
From source file:org.geogit.storage.bdbje.JEStagingDatabase.java
/** * Gets all conflicts that match the specified path filter. * //w w w .j a v a 2 s. c om * @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, final String pathFilter) { Optional<File> conflictsFile = findOrCreateConflictsFile(namespace); if (!conflictsFile.isPresent()) { return ImmutableList.of(); } File file = conflictsFile.get(); List<Conflict> conflicts = Lists.newArrayList(); try { synchronized (file.getCanonicalPath().intern()) { 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.mapr.synth.samplers.VinSampler.java
private static Map<String, String> mapResource(String name) throws IOException { final Splitter onTab = Splitter.on("\t"); return Resources.readLines(Resources.getResource(name), Charsets.UTF_8, new LineProcessor<Map<String, String>>() { final Map<String, String> r = Maps.newHashMap(); @Override/*ww w . j av a 2 s . co m*/ public boolean processLine(String line) throws IOException { Iterator<String> pieces = onTab.split(line).iterator(); String key = pieces.next(); r.put(key, pieces.next()); return true; } @Override public Map<String, String> getResult() { return r; } }); }
From source file:org.gradle.internal.operations.trace.BuildOperationTrace.java
private static List<BuildOperationRecord> readLogToTreeRoots(final File logFile) { try {/*from w ww . j a va 2 s. co m*/ final JsonSlurper slurper = new JsonSlurper(); final List<BuildOperationRecord> roots = new ArrayList<BuildOperationRecord>(); final Map<Object, PendingOperation> pendings = new HashMap<Object, PendingOperation>(); final Map<Object, List<BuildOperationRecord>> childrens = new HashMap<Object, List<BuildOperationRecord>>(); Files.asCharSource(logFile, Charsets.UTF_8).readLines(new LineProcessor<Void>() { @Override public boolean processLine(@SuppressWarnings("NullableProblems") String line) { Map<String, ?> map = uncheckedCast(slurper.parseText(line)); if (map.containsKey("startTime")) { SerializedOperationStart serialized = new SerializedOperationStart(map); pendings.put(serialized.id, new PendingOperation(serialized)); childrens.put(serialized.id, new LinkedList<BuildOperationRecord>()); } else if (map.containsKey("time")) { SerializedOperationProgress serialized = new SerializedOperationProgress(map); PendingOperation pending = pendings.get(serialized.id); assert pending != null : "did not find owner of progress event with ID " + serialized.id; pending.progress.add(serialized); } else { SerializedOperationFinish finish = new SerializedOperationFinish(map); PendingOperation pending = pendings.remove(finish.id); assert pending != null; List<BuildOperationRecord> children = childrens.remove(finish.id); assert children != null; SerializedOperationStart start = pending.start; Map<String, ?> detailsMap = uncheckedCast(start.details); Map<String, ?> resultMap = uncheckedCast(finish.result); List<BuildOperationRecord.Progress> progresses = new ArrayList<BuildOperationRecord.Progress>(); for (SerializedOperationProgress progress : pending.progress) { Map<String, ?> progressDetailsMap = uncheckedCast(progress.details); progresses.add(new BuildOperationRecord.Progress(progress.time, progressDetailsMap, progress.detailsClassName)); } BuildOperationRecord record = new BuildOperationRecord(start.id, start.parentId, start.displayName, start.startTime, finish.endTime, detailsMap == null ? null : Collections.unmodifiableMap(detailsMap), start.detailsClassName, resultMap == null ? null : Collections.unmodifiableMap(resultMap), finish.resultClassName, finish.failureMsg, progresses, BuildOperationRecord.ORDERING.immutableSortedCopy(children)); if (start.parentId == null) { roots.add(record); } else { List<BuildOperationRecord> parentChildren = childrens.get(start.parentId); assert parentChildren != null : "parentChildren != null '" + line + "' from " + logFile; parentChildren.add(record); } } return true; } @Override public Void getResult() { return null; } }); assert pendings.isEmpty(); return roots; } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } }
From source file:org.nmdp.ngs.tools.ValidateInterpretation.java
static ListMultimap<String, Interpretation> read(final File file) throws IOException { BufferedReader reader = null; final ListMultimap<String, Interpretation> interpretations = ArrayListMultimap.create(); final Interpretation.Builder builder = Interpretation.builder(); try {//from w w w .j av a 2 s.co 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 < 6) { throw new IOException("illegal interpretation format, expected at least 6 columns, found " + tokens.length + "\nline=" + line); } Interpretation interpretation = builder.reset().withSample(tokens[0]).withLocus(tokens[1]) .withGeneFamily(tokens[2]).withAlleleDb(tokens[3]).withAlleleVersion(tokens[4]) .withGlstring(tokens[5]).withConsensus(tokens.length > 6 ? tokens[6] : null).build(); interpretations.put(interpretation.sample(), interpretation); count++; return true; } @Override public Void getResult() { return null; } }); return interpretations; } finally { try { reader.close(); } catch (Exception e) { // ignore } } }
From source file:com.mapr.synth.samplers.VinSampler.java
private static SetMultimap<String, String> multiMapResource(String name) throws IOException { final Splitter onTab = Splitter.on("\t"); return Resources.readLines(Resources.getResource(name), Charsets.UTF_8, new LineProcessor<SetMultimap<String, String>>() { final SetMultimap<String, String> r = HashMultimap.create(); @Override//from w w w . j a v a2 s . co m public boolean processLine(String line) throws IOException { Iterator<String> pieces = onTab.split(line).iterator(); String key = pieces.next(); r.put(key, pieces.next()); return true; } @Override public SetMultimap<String, String> getResult() { return r; } }); }