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:net.kemitix.checkstyle.ruleset.builder.ReadmeWriter.java

private String readFile(final Path file) throws IOException {
    return Files.lines(file, StandardCharsets.UTF_8).collect(Collectors.joining(NEWLINE));
}

From source file:com.ethercamp.harmony.service.JsonRpcUsageService.java

private String generateCurlExample(String line) {
    final String[] arr = line.split(" ");
    final String method = arr[0];
    final String paramsString = Stream.of(arr).skip(1).map(i -> "\"0x0\"").collect(Collectors.joining(", "));

    return "curl -X POST --data '{\"jsonrpc\":\"2.0\",\"method\":\"" + method + "\",\"params\":[" + paramsString
            + "],\"id\":64}'";
}

From source file:com.ethercamp.harmony.keystore.FileSystemKeystore.java

/**
 * @return some loaded key or null//from   w  ww  .j  a  v  a  2 s . co m
 */
@Override
public ECKey loadStoredKey(String address, String password) throws RuntimeException {
    return getFiles().stream().filter(f -> hasAddressInName(address, f)).map(f -> {
        try {
            return Files.readAllLines(f.toPath()).stream().collect(Collectors.joining(""));
        } catch (IOException e) {
            throw new RuntimeException("Problem reading keystore file for address:" + address);
        }
    }).map(content -> keystoreFormat.fromKeystore(content, password)).findFirst().orElse(null);
}

From source file:com.homeadvisor.kafdrop.config.ServiceDiscoveryConfiguration.java

public Map<String, Object> serviceDetails(Integer serverPort) {
    Map<String, Object> details = new LinkedHashMap<>();

    Optional.ofNullable(infoEndpoint.invoke()).ifPresent(
            infoMap -> Optional.ofNullable((Map<String, Object>) infoMap.get("build")).ifPresent(buildInfo -> {
                details.put("serviceName", buildInfo.get("artifact"));
                details.put("serviceDescription", buildInfo.get("description"));
                details.put("serviceVersion", buildInfo.get("version"));
            }));//  w  w  w . j a  v  a  2  s.  c  om

    final String name = (String) details.getOrDefault("serviceName", "kafdrop");

    String host = null;
    try {
        host = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        host = "<unknown>";
    }

    details.put("id", Stream.of(name, host, UUID.randomUUID().toString()).collect(Collectors.joining("_")));
    details.put("name", name);
    details.put("host", host);
    details.put("jmxPort", JmxUtils.getJmxPort(environment));
    details.put("jmxHealthMBean", jmxDomain + ":name=" + healthCheckBeanName() + ",type="
            + ClassUtils.getShortName(HealthCheckConfiguration.HealthCheck.class));
    details.put("port", serverPort);

    return details;
}

From source file:io.fd.maintainer.plugin.parser.MaintainersParserTest.java

@Test
public void testParse() throws URISyntaxException, IOException, MaintainerMismatchException {
    final MaintainersParser parser = new MaintainersParser();

    final URL url = this.getClass().getResource("/maintainers");
    final String content = Files.readLines(new File(url.toURI()), StandardCharsets.UTF_8).stream()
            .collect(Collectors.joining(System.lineSeparator()));
    final List<ComponentInfo> maintainers = parser.parseMaintainers(content);
    assertTrue(!maintainers.isEmpty());/*w w w  .j  a va 2s. c om*/

    // tests couple of entries
    assertTrue(compare(maintainers.get(0), buildSystem()));
    assertTrue(compare(maintainers.get(1), buildSystemInternal()));
    assertTrue(compare(maintainers.get(2), doxygen()));
    assertTrue(compare(maintainers.get(3), dpdkDevelopmentPackaging()));
    assertTrue(compare(maintainers.get(4), infrastractureLibrary()));
    assertTrue(compare(maintainers.get(5), vlibLibrary()));
    assertTrue(compare(maintainers.get(6), vlibApiLibraries()));
    assertTrue(compare(maintainers.get(7), vnetBfd()));
    assertEquals(32, maintainers.size());
}

From source file:com.github.horrorho.inflatabledonkey.util.ProcessManager.java

void error(Process process) throws IOException {
    try (BufferedReader br = new BufferedReader(
            new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8))) {

        String error = br.lines().collect(Collectors.joining("\n"));
        if (!error.isEmpty()) {
            logger.warn("-- error() - error: {}", error);
        }//from  ww w  . j  a v  a 2 s  .  c  om
    }
}

From source file:com.codename1.tools.javadoc.sourceembed.javadocsourceembed.Main.java

public static void processFile(File javaSourceFile, File javaDestFile) throws Exception {
    System.out.println("JavaSource Processing: " + javaSourceFile.getName());
    List<String> lines = Files.readAllLines(Paths.get(javaSourceFile.toURI()), CHARSET);
    for (int iter = 0; iter < lines.size(); iter++) {
        String l = lines.get(iter);
        int position = l.indexOf("<script src=\"https://gist.github.com/");
        if (position > -1) {
            String id = l.substring(position + 39);
            id = id.split("/")[1];
            id = id.substring(0, id.indexOf('.'));
            String fileContent = gistCache.get(id);
            if (fileContent != null) {
                lines.add(iter + 1, fileContent);
                iter++;// w  w w  .  java2 s.c  o  m
                continue;
            }

            URL u = new URL("https://api.github.com/gists/" + id + "?client_id=" + CLIENT_ID + "&client_secret="
                    + CLIENT_SECRET);
            try (BufferedReader br = new BufferedReader(new InputStreamReader(u.openStream(), CHARSET))) {
                String jsonText = br.lines().collect(Collectors.joining("\n"));
                JSONObject json = new JSONObject(jsonText);
                JSONObject filesObj = json.getJSONObject("files");
                String str = "";
                for (String k : filesObj.keySet()) {
                    JSONObject jsonFileEntry = filesObj.getJSONObject(k);
                    // breaking line to fix the problem with a blank space on the first line
                    String current = "\n" + jsonFileEntry.getString("content");
                    str += current;
                }
                int commentStartPos = str.indexOf("/*");
                while (commentStartPos > -1) {
                    // we just remove the comment as its pretty hard to escape it properly
                    int commentEndPos = str.indexOf("*/");
                    str = str.substring(commentStartPos, commentEndPos + 1);
                    commentStartPos = str.indexOf("/*");
                }

                // allows things like the @Override annotation
                str = "<noscript><pre>{@code " + str.replace("@", "{@literal @}") + "}</pre></noscript>";
                gistCache.put(id, str);
                lines.add(iter + 1, str);
                iter++;
            }
        }
    }
    try (BufferedWriter fw = new BufferedWriter(new FileWriter(javaDestFile))) {
        for (String l : lines) {
            fw.write(l);
            fw.write('\n');
        }
    }
}

From source file:org.elasticsearch.xpack.ml.integration.DatafeedJobsRestIT.java

private void setupUser(String user, List<String> roles) throws IOException {
    String password = new String(SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING.getChars());

    String json = "{" + "  \"password\" : \"" + password + "\"," + "  \"roles\" : [ "
            + roles.stream().map(unquoted -> "\"" + unquoted + "\"").collect(Collectors.joining(", ")) + " ]"
            + "}";

    client().performRequest("put", "_xpack/security/user/" + user, Collections.emptyMap(),
            new StringEntity(json, ContentType.APPLICATION_JSON));
}

From source file:io.github.carlomicieli.footballdb.starter.pages.Table.java

private String rowsToString() {
    return rowsStream().map(Row::toString).collect(Collectors.joining(", "));
}

From source file:io.mindmaps.engine.loader.DistributedLoader.java

public void submitBatch(Collection<Var> batch) {
    String batchedString = batch.stream().map(Object::toString).collect(Collectors.joining(";"));

    if (batchedString.length() == 0) {
        return;/*from w  ww.jav  a 2  s .  co  m*/
    }

    HttpURLConnection currentConn = acquireNextHost();
    String query = REST.HttpConn.INSERT_PREFIX + batchedString;

    executePost(currentConn, query);

    int responseCode = getResponseCode(currentConn);
    if (responseCode != REST.HttpConn.HTTP_TRANSACTION_CREATED) {
        throw new HTTPException(responseCode);
    }

    markAsLoading(getResponseBody(currentConn));
    LOG.info("Transaction sent to host: " + hostsArray[currentHost]);

    if (future == null) {
        startCheckingStatus();
    }

    currentConn.disconnect();
}