All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.camunda.identity.sdk.utility.UrlUtility Maven / Gradle / Ivy

The newest version!
/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
 * one or more contributor license agreements. Licensed under a proprietary license. See the
 * License.txt file for more information. You may not use this file except in compliance with the
 * proprietary license.
 */
package io.camunda.identity.sdk.utility;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class UrlUtility {
  public static String combinePaths(final String... paths) {
    return IntStream.range(0, paths.length)
      .filter(i -> paths[i] != null)
      .mapToObj(i -> {
        String path = paths[i];

        if (i > 0 && !path.isEmpty() && path.charAt(0) == '/') {
          path = path.substring(1);
        }

        if (i < paths.length - 1 && !path.isEmpty() && path.charAt(path.length() - 1) == '/') {
          path = path.substring(0, path.length() - 1);
        }

        return path;
      })
      .filter(path -> !path.isEmpty())
      .collect(Collectors.joining("/"));
  }

  public static String encodeQueryParameter(final String value) {
    return URLEncoder.encode(value, StandardCharsets.UTF_8);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy