List of usage examples for com.google.common.base Splitter on
@CheckReturnValue @GwtIncompatible("java.util.regex") public static Splitter on(final Pattern separatorPattern)
From source file:org.apache.james.jmap.utils.SortToComparatorConvertor.java
@SuppressWarnings("unchecked") private static <M extends Map.Entry<MailboxPath, MessageResult>, Id extends MailboxId> Comparator<M> comparatorForField( String field) {//from w ww . j a v a2s.c om List<String> splitToList = Splitter.on(SEPARATOR).splitToList(field); checkField(splitToList); Comparator<M> fieldComparator = Comparator.comparing(functionForField(splitToList.get(0))); if (splitToList.size() == 1 || splitToList.get(1).equals(DESC_ORDERING)) { return fieldComparator.reversed(); } return fieldComparator; }
From source file:com.mapr.synth.samplers.StreetNameSampler.java
public StreetNameSampler() { Splitter onTabs = Splitter.on("\t"); try {/*from w ww . j a va 2 s. c om*/ for (String line : Resources.readLines(Resources.getResource("street-name-seeds"), Charsets.UTF_8)) { if (!line.startsWith("#")) { Iterator<Multinomial<String>> i = sampler.iterator(); for (String name : onTabs.split(line)) { i.next().add(name, 1); } } } } catch (IOException e) { throw new RuntimeException("Couldn't read built-in resource", e); } }
From source file:com.android.build.gradle.integration.common.utils.ApkHelper.java
/** * Runs a process, and returns the output. * * @param processInfo the process info to run * @param processExecutor the process executor * * @return the output as a list of files. * @throws ProcessException//from w w w. j a va 2 s.co m */ @NonNull public static List<String> runAndGetOutput(@NonNull ProcessInfo processInfo, @NonNull ProcessExecutor processExecutor) throws ProcessException { CachedProcessOutputHandler handler = new CachedProcessOutputHandler(); processExecutor.execute(processInfo, handler).rethrowFailure().assertNormalExitValue(); return Splitter.on('\n').splitToList(handler.getProcessOutput().getStandardOutputAsString()); }
From source file:net.citizensnpcs.resources.sk89q.CommandContext.java
public CommandContext(String[] args) { int i = 1;//from w ww . j av a 2 s . co m for (; i < args.length; i++) { if (args[i].length() == 0) { // Ignore this } else if (args[i].charAt(0) == '-' && args[i].matches("^-[a-zA-Z]+$")) { for (int k = 1; k < args[i].length(); k++) { flags.add(args[i].charAt(k)); } args[i] = ""; } } this.args = Iterables.toArray( Splitter.on(" ").omitEmptyStrings().split(Joiner.on(" ").skipNulls().join(args)), String.class); }
From source file:gobblin.util.EmailUtils.java
/** * A general method for sending emails.//from ww w. j av a 2s.c o m * * @param state a {@link State} object containing configuration properties * @param subject email subject * @param message email message * @throws EmailException if there is anything wrong sending the email */ public static void sendEmail(State state, String subject, String message) throws EmailException { Email email = new SimpleEmail(); email.setHostName(state.getProp(ConfigurationKeys.EMAIL_HOST_KEY, ConfigurationKeys.DEFAULT_EMAIL_HOST)); if (state.contains(ConfigurationKeys.EMAIL_SMTP_PORT_KEY)) { email.setSmtpPort(state.getPropAsInt(ConfigurationKeys.EMAIL_SMTP_PORT_KEY)); } email.setFrom(state.getProp(ConfigurationKeys.EMAIL_FROM_KEY)); if (state.contains(ConfigurationKeys.EMAIL_USER_KEY) && state.contains(ConfigurationKeys.EMAIL_PASSWORD_KEY)) { email.setAuthentication(state.getProp(ConfigurationKeys.EMAIL_USER_KEY), PasswordManager .getInstance(state).readPassword(state.getProp(ConfigurationKeys.EMAIL_PASSWORD_KEY))); } Iterable<String> tos = Splitter.on(',').trimResults().omitEmptyStrings() .split(state.getProp(ConfigurationKeys.EMAIL_TOS_KEY)); for (String to : tos) { email.addTo(to); } String hostName; try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException uhe) { LOGGER.error("Failed to get the host name", uhe); hostName = "unknown"; } email.setSubject(subject); String fromHostLine = String.format("This email was sent from host: %s%n%n", hostName); email.setMsg(fromHostLine + message); email.send(); }
From source file:org.jclouds.azurecompute.compute.functions.internal.OperatingSystems.java
public static Function<OSImage, String> version() { return new Function<OSImage, String>() { @Override/* w ww . jav a 2 s . c o m*/ public String apply(final OSImage osImage) { if (osImage.category().matches("Canonical|OpenLogic")) { return Iterables.get(Splitter.on(" ").split(osImage.label()), 2); } else if (osImage.category().matches(SUSE)) { if (osImage.label().startsWith(OPENSUSE)) { return osImage.label().substring(OPENSUSE.length() + 1); } if (osImage.label().startsWith(SUSE)) { return Iterables.get(Splitter.on("-").split(osImage.name()), 4); } } else if (osImage.category().matches(MICROSOFT)) { if (osImage.label().startsWith(WINDOWS_SERVER)) { return osImage.label().substring(WINDOWS_SERVER.length() + 1); } if (osImage.label().startsWith(MICROSOFT_SQL_SERVER)) { return osImage.label().substring(MICROSOFT_SQL_SERVER.length() + 1); } } else if (osImage.category().matches("RightScale with Linux|Public ")) { final Iterable<String> splittedLabel = Splitter.on("-").split(osImage.label()); if (Iterables.size(splittedLabel) > 2) { return Iterables.get(splittedLabel, 2); } } return null; } }; }
From source file:com.google.testing.security.firingrange.tests.reverseclickjacking.UniversalReverseClickjackingSinglePage.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { String parameterLocation, template; try {// w ww .j av a2s .co m parameterLocation = Splitter.on('/').splitToList(request.getPathInfo()).get(2); } catch (IndexOutOfBoundsException e) { // The parameter location is not set. Return 400 later. Responses.sendError(response, "Please specify the location of the vulnerable parameter.", 400); return; } String vulnerableParameter = Strings.nullToEmpty(request.getParameter(VULNERABLE_PARAMETER)); // Encode URL to prevent XSS vulnerableParameter = urlFormParameterEscaper().escape(vulnerableParameter); switch (parameterLocation) { case "ParameterInQuery": template = Templates.getTemplate("parameter_in_query.tmpl", getClass()); template = Templates.replacePayload(template, vulnerableParameter); break; case "ParameterInFragment": template = Templates.getTemplate("parameter_in_fragment.tmpl", getClass()); break; default: Responses.sendError(response, "Invalid location of the vulnerable parameter.", 400); return; } Responses.sendXssed(response, template); }
From source file:com.metamx.common.parsers.CSVParser.java
public CSVParser(final Optional<String> listDelimiter) { this.listDelimiter = listDelimiter.isPresent() ? listDelimiter.get() : Parsers.DEFAULT_LIST_DELIMITER; this.listSplitter = Splitter.on(this.listDelimiter); this.valueFunction = new Function<String, Object>() { @Override/*from w w w.j av a 2s.c o m*/ public Object apply(String input) { if (input.contains(CSVParser.this.listDelimiter)) { return Lists.newArrayList( Iterables.transform(listSplitter.split(input), ParserUtils.nullEmptyStringFunction)); } else { return ParserUtils.nullEmptyStringFunction.apply(input); } } }; }
From source file:org.dcache.xrootd.security.SecurityInfo.java
public SecurityInfo(String description) throws XrootdException { this.description = description; int comma = description.indexOf(','); if (comma == -1) { protocol = description.trim();// w ww.j a va2 s. c o m data = Collections.emptyMap(); } else { protocol = description.substring(0, comma); String keyValueData = description.substring(comma + 1); data = Splitter.on(',').omitEmptyStrings().withKeyValueSeparator(':').split(keyValueData); } if (protocol.isEmpty()) { throw new XrootdException(kXR_error, "Missing protocol name"); } }
From source file:com.google.devtools.build.android.aapt2.ProtoResourceUsageAnalyzer.java
private static Resource parse(ResourceUsageModel model, String resourceTypeAndName) { final Iterator<String> iterator = Splitter.on('/').split(resourceTypeAndName).iterator(); Preconditions.checkArgument(iterator.hasNext(), "%s invalid resource name", resourceTypeAndName); ResourceType resourceType = ResourceType.getEnum(iterator.next()); Preconditions.checkArgument(iterator.hasNext(), "%s invalid resource name", resourceTypeAndName); return model.getResource(resourceType, iterator.next()); }