Java URI Encode encodeURI(String uri)

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

Description

encode URI

License

Open Source License

Declaration

public static String encodeURI(String uri) throws URISyntaxException 

Method Source Code

//package com.java2s;
/*/*from  w  ww .j  av  a 2 s .  c o m*/
 * Created on Jun 14, 2004
 *
 * Paros and its related class files.
 * 
 * Paros is an HTTP/HTTPS proxy for assessing web application security.
 * Copyright (C) 2003-2004 Chinotec Technologies Company
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the Clarified Artistic License
 * as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * Clarified Artistic License for more details.
 * 
 * You should have received a copy of the Clarified Artistic License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

import java.net.URISyntaxException;

public class Main {
    public static String encodeURI(String uri) throws URISyntaxException {

        // ZAP: FindBugs fix - dont need sb
        //StringBuffer sb = new StringBuffer();
        String tmp = null;

        //try {
        //   tmp = URLEncoder.encode(uri, "8859_1");
        //} catch (UnsupportedEncodingException e) {
        //}

        tmp = uri.replaceAll(" ", "%20");
        tmp = tmp.replaceAll("<", "%3C");
        tmp = tmp.replaceAll(">", "%3E");
        tmp = tmp.replaceAll("'", "%27");
        tmp = tmp.replaceAll("\\x28", "%28"); // left bracket
        tmp = tmp.replaceAll("\\x29", "%29"); // right bracket
        tmp = tmp.replaceAll("\\x22", "%22"); // double quote

        return tmp;
    }
}

Related

  1. encodeIfNeeded(String uri)
  2. encodeUri(final String uri)
  3. encodeUri(final URI uri)
  4. encodeURI(String s)
  5. encodeUri(String string)
  6. encodeUri(String uri)
  7. encodeUri(String uri)
  8. encodeUri(URI uri)
  9. encodeURI(URI uri)