Example usage for java.util StringJoiner StringJoiner

List of usage examples for java.util StringJoiner StringJoiner

Introduction

In this page you can find the example usage for java.util StringJoiner StringJoiner.

Prototype

public StringJoiner(CharSequence delimiter) 

Source Link

Document

Constructs a StringJoiner with no characters in it, with no prefix or suffix , and a copy of the supplied delimiter .

Usage

From source file:info.archinnov.achilles.internals.codegen.meta.EntityMetaCodeGen.java

private MethodSpec buildStaticColumns(List<FieldMetaSignature> parsingResults, TypeName rawClassType) {
    StringJoiner joiner = new StringJoiner(",");
    parsingResults.stream()/* w ww  .ja va2  s . c  o m*/
            .filter(x -> (x.context.columnType == ColumnType.STATIC
                    || x.context.columnType == ColumnType.STATIC_COUNTER))
            .map(x -> Tuple2.of(x.context.cqlColumn, x.context.fieldName)).sorted(BY_CQL_NAME_COLUMN_SORTER)
            .map(x -> x._2()).forEach(x -> joiner.add(x));

    return MethodSpec.methodBuilder("getStaticColumns").addAnnotation(Override.class)
            .addModifiers(Modifier.PROTECTED).returns(propertyListType(rawClassType))
            .addStatement("return $T.asList($L)", ARRAYS, joiner.toString()).build();
}

From source file:org.wso2.identity.scenarios.commons.util.SSOUtil.java

/**
 * Post user consent to Consent page/*w ww. j a  v a  2 s  .  c  om*/
 *
 * @param response      HttpResponse to be referred for request sending.
 * @param commonAuthUrl commonauth URL
 * @param userAgent     user-Agent
 * @param referer       referer URL
 * @param httpClient    HttpClient to be used for request sending.
 * @param pastreCookie  'pastre' Cookie
 * @return response after submitting consent
 * @throws Exception
 */
public static HttpResponse sendPOSTConsentMessage(HttpResponse response, String commonAuthUrl, String userAgent,
        String referer, HttpClient httpClient, String pastreCookie) throws Exception {
    String redirectUrl = getRedirectUrlFromResponse(response);
    Map<String, String> queryParams = getQueryParams(redirectUrl);

    String sessionKey = queryParams.get(PARAM_SESSION_DATA_KEY);
    String mandatoryClaims = queryParams.get(PARAM_MANDATORY_CLAIMS);
    String requestedClaims = queryParams.get(PARAM_REQUESTED_CLAIMS);
    String consentRequiredClaims;

    if (isNotBlank(mandatoryClaims) && isNotBlank(requestedClaims)) {
        StringJoiner joiner = new StringJoiner(",");
        joiner.add(mandatoryClaims);
        joiner.add(requestedClaims);
        consentRequiredClaims = joiner.toString();
    } else if (isNotBlank(mandatoryClaims)) {
        consentRequiredClaims = mandatoryClaims;
    } else {
        consentRequiredClaims = requestedClaims;
    }

    String[] claims;
    if (isNotBlank(consentRequiredClaims)) {
        claims = consentRequiredClaims.split(",");
    } else {
        claims = new String[0];
    }

    HttpPost post = new HttpPost(commonAuthUrl);
    post.setHeader(HttpHeaders.USER_AGENT, userAgent);
    post.addHeader(HttpHeaders.REFERER, referer);
    post.addHeader(COOKIE, pastreCookie);
    List<NameValuePair> urlParameters = new ArrayList<>();

    for (int i = 0; i < claims.length; i++) {

        if (isNotBlank(claims[i])) {
            String[] claimMeta = claims[i].split("_", 2);
            if (claimMeta.length == 2) {
                urlParameters.add(new BasicNameValuePair("consent_" + claimMeta[0], "on"));
            }
        }
    }
    urlParameters.add(new BasicNameValuePair(PARAM_SESSION_DATA_KEY, sessionKey));
    urlParameters.add(new BasicNameValuePair("consent", "approve"));
    post.setEntity(new UrlEncodedFormEntity(urlParameters));
    return httpClient.execute(post);
}

From source file:info.archinnov.achilles.internals.codegen.meta.EntityMetaCodeGen.java

private MethodSpec buildComputedColumns(List<FieldMetaSignature> parsingResults, TypeName rawClassType) {
    StringJoiner joiner = new StringJoiner(",");
    parsingResults.stream().filter(x -> x.context.columnType == ColumnType.COMPUTED)
            .map(x -> Tuple2.of(((ComputedColumnInfo) x.context.columnInfo).alias, x.context.fieldName))
            .sorted(BY_CQL_NAME_COLUMN_SORTER).map(x -> x._2()).forEach(x -> joiner.add(x));

    return MethodSpec.methodBuilder("getComputedColumns").addAnnotation(Override.class)
            .addModifiers(Modifier.PROTECTED).returns(propertyListType(rawClassType))
            .addStatement("return $T.asList($L)", ARRAYS, joiner.toString()).build();
}

From source file:ca.osmcanada.osvuploadr.JPMain.java

private void SendAuthTokens(String accessToken, String accessSecret) {
    try {//from  w ww .  j  a  v  a 2s .  co m
        URL url = new URL(URL_ACCESS);
        URLConnection con = url.openConnection();
        HttpURLConnection http = (HttpURLConnection) con;
        http.setRequestMethod("POST"); // PUT is another valid option
        http.setDoOutput(true);

        Map<String, String> arguments = new HashMap<>();
        arguments.put("request_token", accessToken);
        arguments.put("secret_token", accessSecret);
        System.out.println("accessToken:" + accessToken + "|secret token:" + accessSecret);

        StringJoiner sj = new StringJoiner("&");
        for (Map.Entry<String, String> entry : arguments.entrySet())
            sj.add(URLEncoder.encode(entry.getKey(), "UTF-8") + "="
                    + URLEncoder.encode(entry.getValue(), "UTF-8"));
        byte[] out = sj.toString().getBytes(StandardCharsets.UTF_8);
        int length = out.length;

        http.setFixedLengthStreamingMode(length);
        http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        http.connect();
        try (OutputStream os = http.getOutputStream()) {
            os.write(out);
            os.close();
        }
        InputStream is = http.getInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        byte buf[] = new byte[1024];
        int letti;

        while ((letti = is.read(buf)) > 0)
            baos.write(buf, 0, letti);

        String data = new String(baos.toByteArray());
        http.disconnect();

    } catch (Exception ex) {
        Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:info.archinnov.achilles.internals.codegen.meta.EntityMetaCodeGen.java

private MethodSpec buildCounterColumns(List<FieldMetaSignature> parsingResults, TypeName rawClassType) {
    StringJoiner joiner = new StringJoiner(",");
    parsingResults.stream().filter(x -> x.context.columnType == COUNTER)
            .map(x -> Tuple2.of(x.context.cqlColumn, x.context.fieldName)).sorted(BY_CQL_NAME_COLUMN_SORTER)
            .map(x -> x._2()).forEach(x -> joiner.add(x));

    return MethodSpec.methodBuilder("getCounterColumns").addAnnotation(Override.class)
            .addModifiers(Modifier.PROTECTED).returns(propertyListType(rawClassType))
            .addStatement("return $T.asList($L)", ARRAYS, joiner.toString()).build();
}

From source file:info.archinnov.achilles.internals.codegen.meta.EntityMetaCodeGen.java

private MethodSpec buildNormalColumns(List<FieldMetaSignature> parsingResults, TypeName rawClassType) {
    StringJoiner joiner = new StringJoiner(",");
    parsingResults.stream().filter(x -> x.context.columnType == ColumnType.NORMAL)
            .map(x -> Tuple2.of(x.context.cqlColumn, x.context.fieldName)).sorted(BY_CQL_NAME_COLUMN_SORTER)
            .map(x -> x._2()).forEach(x -> joiner.add(x));

    return MethodSpec.methodBuilder("getNormalColumns").addAnnotation(Override.class)
            .addModifiers(Modifier.PROTECTED).returns(propertyListType(rawClassType))
            .addStatement("return $T.asList($L)", ARRAYS, joiner.toString()).build();
}

From source file:ca.osmcanada.osvuploadr.JPMain.java

private void SendFinished(long Sequence_id, String accessToken) {
    try {//from   w  w  w . j  a  va 2 s . com
        URL url = new URL(URL_FINISH);
        URLConnection con = url.openConnection();
        HttpURLConnection http = (HttpURLConnection) con;
        http.setRequestMethod("POST"); // PUT is another valid option
        http.setDoOutput(true);

        Map<String, String> arguments = new HashMap<>();
        arguments.put("access_token", accessToken);
        arguments.put("sequenceId", Long.toString(Sequence_id));
        System.out.println("accessToken:" + accessToken + "|sequenceId:" + Long.toString(Sequence_id));

        StringJoiner sj = new StringJoiner("&");
        for (Map.Entry<String, String> entry : arguments.entrySet())
            sj.add(URLEncoder.encode(entry.getKey(), "UTF-8") + "="
                    + URLEncoder.encode(entry.getValue(), "UTF-8"));
        byte[] out = sj.toString().getBytes(StandardCharsets.UTF_8);
        int length = out.length;

        http.setFixedLengthStreamingMode(length);
        http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        http.connect();
        try (OutputStream os = http.getOutputStream()) {
            os.write(out);
            os.close();
        }
        InputStream is = http.getInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        byte buf[] = new byte[1024];
        int letti;

        while ((letti = is.read(buf)) > 0)
            baos.write(buf, 0, letti);

        String data = new String(baos.toByteArray());
        http.disconnect();

    } catch (Exception ex) {
        Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ca.osmcanada.osvuploadr.JPMain.java

private long getSequence(ImageProperties imp, String accessToken) {
    try {//from ww  w. j a  va2s .  c  o m
        URL url = new URL(URL_SEQUENCE);
        URLConnection con = url.openConnection();
        HttpURLConnection http = (HttpURLConnection) con;
        http.setRequestMethod("POST"); // PUT is another valid option
        http.setDoOutput(true);

        DecimalFormat df = new DecimalFormat("#.##############");
        df.setRoundingMode(RoundingMode.CEILING);
        System.out.println("Getting Sequence ID..");
        Map<String, String> arguments = new HashMap<>();
        arguments.put("uploadSource", "OSVUploadr");
        arguments.put("access_token", accessToken);
        arguments.put("currentCoordinate", df.format(imp.getLatitude()) + "," + df.format(imp.getLongitude()));
        System.out.println(
                "currentCoordinate:" + df.format(imp.getLatitude()) + "," + df.format(imp.getLongitude()));
        StringJoiner sj = new StringJoiner("&");
        for (Map.Entry<String, String> entry : arguments.entrySet())
            sj.add(URLEncoder.encode(entry.getKey(), "UTF-8") + "="
                    + URLEncoder.encode(entry.getValue(), "UTF-8"));
        byte[] out = sj.toString().getBytes(StandardCharsets.UTF_8);
        int length = out.length;
        System.out.println("Sending request:" + sj.toString());

        http.setFixedLengthStreamingMode(length);
        http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        http.connect();
        try (OutputStream os = http.getOutputStream()) {
            os.write(out);
            os.close();
        }
        System.out.println("Request Sent getting sequence response...");
        InputStream is = http.getInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        byte buf[] = new byte[1024];
        int letti;

        while ((letti = is.read(buf)) > 0)
            baos.write(buf, 0, letti);

        String data = new String(baos.toByteArray());
        int start = data.indexOf("\"osv\":{\"sequence\":{\"id\":\"");
        int end = data.indexOf("\"", start + 25);
        System.out.println("Received request:" + data);
        String sequence_id = data.substring(start + 25, end);
        System.out.println("Obtained Sequence ID: sequence_id");
        http.disconnect();
        return Long.parseLong(sequence_id);

    } catch (Exception ex) {
        System.out.println(ex.toString());
        Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, null, ex);
    }
    return -1;
}

From source file:org.springframework.cloud.gcp.data.spanner.core.SpannerTemplate.java

private StringBuilder logColumns(String tableName, KeySet keys, Iterable<String> columns) {
    StringBuilder logSb = new StringBuilder(
            "Executing read on table " + tableName + " with keys: " + keys + " and columns: ");
    StringJoiner sj = new StringJoiner(",");
    columns.forEach((col) -> sj.add(col));
    logSb.append(sj.toString());//from   w  w  w.  ja  va  2 s.c o m
    return logSb;
}