List of usage examples for java.util.stream Collectors joining
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter)
From source file:ch.ifocusit.plantuml.utils.ClassUtils.java
public static String getParameterizedTypeName(ParameterizedType genericType) { // manage generics String subtypes = Stream.of(genericType.getActualTypeArguments()).map(ClassUtils::getSimpleName) .collect(Collectors.joining(GENERICS_SEP)); return GENERICS_OPEN + subtypes + GENERICS_CLOSE; }
From source file:org.fede.util.Util.java
public static <T> String list(Collection<T> elements, String separator) { return elements.stream().map(e -> e.toString()).collect(Collectors.joining(separator)); }
From source file:com.thoughtworks.go.server.service.CcTrayService.java
public Appendable renderCCTrayXML(String siteUrlPrefix, String userName, Appendable appendable, Consumer<String> etagConsumer) { boolean isSecurityEnabled = goConfigService.isSecurityEnabled(); List<ProjectStatus> statuses = ccTrayCache.allEntriesInOrder(); String hashCodes = statuses.stream().map(ProjectStatus::hashCode).map(Object::toString) .collect(Collectors.joining("/")); String etag = DigestUtils.sha256Hex(siteUrlPrefix + "/" + hashCodes); etagConsumer.accept(etag);/*from w ww . j av a 2 s .c o m*/ try { appendable.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); appendable.append("\n"); appendable.append("<Projects>"); appendable.append("\n"); for (ProjectStatus status : statuses) { if (!isSecurityEnabled || status.canBeViewedBy(userName)) { String xmlRepresentation = status.xmlRepresentation().replaceAll(ProjectStatus.SITE_URL_PREFIX, siteUrlPrefix); if (!StringUtils.isBlank(xmlRepresentation)) { appendable.append(" ").append(xmlRepresentation).append("\n"); } } } appendable.append("</Projects>"); } catch (IOException e) { // ignore. `StringBuilder#append` does not throw } return appendable; }
From source file:au.org.ncallister.goodbudget.tools.coms.GoodBudgetSession.java
public String get(String path, List<NameValuePair> parameters) throws URISyntaxException, IOException { URIBuilder builder = new URIBuilder(BASE_URI); builder.setPath(path);//from www . jav a 2 s . c o m builder.setParameters(parameters); HttpGet get = new HttpGet(builder.build()); CloseableHttpResponse response = client.execute(get, sessionContext); try { BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); return reader.lines().collect(Collectors.joining("\n")); } finally { response.close(); } }
From source file:org.ambraproject.wombat.service.remote.ApiAddress.java
private ApiAddress(Builder builder) { this.path = builder.pathTokens.stream().map(ApiAddress::encodePath).collect(Collectors.joining("/")); this.parameters = ImmutableList.copyOf(builder.parameters); }
From source file:com.blackducksoftware.integration.hub.detect.testutils.TestUtil.java
public String getResourceAsUTF8String(final String resourcePath) { final String data; try {/*from ww w . j a v a 2 s . co m*/ data = ResourceUtil.getResourceAsString(getClass(), resourcePath, StandardCharsets.UTF_8.toString()); } catch (final IOException e) { throw new RuntimeException(e); } return Arrays.asList(data.split("\r?\n")).stream().collect(Collectors.joining(System.lineSeparator())); }
From source file:net.kemitix.checkstyle.ruleset.builder.DefaultReadmeIndexBuilder.java
@Override public final String build() { return rulesProperties.getRules().stream().sorted(Comparator.comparing(lowerCaseRuleName())) .map(this::formatRuleRow).collect(Collectors.joining(NEWLINE)); }
From source file:enmasse.controller.flavor.FlavorManager.java
@Override public Flavor getFlavor(String flavorName, long timeoutInMillis) { long endTime = System.currentTimeMillis() + timeoutInMillis; Flavor flavor = null;//from w w w.jav a2 s . com try { do { flavor = flavorMap.get(flavorName); if (flavor == null) { Thread.sleep(1000); } } while (System.currentTimeMillis() < endTime && flavor == null); } catch (InterruptedException e) { log.warn("Interrupted while retrieving flavor"); } if (flavor == null) { String flavors = flavorMap.keySet().stream().collect(Collectors.joining(",")); throw new IllegalArgumentException( String.format("No flavor with name '%s' exists, have [%s]", flavorName, flavors)); } return flavor; }
From source file:org.trustedanalytics.servicebroker.gearpump.service.externals.helpers.ExternalProcessExecutor.java
public ExternalProcessExecutorResult run(String[] command, String workingDir, Map<String, String> properties) { String lineToRun = Arrays.asList(command).stream().collect(Collectors.joining(" ")); LOGGER.info("==================="); LOGGER.info("Command to invoke: {}", lineToRun); ProcessBuilder processBuilder = new ProcessBuilder(command); updateEnvOfProcessBuilder(processBuilder.environment(), properties); if (workingDir != null) { processBuilder.directory(new File(workingDir)); }/* ww w . j a va 2s . c o m*/ processBuilder.redirectErrorStream(true); StringBuilder processOutput = new StringBuilder(); Process process; BufferedReader stdout = null; try { process = processBuilder.start(); stdout = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = stdout.readLine()) != null) { LOGGER.debug(":::::: " + line); processOutput.append(line); processOutput.append('\n'); } try { process.waitFor(); } catch (InterruptedException e) { LOGGER.error("Command '" + lineToRun + "' interrupted.", e); } } catch (IOException e) { LOGGER.error("Problem executing external process.", e); return new ExternalProcessExecutorResult(Integer.MIN_VALUE, "", e); } finally { closeReader(stdout); } ExternalProcessExecutorResult result = new ExternalProcessExecutorResult(process.exitValue(), processOutput.toString(), null); LOGGER.info("Exit value: {}", result.getExitCode()); LOGGER.info("==================="); return result; }
From source file:it.greenvulcano.gvesb.api.security.JaxRsIdentityInfo.java
public JaxRsIdentityInfo(SecurityContext securityContext, Identity identity, String remoteAddress) { super();/*from w w w . ja va2 s. c o m*/ this.securityContext = securityContext; this.remoteAddress = remoteAddress; getAttributes().put("id", identity.getId().toString()); getAttributes().put("roles", identity.getRoles().stream().collect(Collectors.joining(","))); }