List of usage examples for com.google.common.base Splitter split
@CheckReturnValue public Iterable<String> split(final CharSequence sequence)
From source file:nallar.tickthreading.patcher.remapping.Deobfuscator.java
public void setup(File mapData) { try {//from w w w . j av a 2 s . co m mapData = mapData.getCanonicalFile(); //noinspection IOResourceOpenedButNotSafelyClosed ZipFile mapZip = new ZipFile(mapData); ZipEntry classData = mapZip.getEntry("joined.srg"); ZipInputSupplier zis = new ZipInputSupplier(mapZip, classData); InputSupplier<InputStreamReader> srgSupplier = CharStreams.newReaderSupplier(zis, Charsets.UTF_8); List<String> srgList = CharStreams.readLines(srgSupplier); rawMethodMaps = Maps.newHashMap(); rawFieldMaps = Maps.newHashMap(); Builder<String, String> builder = ImmutableBiMap.builder(); Builder<String, String> mcpBuilder = ImmutableBiMap.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); parseMCPClass(mcpBuilder, parts); } else if ("MD".equals(typ)) { parseMethod(parts); } else if ("FD".equals(typ)) { parseField(parts); } } classNameBiMap = builder.build(); // Special case some mappings for modloader mods mcpBuilder.put("BaseMod", "net/minecraft/src/BaseMod"); mcpBuilder.put("ModLoader", "net/minecraft/src/ModLoader"); mcpBuilder.put("EntityRendererProxy", "net/minecraft/src/EntityRendererProxy"); mcpBuilder.put("MLProp", "net/minecraft/src/MLProp"); mcpBuilder.put("TradeEntry", "net/minecraft/src/TradeEntry"); mcpNameBiMap = mcpBuilder.build(); } catch (IOException ioe) { Log.severe("An error occurred loading the deobfuscation map data", ioe); } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }
From source file:org.apache.isis.core.metamodel.adapter.oid.OidMarshaller.java
@Programmatic @SuppressWarnings("unchecked") public <T extends Oid> T unmarshal(String oidStr, Class<T> requestedType) { final Matcher matcher = OIDSTR_PATTERN.matcher(oidStr); if (!matcher.matches()) { throw new IllegalArgumentException( "Could not parse OID '" + oidStr + "'; should match pattern: " + OIDSTR_PATTERN.pattern()); }/*from www . j ava2s . com*/ final String isTransientOrViewModelStr = getGroup(matcher, 3); final State state; if ("!".equals(isTransientOrViewModelStr)) { state = State.TRANSIENT; } else if ("*".equals(isTransientOrViewModelStr)) { state = State.VIEWMODEL; } else { state = State.PERSISTENT; } final String rootObjectType = getGroup(matcher, 4); final String rootIdentifier = getGroup(matcher, 5); final String aggregateOidPart = getGroup(matcher, 6); final List<AggregateOidPart> aggregateOidParts = Lists.newArrayList(); final Splitter nestingSplitter = Splitter.on(SEPARATOR_NESTING); final Splitter partsSplitter = Splitter.on(SEPARATOR); if (aggregateOidPart != null) { final Iterable<String> tildaSplitIter = nestingSplitter.split(aggregateOidPart); for (String str : tildaSplitIter) { if (Strings.isNullOrEmpty(str)) { continue; // leading "~" } final Iterator<String> colonSplitIter = partsSplitter.split(str).iterator(); final String objectType = colonSplitIter.next(); final String localId = colonSplitIter.next(); aggregateOidParts.add(new AggregateOidPart(objectType, localId)); } } final String collectionPart = getGroup(matcher, 8); final String collectionName = collectionPart != null ? collectionPart.substring(1) : null; final String versionSequence = getGroup(matcher, 10); final String versionUser = getGroup(matcher, 11); final String versionUtcTimestamp = getGroup(matcher, 12); final Version version = Version.create(versionSequence, versionUser, versionUtcTimestamp); if (collectionName == null) { if (aggregateOidParts.isEmpty()) { ensureCorrectType(oidStr, requestedType, RootOid.class); return (T) new RootOid(ObjectSpecId.of(rootObjectType), rootIdentifier, state, version); } else { throw new RuntimeException("Aggregated Oids are no longer supported"); } } else { final String oidStrWithoutCollectionName = getGroup(matcher, 1); final String parentOidStr = oidStrWithoutCollectionName + marshal(version); RootOid parentOid = this.unmarshal(parentOidStr, RootOid.class); ensureCorrectType(oidStr, requestedType, ParentedCollectionOid.class); return (T) new ParentedCollectionOid(parentOid, collectionName); } }
From source file:cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.java
public void setupLoadOnly(String deobfFileName, boolean loadAll) { try {/*from ww w . java2 s . c o m*/ File mapData = new File(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData)); InputSupplier<InputStreamReader> srgSupplier = CharStreams.newReaderSupplier(zis, Charsets.UTF_8); List<String> srgList = CharStreams.readLines(srgSupplier); 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) && loadAll) { parseMethod(parts); } else if ("FD".equals(typ) && loadAll) { parseField(parts); } } classNameBiMap = builder.build(); } catch (IOException ioe) { FMLRelaunchLog.log(Level.ERROR, "An error occurred loading the deobfuscation map data", ioe); } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }
From source file:cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.java
public void setup(File mcDir, LaunchClassLoader classLoader, String deobfFileName) { this.classLoader = classLoader; try {/*from w w w . j av a 2s . c o m*/ InputStream classData = getClass().getResourceAsStream(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(classData); InputSupplier<InputStreamReader> srgSupplier = CharStreams.newReaderSupplier(zis, Charsets.UTF_8); List<String> srgList = CharStreams.readLines(srgSupplier); 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:net.minecraftforge.common.config.ConfigCategory.java
public void write(BufferedWriter out, int indent) throws IOException { String pad0 = getIndent(indent); String pad1 = getIndent(indent + 1); String pad2 = getIndent(indent + 2); if (comment != null && !comment.isEmpty()) { write(out, pad0, COMMENT_SEPARATOR); write(out, pad0, "# ", name); write(out, pad0,/* w ww. j a v a 2 s .co m*/ "#--------------------------------------------------------------------------------------------------------#"); Splitter splitter = Splitter.onPattern("\r?\n"); for (String line : splitter.split(comment)) { write(out, pad0, "# ", line); } write(out, pad0, COMMENT_SEPARATOR, NEW_LINE); } String displayName = name; if (!allowedProperties.matchesAllOf(name)) { displayName = '"' + name + '"'; } write(out, pad0, displayName, " {"); Property[] props = getOrderedValues().toArray(new Property[] {}); for (int x = 0; x < props.length; x++) { Property prop = props[x]; if (prop.comment != null && !prop.comment.isEmpty()) { if (x != 0) { out.newLine(); } Splitter splitter = Splitter.onPattern("\r?\n"); for (String commentLine : splitter.split(prop.comment)) { write(out, pad1, "# ", commentLine); } } String propName = prop.getName(); if (!allowedProperties.matchesAllOf(propName)) { propName = '"' + propName + '"'; } if (prop.isList()) { char type = prop.getType().getID(); write(out, pad1, String.valueOf(type), ":", propName, " <"); for (String line : prop.getStringList()) { write(out, pad2, line); } write(out, pad1, " >"); } else if (prop.getType() == null) { write(out, pad1, propName, "=", prop.getString()); } else { char type = prop.getType().getID(); write(out, pad1, String.valueOf(type), ":", propName, "=", prop.getString()); } } if (children.size() > 0) out.newLine(); for (ConfigCategory child : children) { child.write(out, indent + 1); } write(out, pad0, "}", NEW_LINE); }
From source file:chibill.DeobLoader.loader.Remappers.java
public void setupLoadOnly(String deobfFileName, boolean loadAll) { try {// w w w. j av a 2 s .com File mapData = new File(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData)); CharSource srgSource = zis.asCharSource(Charsets.UTF_8); List<String> srgList = srgSource.readLines(); 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) && loadAll) { parseMethod(parts); } else if ("FD".equals(typ) && loadAll) { parseField(parts); } } classNameBiMap = builder.build(); } catch (IOException ioe) { } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }
From source file:chibill.DeobLoader.loader.Remappers.java
public void setup(File mcDir, LaunchClassLoader classLoader, String deobfFileName) { this.classLoader = classLoader; try {//from ww w.jav a 2 s.c o m InputStream classData = getClass().getResourceAsStream(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(classData); CharSource srgSource = zis.asCharSource(Charsets.UTF_8); List<String> srgList = srgSource.readLines(); 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) { } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }
From source file:de.schildbach.wallet.ui.AlertDialogsFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); log.debug("querying \"{}\"...", versionUrl); final Request.Builder request = new Request.Builder(); request.url(versionUrl);/* ww w . j a va2 s.c om*/ request.header("Accept-Charset", "utf-8"); final String userAgent = application.httpUserAgent(); if (userAgent != null) request.header("User-Agent", userAgent); final Call call = Constants.HTTP_CLIENT.newCall(request.build()); backgroundHandler.post(new Runnable() { @Override public void run() { boolean abort = false; try { final Response response = call.execute(); if (response.isSuccessful()) { final long serverTime = response.headers().getDate("Date").getTime(); try (final BufferedReader reader = new BufferedReader(response.body().charStream())) { abort = handleServerTime(serverTime); while (true) { final String line = reader.readLine(); if (line == null) break; if (line.charAt(0) == '#') continue; final Splitter splitter = Splitter.on('=').trimResults(); final Iterator<String> split = splitter.split(line).iterator(); if (!split.hasNext()) continue; final String key = split.next(); if (!split.hasNext()) { abort = handleLine(key); if (abort) break; continue; } final String value = split.next(); if (!split.hasNext()) { abort = handleProperty(key, value); if (abort) break; continue; } log.info("Ignoring line: {}", line); } } } } catch (final Exception x) { handleException(x); } if (!abort) handleCatchAll(); } }); }
From source file:com.mapr.synth.samplers.NameSampler.java
public NameSampler() { try {//from w ww.j a v a 2 s .c o m if (first.compareAndSet(null, new Multinomial<String>())) { Preconditions.checkState(last.getAndSet(new Multinomial<String>()) == null); Splitter onTab = Splitter.on(CharMatcher.WHITESPACE).omitEmptyStrings().trimResults(); for (String resourceName : ImmutableList.of("dist.male.first", "dist.female.first")) { for (String line : Resources.readLines(Resources.getResource(resourceName), Charsets.UTF_8)) { if (!line.startsWith("#")) { Iterator<String> parts = onTab.split(line).iterator(); String name = initialCap(parts.next()); double weight = Double.parseDouble(parts.next()); if (first.get().getWeight(name) == 0) { first.get().add(name, weight); } else { // do this instead of add because some first names may appear more than once first.get().set(name, first.get().getWeight(name) + weight); } } } } for (String line : Resources.readLines(Resources.getResource("dist.all.last"), Charsets.UTF_8)) { if (!line.startsWith("#")) { Iterator<String> parts = onTab.split(line).iterator(); String name = initialCap(parts.next()); double weight = Double.parseDouble(parts.next()); last.get().add(name, weight); } } } } catch (IOException e) { throw new RuntimeException("Couldn't read built-in resource file", e); } }
From source file:net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.java
public void setupLoadOnly(String deobfFileName, boolean loadAll) { try {// w ww . j ava 2s .co m File mapData = new File(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData)); CharSource srgSource = zis.asCharSource(Charsets.UTF_8); List<String> srgList = srgSource.readLines(); 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) && loadAll) { parseMethod(parts); } else if ("FD".equals(typ) && loadAll) { parseField(parts); } } classNameBiMap = builder.build(); } catch (IOException ioe) { FMLRelaunchLog.log(Level.ERROR, "An error occurred loading the deobfuscation map data", ioe); } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }