Java URL Decode decodeArray(final String val)

Here you can find the source of decodeArray(final String val)

Description

Return a StringArray resulting from decoding the given String which should have been encoded by encodeArray

License

Apache License

Parameter

Parameter Description
val String value encoded by encodeArray

Return

String[] decoded value

Declaration

public static String[] decodeArray(final String val) 

Method Source Code

//package com.java2s;
/* ********************************************************************
Licensed to Jasig under one or more contributor license
agreements. See the NOTICE file distributed with this work
for additional information regarding copyright ownership.
Jasig licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a
copy of the License at:/*from w w w.  ja v a  2 s.  c  o m*/
    
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

import java.net.URLDecoder;

import java.util.ArrayList;

public class Main {
    /** Return a StringArray resulting from decoding the given String which
     * should have been encoded by encodeArray
     *
     * @param  val      String value encoded by encodeArray
     * @return String[] decoded value
     */
    public static String[] decodeArray(final String val) {
        if (val == null) {
            return null;
        }

        int len = val.length();

        if (len == 0) {
            return new String[0];
        }

        ArrayList<String> al = new ArrayList<String>();
        int i = 0;

        while (i < len) {
            int end = val.indexOf(" ", i);

            String s;
            if (end < 0) {
                s = val.substring(i);
                i = len;
            } else {
                s = val.substring(i, end);
                i = end + 1;
            }

            try {
                if (s.equals("\t")) {
                    al.add(null);
                } else {
                    al.add(URLDecoder.decode(s, "UTF-8"));
                }
            } catch (Throwable t) {
                throw new RuntimeException(t);
            }
        }

        return al.toArray(new String[al.size()]);
    }
}

Related

  1. decode(String value, String charset)
  2. decode(String value, String charset)
  3. decode(String value, String encoding)
  4. decodeAjax(String value)
  5. decodeAjaxParam(final String source)
  6. decodeCodedStr(String sourceStr, String targetCharset)
  7. decodeFormData(String formData)
  8. decodeHtmlString(String inputString)
  9. decodeIfNeeded(String s)