Java URL Encode urlEncodeFilename(char[] input)

Here you can find the source of urlEncodeFilename(char[] input)

Description

This method encodes the URL, removes the spaces and brackets from the URL and replaces the same with "%20" and "%5B" and "%5D" and "%7B" "%7D".

License

Open Source License

Parameter

Parameter Description
input a parameter

Return

String

Declaration

public static String urlEncodeFilename(char[] input) 

Method Source Code

//package com.java2s;
/**//from   w  w w  .j a  v  a 2s. co m
 * Copyright (c) 2005-2006 Aptana, Inc.
 *
 * 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. If redistributing this code,
 * this entire header must remain intact.
 */

public class Main {
    /**
     * This method encodes the URL, removes the spaces and brackets from the URL and replaces the same with
     * <code>"%20"</code> and <code>"%5B" and "%5D"</code> and <code>"%7B" "%7D"</code>.
     * 
     * @param input
     * @return String
     * @since 3.0.2
     */
    public static String urlEncodeFilename(char[] input) {

        if (input == null) {
            return null;
        }

        StringBuffer retu = new StringBuffer(input.length);
        for (int i = 0; i < input.length; i++) {
            if (input[i] == ' ') {
                retu.append("%20"); //$NON-NLS-1$
            } else if (input[i] == '[') {
                retu.append("%5B"); //$NON-NLS-1$
            } else if (input[i] == ']') {
                retu.append("%5D"); //$NON-NLS-1$
            } else if (input[i] == '{') {
                retu.append("%7B"); //$NON-NLS-1$
            } else if (input[i] == '}') {
                retu.append("%7D"); //$NON-NLS-1$
            } else if (input[i] == '`') {
                retu.append("%60"); //$NON-NLS-1$
            } else if (input[i] == '+') {
                retu.append("%2B"); //$NON-NLS-1$
            } else {
                retu.append(input[i]);
            }
        }
        return retu.toString();
    }
}

Related

  1. URLencode(String s)
  2. urlEncode(String str)
  3. urlEncode(String str)
  4. urlEncode(String str)
  5. urlEncode(String urlPlain)
  6. URLEncodeFilePath(String s)
  7. urlEncodeForSpaces(String href)
  8. urlEncodeForSpaces(String input)
  9. urlEncodeForSpaces(String input)