All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.red5.server.util.UrlQueryStringMap Maven / Gradle / Ivy

Go to download

Ant Media Server supports RTMP, RTSP, MP4, HLS, WebRTC, Adaptive Streaming, etc.

There is a newer version: 2.10.0
Show newest version
package org.red5.server.util;

import java.util.HashMap;

/**
 * Simple query string to map converter.
 *
 * @param 
 *            key
 * @param 
 *            value
 * 
 * @author Paul Gregoire
 */
@SuppressWarnings("serial")
public final class UrlQueryStringMap extends HashMap {

    public UrlQueryStringMap() {
        super();
    }

    /**
     * Parse a given query string and return an instance of this class.
     * 
     * @param queryString
     *            query string
     * @return query string items as map entries
     */
    public static UrlQueryStringMap parse(String queryString) {
        UrlQueryStringMap map = new UrlQueryStringMap();
        //
        String tmp = queryString;
        //check if we start with '?' or not
        if (queryString.charAt(0) != '?') {
            tmp = queryString.split("\\?")[1];
        } else if (queryString.charAt(0) == '?') {
            tmp = queryString.substring(1);
        }
        //now break up into key/value blocks
        String[] kvs = tmp.split("&");
        //take each key/value block and break into its key value parts
        for (String kv : kvs) {
            String[] split = kv.split("=");
            map.put(split[0], split[1]);
        }
        return map;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy