List of usage examples for com.google.common.base Splitter split
@CheckReturnValue public Iterable<String> split(final CharSequence sequence)
From source file:net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.java
public void setup(File mcDir, LaunchClassLoader classLoader, String deobfFileName) { this.classLoader = classLoader; try {/*from www. j av a 2 s . c o m*/ List<String> srgList; final String gradleStartProp = System.getProperty("net.minecraftforge.gradle.GradleStart.srg.srg-mcp"); if (Strings.isNullOrEmpty(gradleStartProp)) { // get as a resource InputStream classData = getClass().getResourceAsStream(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(classData); CharSource srgSource = zis.asCharSource(Charsets.UTF_8); srgList = srgSource.readLines(); } else { srgList = Files.readLines(new File(gradleStartProp), Charsets.UTF_8); } rawMethodMaps = Maps.newHashMap(); rawFieldMaps = Maps.newHashMap(); Builder<String, String> builder = ImmutableBiMap.<String, String>builder(); Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults(); for (String line : srgList) { String[] parts = Iterables.toArray(splitter.split(line), String.class); String typ = parts[0]; if ("CL".equals(typ)) { parseClass(builder, parts); } else if ("MD".equals(typ)) { parseMethod(parts); } else if ("FD".equals(typ)) { parseField(parts); } } classNameBiMap = builder.build(); } catch (IOException ioe) { FMLRelaunchLog.log(Level.ERROR, ioe, "An error occurred loading the deobfuscation map data"); } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }
From source file:edu.mit.streamjit.tuner.OfflineTuner.java
private void printFinalConfg(String finalConfg, BufferedWriter bw) throws IOException { finalConfg = finalConfg.replaceAll("u'", ""); finalConfg = finalConfg.replaceAll("':", ""); finalConfg = finalConfg.replaceAll("\\{", ""); finalConfg = finalConfg.replaceAll("\\}", ""); Splitter dictSplitter = Splitter.on(", ").omitEmptyStrings().trimResults(); System.out.println("********************************"); System.out.println("This is the final configuration*"); bw.write("\n********************************\n"); bw.write("This is the final configuration\n"); for (String s : dictSplitter.split(finalConfg)) { String[] str = s.split(" "); if (str.length != 2) throw new AssertionError("Wrong python dictionary..."); // System.out.println(String.format("\t%s = %s", str[0], str[1])); bw.write(String.format("\t%s = %s\n", str[0], str[1])); }/*from w ww .ja v a 2 s. c om*/ }
From source file:keepcalm.programs.idfixer.Configuration.java
private void writeProperties(BufferedWriter buffer, Collection<Property> props) throws IOException { for (Property property : props) { if (property.comment != null) { Splitter splitter = Splitter.onPattern("\r?\n"); for (String commentLine : splitter.split(property.comment)) { buffer.write(" # " + commentLine + "\r\n"); }// w w w .j a v a 2s . c om } String propName = property.getName(); if (!allowedProperties.matchesAllOf(propName)) { propName = '"' + propName + '"'; } buffer.write(" " + propName + "=" + property.value); buffer.write("\r\n"); } }
From source file:keepcalm.programs.idfixer.Configuration.java
private void save(BufferedWriter out) throws IOException { for (Map.Entry<String, Map<String, Property>> category : categories.entrySet()) { out.write("####################\r\n"); out.write("# " + category.getKey() + " \r\n"); if (customCategoryComments.containsKey(category.getKey())) { out.write("#===================\r\n"); String comment = customCategoryComments.get(category.getKey()); Splitter splitter = Splitter.onPattern("\r?\n"); for (String commentLine : splitter.split(comment)) { out.write("# "); out.write(commentLine + "\r\n"); }/*from ww w . j a va2s .com*/ } out.write("####################\r\n\r\n"); String catKey = category.getKey(); if (!allowedProperties.matchesAllOf(catKey)) { catKey = '"' + catKey + '"'; } out.write(catKey + " {\r\n"); writeProperties(out, category.getValue().values()); out.write("}\r\n\r\n"); } }
From source file:net.minecraftforge.gradle.user.TaskExtractDepAts.java
@TaskAction public void doTask() throws IOException { FileCollection col = getCollections(); File outputDir = getOutputDir(); outputDir.mkdirs(); // make sur eit exists // make a list of things to delete... List<File> toDelete = Lists.newArrayList(outputDir.listFiles(new FileFilter() { @Override/*from w w w. j av a2 s.c o m*/ public boolean accept(File f) { return f.isFile(); } })); Splitter splitter = Splitter.on(' '); for (File f : col) { if (!f.exists() || !f.getName().endsWith("jar")) continue; JarFile jar = new JarFile(f); Manifest man = jar.getManifest(); if (man != null) { String atString = man.getMainAttributes().getValue("FMLAT"); if (!Strings.isNullOrEmpty(atString)) { for (String at : splitter.split(atString.trim())) { // append _at.cfg just in case its not there already... // also differentiate the file name, in cas the same At comes from multiple jars.. who knows why... File outFile = new File(outputDir, at + "_" + Files.getNameWithoutExtension(f.getName()) + "_at.cfg"); toDelete.remove(outFile); JarEntry entry = jar.getJarEntry("META-INF/" + at); InputStream istream = jar.getInputStream(entry); OutputStream ostream = new FileOutputStream(outFile); ByteStreams.copy(istream, ostream); istream.close(); ostream.close(); } } } jar.close(); } // remove the files that shouldnt be there... for (File f : toDelete) { f.delete(); } }
From source file:com.android.build.gradle.tasks.annotations.ApiDatabase.java
private void readApi() { String MODIFIERS = "((deprecated|public|static|private|protected|final|abstract|\\s*)\\s+)*"; Pattern PACKAGE = Pattern.compile("package (\\S+) \\{"); Pattern CLASS = Pattern.compile( MODIFIERS + "(class|interface|enum)\\s+(\\S+)\\s+(extends (.+))?(implements (.+))?(.*)\\{"); Pattern METHOD = Pattern.compile("(method|ctor)\\s+" + MODIFIERS + "(.+)??\\s+(\\S+)\\s*\\((.*)\\)(.*);"); Pattern CTOR = Pattern.compile("(method|ctor)\\s+.*\\((.*)\\)(.*);"); Pattern FIELD = Pattern.compile("(enum_constant|field)\\s+" + MODIFIERS + "(.+)\\s+(\\S+)\\s*;"); String currentPackage = null; String currentClass = null;/*from w ww . j a v a 2 s. c o m*/ for (String line : lines) { line = line.trim(); if (line.isEmpty() || line.equals("}")) { continue; } if (line.startsWith("method ")) { Matcher matcher = METHOD.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a member: " + line); } else { assert currentClass != null; Map<String, List<String>> memberMap = methodMap.get(currentClass); if (memberMap == null) { memberMap = Maps.newHashMap(); methodMap.put(currentClass, memberMap); methodMap.put(getRawClass(currentClass), memberMap); } String methodName = matcher.group(5); List<String> signatures = memberMap.get(methodName); if (signatures == null) { signatures = Lists.newArrayList(); memberMap.put(methodName, signatures); memberMap.put(getRawMethod(methodName), signatures); } String signature = matcher.group(6); signature = signature.trim().replace(" ", "").replace(" ", ""); // normalize varargs: allow lookup with both formats signatures.add(signature); if (signature.endsWith("...")) { signatures.add(signature.substring(0, signature.length() - 3) + "[]"); } else if (signature.endsWith("[]") && !signature.endsWith("[][]")) { signatures.add(signature.substring(0, signature.length() - 2) + "..."); } String raw = getRawParameterList(signature); if (!signatures.contains(raw)) { signatures.add(raw); } } } else if (line.startsWith("ctor ")) { Matcher matcher = CTOR.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a member: " + line); } else { assert currentClass != null; Map<String, List<String>> memberMap = methodMap.get(currentClass); if (memberMap == null) { memberMap = Maps.newHashMap(); methodMap.put(currentClass, memberMap); methodMap.put(getRawClass(currentClass), memberMap); } @SuppressWarnings("UnnecessaryLocalVariable") String methodName = currentClass; List<String> signatures = memberMap.get(methodName); if (signatures == null) { signatures = Lists.newArrayList(); memberMap.put(methodName, signatures); String constructor = methodName.substring(methodName.lastIndexOf('.') + 1); memberMap.put(constructor, signatures); memberMap.put(getRawMethod(methodName), signatures); memberMap.put(getRawMethod(constructor), signatures); } String signature = matcher.group(2); signature = signature.trim().replace(" ", "").replace(" ", ""); if (signature.endsWith("...")) { signatures.add(signature.substring(0, signature.length() - 3) + "[]"); } else if (signature.endsWith("[]") && !signature.endsWith("[][]")) { signatures.add(signature.substring(0, signature.length() - 2) + "..."); } signatures.add(signature); String raw = getRawMethod(signature); if (!signatures.contains(raw)) { signatures.add(raw); } } } else if (line.startsWith("enum_constant ") || line.startsWith("field ")) { int equals = line.indexOf('='); if (equals != -1) { line = line.substring(0, equals).trim(); int semi = line.indexOf(';'); if (semi == -1) { line = line + ';'; } } else if (!line.endsWith(";")) { int semi = line.indexOf(';'); if (semi != -1) { line = line.substring(0, semi + 1); } } Matcher matcher = FIELD.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a member: " + line); } else { assert currentClass != null; String fieldName = matcher.group(5); Set<String> fieldSet = fieldMap.get(currentClass); if (fieldSet == null) { fieldSet = Sets.newHashSet(); fieldMap.put(currentClass, fieldSet); } fieldSet.add(fieldName); String type = matcher.group(4); if (type.equals("int")) { fieldSet = intFieldMap.get(currentClass); if (fieldSet == null) { fieldSet = Sets.newHashSet(); intFieldMap.put(currentClass, fieldSet); } fieldSet.add(fieldName); } } } else if (line.startsWith("package ")) { Matcher matcher = PACKAGE.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a package: " + line); } else { currentPackage = matcher.group(1); } } else { Matcher matcher = CLASS.matcher(line); if (!matcher.matches()) { Extractor.warning("Warning: Did not match as a class/interface: " + line); } else { currentClass = currentPackage + '.' + matcher.group(4); classSet.add(currentClass); String superClass = matcher.group(6); if (superClass != null) { Splitter splitter = Splitter.on(' ').trimResults().omitEmptyStrings(); for (String from : splitter.split(superClass)) { if (from.equals("implements")) { // workaround for broken regexp continue; } addInheritsFrom(currentClass, from); } addInheritsFrom(currentClass, superClass.trim()); } String implementsList = matcher.group(8); if (implementsList != null) { Splitter splitter = Splitter.on(' ').trimResults().omitEmptyStrings(); for (String from : splitter.split(implementsList)) { addInheritsFrom(currentClass, from); } } } } } }
From source file:ru.codeinside.adm.parser.ServiceFixtureParser.java
public void loadFixtures(InputStream is, ServiceFixtureParser.PersistenceCallback callback) throws IOException { final Splitter propertySplitter = Splitter.on(':'); final BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); String line;/*w w w .j a v a 2 s . co m*/ int lineNumber = 0; while ((line = reader.readLine()) != null) { lineNumber++; int level = startIndex(line); if (line.startsWith("#") || level < 0) { continue; } final ArrayList<String> props = Lists.newArrayList(propertySplitter.split(line.substring(level))); final String name = StringUtils.trimToNull(props.get(0)).replace("<br/>", "\n"); if (name == null) { throw new IllegalStateException(" ?( ?:" + lineNumber + ")"); } final Long regCode; try { regCode = Long.parseLong(props.get(1)); } catch (NumberFormatException e) { throw new IllegalStateException( " ( ?:" + lineNumber + "): " + name); } final boolean isProc = level > 0; Row parent = getParentRow(level); if (!isProc) { long servId = callback.onServiceComplete(name, regCode); stack.addLast(new Row(level, servId)); } if (isProc && parent != null) { callback.onProcedureComplete(name, regCode, parent.id); } if (isProc && parent == null) { throw new IllegalStateException( " ?( ?:" + lineNumber + "): " + name); } } }
From source file:com.music.TitleGenerator.java
public TitleGenerator() throws IOException { Splitter splitter = Splitter.on(','); Properties properties = new Properties(); try (InputStreamReader reader = new InputStreamReader( TitleGenerator.class.getResourceAsStream("/titleComponents.properties"))) { properties.load(reader);/*w w w .j a va2 s . c o m*/ nouns = Lists.newArrayList(splitter.split(properties.getProperty("nouns"))); abstractNouns = Lists.newArrayList(splitter.split(properties.getProperty("abstract.nouns"))); pronouns = Lists.newArrayList(splitter.split(properties.getProperty("pronouns"))); adjectives = Lists.newArrayList(splitter.split(properties.getProperty("adjectives"))); minorAdjectives = Lists.newArrayList(splitter.split(properties.getProperty("minor.adjectives"))); linkingWords = Lists.newArrayList(splitter.split(properties.getProperty("linking.words"))); transitiveVerbs = Lists.newArrayList(splitter.split(properties.getProperty("transitive.verbs"))); adverbs = Lists.newArrayList(splitter.split(properties.getProperty("adverbs"))); List<String> intransitiveVerbsList = Lists .newArrayList(splitter.split(properties.getProperty("intransitive.verbs"))); for (String verb : intransitiveVerbsList) { String[] parts = verb.split("\\|"); intransitiveVerbs.add(new KeyValue(parts[0], parts[1])); } } // define the possible structures of the piece title in terms of its components String[] nouns = new String[] { "CN", "AN" }; String[] verbs = new String[] { "TV", "IV" }; for (String noun : nouns) { for (String verb : verbs) { for (String secondNoun : nouns) { structures.add(noun + "-" + verb + "-" + secondNoun); structures.add("PRN" + "-" + verb + "-" + secondNoun); structures.add("ADJ-" + noun + "-" + verb + "-" + secondNoun); structures.add(noun + "-" + verb + "-ADJ-" + secondNoun); structures.add(noun + "-LNK-" + secondNoun); structures.add(noun + "-LNK-ADJ-" + secondNoun); structures.add("ADJ-" + noun + "-LNK-" + secondNoun); } if (verb.equals("IV")) { structures.add(noun + "-" + verb); structures.add("ADJ-" + noun + "-" + verb); structures.add(noun + "-" + verb + "-ADV"); structures.add("ADJ-" + noun + "-" + verb + "-ADV"); } structures.add(verb + "-ADV"); structures.add(verb + "-" + noun); structures.add(verb + "-ADJ-" + noun); } } }
From source file:uk.q3c.krail.core.navigate.sitemap.DefaultFileSitemapLoader.java
/** * The expected syntax of a redirect is <em> fromPage : toPage</em> * <p/>/*from w w w. j a v a2s . co m*/ * Lines which do not contain a ':' are ignored<br> * Lines containing multiple ':' will only process the first two segments, the rest is ignored */ private void processRedirects() { List<String> sectionLines = sections.get(SectionName.redirects); for (String redirect : sectionLines) { if (redirect.contains(":")) { Splitter splitter = Splitter.on(":").trimResults(); Iterable<String> split = splitter.split(redirect); Iterator<String> iter = split.iterator(); String fromPage = iter.next(); String toPage = iter.next(); sitemap.addRedirect(fromPage, toPage); } else { addInfo(REDIRECT_INVALID, redirect); } } }
From source file:uk.q3c.krail.core.navigate.sitemap.DefaultFileSitemapLoader.java
private void processMap(String source) { URITracker uriTracker = new URITracker(); MapLineReader reader = new MapLineReader(); List<String> sectionLines = sections.get(SectionName.map); int lineIndex = 1; int currentIndent = 0; for (String line : sectionLines) { MapLineRecord lineRecord = reader.processLine(this, source, lineIndex, line, currentIndent, segmentSeparator);/*from w ww. j a va2 s . co m*/ uriTracker.track(lineRecord.getIndentLevel(), lineRecord.getSegment()); MasterSitemapNode node = sitemap.append(uriTracker.uri()); node.setUriSegment(lineRecord.getSegment()); findView(source, node, lineRecord.getSegment(), lineRecord.getViewName()); labelKeyForName(lineRecord.getKeyName(), node); Splitter splitter = Splitter.on(",").trimResults(); Iterable<String> roles = splitter.split(lineRecord.getRoles()); for (String role : roles) { node.addRole(role); } node.setPageAccessControl(lineRecord.getPageAccessControl()); currentIndent = lineRecord.getIndentLevel(); lineIndex++; } }