]> git.basschouten.com Git - openhab-addons.git/blob
2d964f36fe24cebfa253206aed0025e8e6f5a052
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.folderwatcher.internal.api.util;
14
15 import java.io.UnsupportedEncodingException;
16 import java.net.URLEncoder;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19
20 /**
21  * The {@link HttpUtils} class contains metohdos related to HTTP(S).
22  * <p>
23  * Based on offical AWS example {@see https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-examples-using-sdks.html}
24  * 
25  * @author Alexandr Salamatov - Initial contribution
26  */
27 @NonNullByDefault
28 public class HttpUtils {
29     public static String urlEncode(String url, boolean keepPathSlash) throws HttpUtilException {
30         String encoded;
31         try {
32             encoded = URLEncoder.encode(url, "UTF-8");
33         } catch (UnsupportedEncodingException e) {
34             throw new HttpUtilException("UTF-8 encoding is not supported.", e);
35         }
36         if (keepPathSlash) {
37             encoded = encoded.replace("%2F", "/");
38         }
39         return encoded;
40     }
41 }