Example usage for java.util.stream Collectors joining

List of usage examples for java.util.stream Collectors joining

Introduction

In this page you can find the example usage for java.util.stream Collectors joining.

Prototype

public static Collector<CharSequence, ?, String> joining(CharSequence delimiter) 

Source Link

Document

Returns a Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.

Usage

From source file:com.github.horrorho.inflatabledonkey.requests.AuthorizeGetRequestFactory.java

public Optional<HttpUriRequest> newRequest(String dsPrsID, String contentBaseUrl, String container, String zone,
        CloudKit.FileTokens fileTokens) {

    if (fileTokens.getFileTokensCount() == 0) {
        return Optional.empty();
    }/*from w w  w.j av  a  2 s  . c o m*/

    CloudKit.FileToken base = fileTokens.getFileTokens(0);

    String mmcsAuthToken = Stream
            .of(Hex.encodeHexString(base.getFileChecksum().toByteArray()),
                    Hex.encodeHexString(base.getFileSignature().toByteArray()), base.getToken())
            .collect(Collectors.joining(" "));

    ByteArrayEntity byteArrayEntity = new ByteArrayEntity(fileTokens.toByteArray());

    String uri = contentBaseUrl + "/" + dsPrsID + "/authorizeGet";

    HttpUriRequest request = RequestBuilder.post(uri)
            .addHeader(Headers.ACCEPT.header("application/vnd.com.apple.me.ubchunk+protobuf"))
            .addHeader(Headers.CONTENTTYPE.header("application/vnd.com.apple.me.ubchunk+protobuf"))
            .addHeader(Headers.XAPPLEMMCSDATACLASS.header("com.apple.Dataclass.CloudKit"))
            .addHeader(Headers.XAPPLEMMCSAUTH.header(mmcsAuthToken))
            .addHeader(Headers.XAPPLEMMEDSID.header(dsPrsID))
            .addHeader(Headers.XCLOUDKITCONTAINER.header(container))
            .addHeader(Headers.XCLOUDKITZONES.header(zone)).addHeader(headers.get(Headers.USERAGENT))
            .addHeader(headers.get(Headers.XAPPLEMMCSPROTOVERSION))
            .addHeader(headers.get(Headers.XMMECLIENTINFO)).setEntity(byteArrayEntity).build();

    return Optional.of(request);
}

From source file:net.kemitix.checkstyle.ruleset.builder.CheckstyleWriter.java

