org.apache.tomcat.util.http.fileupload.util.mime.MimeUtility Java Examples

The following examples show how to use org.apache.tomcat.util.http.fileupload.util.mime.MimeUtility. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParameterParser.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * 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<>();
    }
    HashMap<String, String> params = new HashMap<>();
    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;
}
 
Example #2
Source File: ParameterParser.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: ParameterParser.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}