Java 类org.apache.commons.fileupload.util.mime.MimeUtility 实例源码

项目:WidgetStore    文件:ParameterParser.java   
/**
 * Extracts a map of name/value pairs from the given array of
 * characters. Names are expected to be unique.
 *
 * @param charArray the array of characters that contains a sequence of
 * name/value pairs
 * @param offset - the initial offset.
 * @param length - the length.
 * @param separator the name/value pairs separator
 *
 * @return a map of name/value pairs
 */
public Map<String, String> parse(
    final char[] charArray,
    int offset,
    int length,
    char separator) {

    if (charArray == null) {
        return new HashMap<String, String>();
    }
    HashMap<String, String> params = new HashMap<String, String>();
    this.chars = charArray;
    this.pos = offset;
    this.len = length;

    String paramName = null;
    String paramValue = null;
    while (hasChar()) {
        paramName = parseToken(new char[] {
                '=', separator });
        paramValue = null;
        if (hasChar() && (charArray[pos] == '=')) {
            pos++; // skip '='
            paramValue = parseQuotedToken(new char[] {
                    separator });

            if (paramValue != null) {
                try {
                    paramValue = MimeUtility.decodeText(paramValue);
                } catch (UnsupportedEncodingException e) {
                    // let's keep the original value in this case
                }
            }
        }
        if (hasChar() && (charArray[pos] == separator)) {
            pos++; // skip separator
        }
        if ((paramName != null) && (paramName.length() > 0)) {
            if (this.lowerCaseNames) {
                paramName = paramName.toLowerCase(Locale.ENGLISH);
            }

            params.put(paramName, paramValue);
        }
    }
    return params;
}
项目:cim    文件:ParameterParser.java   
/**
 * Extracts a map of name/value pairs from the given array of
 * characters. Names are expected to be unique.
 *
 * @param chars the array of characters that contains a sequence of
 * name/value pairs
 * @param offset - the initial offset.
 * @param length - the length.
 * @param separator the name/value pairs separator
 *
 * @return a map of name/value pairs
 */
public Map<String, String> parse(
    final char[] chars,
    int offset,
    int length,
    char separator) {

    if (chars == null) {
        return new HashMap<String, String>();
    }
    HashMap<String, String> params = new HashMap<String, String>();
    this.chars = chars;
    this.pos = offset;
    this.len = length;

    String paramName = null;
    String paramValue = null;
    while (hasChar()) {
        paramName = parseToken(new char[] {
                '=', separator });
        paramValue = null;
        if (hasChar() && (chars[pos] == '=')) {
            pos++; // skip '='
            paramValue = parseQuotedToken(new char[] {
                    separator });

            if (paramValue != null) {
                try {
                    paramValue = MimeUtility.decodeText(paramValue);
                } catch (UnsupportedEncodingException e) {
                    // let's keep the original value in this case
                }
            }
        }
        if (hasChar() && (chars[pos] == separator)) {
            pos++; // skip separator
        }
        if ((paramName != null) && (paramName.length() > 0)) {
            if (this.lowerCaseNames) {
                paramName = paramName.toLowerCase(Locale.ENGLISH);
            }

            params.put(paramName, paramValue);
        }
    }
    return params;
}
项目:AndroidWebServ    文件:ParameterParser.java   
/**
 * Extracts a map of name/value pairs from the given array of
 * characters. Names are expected to be unique.
 *
 * @param chars the array of characters that contains a sequence of
 * name/value pairs
 * @param offset - the initial offset.
 * @param length - the length.
 * @param separator the name/value pairs separator
 *
 * @return a map of name/value pairs
 */
public Map<String, String> parse(
    final char[] chars,
    int offset,
    int length,
    char separator) {

    if (chars == null) {
        return new HashMap<String, String>();
    }
    HashMap<String, String> params = new HashMap<String, String>();
    this.chars = chars;
    this.pos = offset;
    this.len = length;

    String paramName = null;
    String paramValue = null;
    while (hasChar()) {
        paramName = parseToken(new char[] {
                '=', separator });
        paramValue = null;
        if (hasChar() && (chars[pos] == '=')) {
            pos++; // skip '='
            paramValue = parseQuotedToken(new char[] {
                    separator });

            if (paramValue != null) {
                try {
                    paramValue = MimeUtility.decodeText(paramValue);
                } catch (UnsupportedEncodingException e) {
                    // let's keep the original value in this case
                }
            }
        }
        if (hasChar() && (chars[pos] == separator)) {
            pos++; // skip separator
        }
        if ((paramName != null) && (paramName.length() > 0)) {
            if (this.lowerCaseNames) {
                paramName = paramName.toLowerCase(Locale.ENGLISH);
            }

            params.put(paramName, paramValue);
        }
    }
    return params;
}