Java URI Encode uriEncoding(String plainString)

Here you can find the source of uriEncoding(String plainString)

Description

uri Encoding

License

Open Source License

Declaration

public static String uriEncoding(String plainString) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    public static String uriEncoding(String plainString) {
        try {//  w w  w .j  ava2 s.co m
            URL url = new URL(plainString);
            URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                    url.getQuery(), url.getRef());
            return uri.toString();
        } catch (URISyntaxException | MalformedURLException e) {
            System.out.println("Utilities.uriEncoding(String plainString)\nError trying to encode " + plainString);
            return null;
        }
    }
}

Related

  1. encodeUriWithPrefix(String uri)
  2. uriEncode(Object o)
  3. uriEncode(String decoded)
  4. uriEncode(String input)
  5. uriEncodePath(String path)