Java URI Encode encodeURI(URI uri)

Here you can find the source of encodeURI(URI uri)

Description

encode URI

License

Open Source License

Declaration

public static String encodeURI(URI uri) 

Method Source Code


//package com.java2s;
/*/*from  w  ww.  j a  v a2  s.  c  o m*/
 * Copyright (c) 2015 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */

import java.io.UnsupportedEncodingException;
import java.net.URI;

import java.net.URLEncoder;

public class Main {
    public static String encodeURI(URI uri) {
        return encodeURI(uri.toString());
    }

    public static String encodeURI(String uri) {
        try {
            uri = URLEncoder.encode(uri, "UTF-8"); //$NON-NLS-1$
        } catch (UnsupportedEncodingException ex) {
            // UTF-8 should always be available.
        }

        return uri;
    }
}

Related

  1. encodeUri(String string)
  2. encodeURI(String uri)
  3. encodeUri(String uri)
  4. encodeUri(String uri)
  5. encodeUri(URI uri)
  6. encodeURIComponent(final String s)
  7. encodeURIComponent(String component)
  8. encodeURIComponent(String input)
  9. encodeURIComponent(String s, String charset)