Java URI Encode encodeUri(final String uri)

Here you can find the source of encodeUri(final String uri)

Description

URI encodes a path to comply with Subversion specification (according to rfc2396).

License

Open Source License

Parameter

Parameter Description
uri Path (or any string) to convert.

Return

String URL encoded using UTF-8.

Declaration

public static String encodeUri(final String uri) 

Method Source Code

//package com.java2s;
/*/*w ww . j a  va 2s  . c  o m*/
 * ====================================================================
 * Copyright (c) 2005-2012 sventon project. All rights reserved.
 *
 * This software is licensed as described in the file LICENSE, which
 * you should have received as part of this distribution. The terms
 * are also available at http://www.sventon.org.
 * If newer versions of this license are posted there, you may use a
 * newer version instead, at your option.
 * ====================================================================
 */

import java.net.URI;
import java.net.URISyntaxException;

public class Main {
    /**
     * URI encodes a path to comply with Subversion specification (according to rfc2396).
     *
     * @param uri Path (or any string) to convert.
     * @return String URL encoded using UTF-8.
     */
    public static String encodeUri(final String uri) {
        try {
            return new URI(null, null, uri, null).toASCIIString();
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e);
        }
    }
}

Related

  1. encode(String str, boolean fullUri)
  2. encode(String uri)
  3. encodeForURI(String uriPart)
  4. encodeIfNeeded(String uri)
  5. encodeUri(final URI uri)
  6. encodeURI(String s)
  7. encodeUri(String string)
  8. encodeURI(String uri)