private void writeCheckstyleFile(@NonNull final RuleLevel ruleLevel) {
    val xmlFile = outputProperties.getDirectory().resolve(outputProperties.getRulesetFiles().get(ruleLevel));
    val checkerRules = rulesProperties.getRules().stream().filter(Rule::isEnabled)
            .filter(rule -> RuleParent.CHECKER.equals(rule.getParent()))
            .filter(rule -> ruleLevel.compareTo(rule.getLevel()) >= 0).map(this::formatRuleAsModule)
            .collect(Collectors.joining(NEWLINE));
    val treeWalkerRules = rulesProperties.getRules().stream().filter(Rule::isEnabled)
            .filter(rule -> RuleParent.TREEWALKER.equals(rule.getParent()))
            .filter(rule -> ruleLevel.compareTo(rule.getLevel()) >= 0).map(this::formatRuleAsModule)
            .collect(Collectors.joining(NEWLINE));
    try {/* w w  w .j a  va  2s  .  c om*/
        val checkstyleXmlTemplate = templateProperties.getCheckstyleXml();
        if (checkstyleXmlTemplate.toFile().exists()) {
            val bytes = Files.readAllBytes(checkstyleXmlTemplate);
            val template = new String(bytes, StandardCharsets.UTF_8);
            val output = Arrays.asList(String.format(template, checkerRules, treeWalkerRules).split(NEWLINE));
            log.info("Writing xmlFile: {}", xmlFile);
            Files.write(xmlFile, output, StandardCharsets.UTF_8);
        } else {
            throw new IOException("Missing template: " + checkstyleXmlTemplate.toString());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.vsct.dt.hesperides.indexation.command.IndexNewTemplateCommandBulk.java

@Override
public Void index(final ElasticSearchClient elasticSearchClient) {
    String body;//w w w .  ja  v  a  2  s. c om
    List<SingleToBulkMapper> propertiesAsString;

    LOGGER.info("Index {} templates.", templates.size());

    propertiesAsString = templates.stream().map(template -> {
        LOGGER.info("Index template with namespace {}.", template.getNamespace());

        try {
            return new SingleToBulkMapper(template.getId(),
                    ElasticSearchMappers.TEMPLATE_WRITER.writeValueAsString(template));
        } catch (final JsonProcessingException e) {
            LOGGER.error("Could not serialize template " + template);
            throw new RuntimeException(e);
        }
    }).collect(Collectors.toList());

    if (propertiesAsString != null && propertiesAsString.size() > 0) {
        body = propertiesAsString.stream().map(template -> template.toString()).collect(Collectors.joining(""));

        ElasticSearchEntity<TemplateIndexation> entity = elasticSearchClient
                .withResponseReader(ElasticSearchMappers.ES_ENTITY_TEMPLATE_READER)
                .post("/templates/_bulk", body);

        LOGGER.info("Successfully indexed new templates {}", propertiesAsString.size());
    }
    return null;
}

From source file:org.fenixedu.start.controller.StartController.java

@RequestMapping(value = "/webapp.txt", method = RequestMethod.POST)
@ResponseBody//from w w  w .java2s. co m
String webappText(@ModelAttribute ProjectRequest request) throws IOException, PebbleException {
    return projectService.buildWebapp(request).entrySet().stream()
            .map(entry -> "Path: " + entry.getKey() + "\nValue:\n" + new String(entry.getValue()))
            .collect(Collectors.joining("\n\n---------\n\n"));
}

From source file:com.github.robozonky.app.runtime.LivenessCheck.java

@Override
protected String getLatestSource() {
    logger.trace("Running.");
    // need to send parsed version, since the object itself changes every time due to currentApiTime field
    return Try.withResources(() -> UrlUtil.open(new URL(url))).of(s -> {
        final String source = IOUtils.readLines(s, Defaults.CHARSET).stream()
                .collect(Collectors.joining(System.lineSeparator()));
        logger.trace("API info coming from Zonky: {}.", source);
        return read(source);
    }).getOrElseGet(ex -> {//  w  w w  . ja  v  a  2  s.  com
        // don't propagate this exception as it is likely to happen and the calling code would WARN about it
        logger.debug("Zonky servers are likely unavailable.", ex);
        return null; // will fail during transform()
    });
}

From source file:fi.helsinki.moodi.service.importing.MoodleCourseBuilder.java

private String getDescription(OodiCourseUnitRealisation oodiCourseUnitRealisation, String language) {
    return oodiCourseUnitRealisation.descriptions.stream().map(d -> getTranslation(d.texts, language))
            .collect(Collectors.joining(" "));
}

From source file:net.sf.jabref.collab.MetaDataChange.java

@Override
public JComponent description() {
    StringBuilder sb = new StringBuilder(
            "<html>" + Localization.lang("Changes have been made to the following metadata elements")
                    + ":<p><br>&nbsp;&nbsp;");
    sb.append(changes.stream().map(unit -> unit.key).collect(Collectors.joining("<br>&nbsp;&nbsp;")));
    sb.append("</html>");
    tp.setText(sb.toString());//from w w w .ja va2 s  .  com
    return sp;
}

From source file:com.teradata.benchto.driver.loader.AnnotatedQueryParser.java

public Query parseLines(String queryName, List<String> lines) {
    lines = lines.stream().map(line -> line.trim()).collect(toList());

    Map<String, String> properties = new HashMap<>();
    for (String line : lines) {
        if (isPropertiesLine(line)) {
            Map<String, String> lineProperties = parseLineProperties(line);
            Map<String, ValueDifference<String>> difference = difference(properties, lineProperties)
                    .entriesDiffering();
            checkState(difference.isEmpty(), "Different properties: ", difference);
            properties.putAll(lineProperties);
        }//w ww.j  a va 2  s  .c o  m
    }

    String contentFiltered = lines.stream().filter(this::isNotCommentLine).collect(Collectors.joining("\n"));
    return new Query(queryName, contentFiltered, properties);
}

From source file:com.vsct.dt.hesperides.indexation.command.IndexNewPlatformCommandBulk.java

@Override
public Void index(final ElasticSearchClient elasticSearchClient) {
    String body;//from  ww  w  . ja  v a  2s  . co m
    List<SingleToBulkMapper> propertiesAsString;

    LOGGER.info("Index {} platforms.", platforms.size());

    propertiesAsString = platforms.stream().map(platform -> {
        try {
            LOGGER.info("Index platform with name {}-{}-{}.", platform.getApplicationName(),
                    platform.getPlatformName(), platform.getApplicationVersion());

            return new SingleToBulkMapper(platform.getId(),
                    ElasticSearchMappers.PLATFORM_WRITER.writeValueAsString(platform));
        } catch (final JsonProcessingException e) {
            LOGGER.error("Could not serialize platform " + platform);
            throw new RuntimeException(e);
        }
    }).collect(Collectors.toList());

    if (propertiesAsString != null && propertiesAsString.size() > 0) {
        body = propertiesAsString.stream().map(platform -> platform.toString()).collect(Collectors.joining(""));

        ElasticSearchEntity<PlatformIndexation> entity = elasticSearchClient
                .withResponseReader(ElasticSearchMappers.ES_ENTITY_PLATFORM_READER)
                .post("/platforms/_bulk", body);

        LOGGER.info("Successfully indexed new platform {}", propertiesAsString.size());
    }
    return null;
}

From source file:de.javagl.jgltf.model.io.JsonError.java

/**
 * Returns a short string representation of the {@link #getJsonPath()}
 * /*from w  w w. ja  v  a  2s . c om*/
 * @return The string
 */
public String getJsonPathString() {
    return jsonPath.stream().collect(Collectors.joining("."));
}