org.eclipse.jetty.util.QuotedStringTokenizer Java Examples

The following examples show how to use org.eclipse.jetty.util.QuotedStringTokenizer. 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: JSON.java    From cmake4eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public void add(String name, Object value)
{
    try
    {
        if (c == 0)
            throw new IllegalStateException();
        _buffer.append(c);
        QuotedStringTokenizer.quote(_buffer,name);
        _buffer.append(':');
        append(_buffer,value);
        c = ',';
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #2
Source File: JSON.java    From cmake4eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public void add(String name, double value)
{
    try
    {
        if (c == 0)
            throw new IllegalStateException();
        _buffer.append(c);
        QuotedStringTokenizer.quote(_buffer,name);
        _buffer.append(':');
        appendNumber(_buffer,new Double(value));
        c = ',';
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #3
Source File: JSON.java    From cmake4eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public void add(String name, long value)
{
    try
    {
        if (c == 0)
            throw new IllegalStateException();
        _buffer.append(c);
        QuotedStringTokenizer.quote(_buffer,name);
        _buffer.append(':');
        appendNumber(_buffer, value);
        c = ',';
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #4
Source File: JSON.java    From cmake4eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public void add(String name, boolean value)
{
    try
    {
        if (c == 0)
            throw new IllegalStateException();
        _buffer.append(c);
        QuotedStringTokenizer.quote(_buffer,name);
        _buffer.append(':');
        appendBoolean(_buffer,value?Boolean.TRUE:Boolean.FALSE);
        c = ',';
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #5
Source File: HttpFields.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
/**
 * Get field value parameters. Some field values can have parameters. This method separates the
 * value from the parameters and optionally populates a map with the parameters. For example:
 * 
 * <PRE>
 * 
 * FieldName : Value ; param1=val1 ; param2=val2
 * 
 * </PRE>
 * 
 * @param value The Field value, possibly with parameteres.
 * @param parameters A map to populate with the parameters, or null
 * @return The value.
 */
public static String valueParameters(String value, Map<String,String> parameters)
{
    if (value == null) return null;

    int i = value.indexOf(';');
    if (i < 0) return value;
    if (parameters == null) return value.substring(0, i).trim();

    StringTokenizer tok1 = new QuotedStringTokenizer(value.substring(i), ";", false, true);
    while (tok1.hasMoreTokens())
    {
        String token = tok1.nextToken();
        StringTokenizer tok2 = new QuotedStringTokenizer(token, "= ");
        if (tok2.hasMoreTokens())
        {
            String paramName = tok2.nextToken();
            String paramVal = null;
            if (tok2.hasMoreTokens()) paramVal = tok2.nextToken();
            parameters.put(paramName, paramVal);
        }
    }

    return value.substring(0, i).trim();
}
 
Example #6
Source File: HttpFields.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
/**
 * Get field value parameters. Some field values can have parameters. This method separates the
 * value from the parameters and optionally populates a map with the parameters. For example:
 * 
 * <PRE>
 * 
 * FieldName : Value ; param1=val1 ; param2=val2
 * 
 * </PRE>
 * 
 * @param value The Field value, possibly with parameteres.
 * @param parameters A map to populate with the parameters, or null
 * @return The value.
 */
public static String valueParameters(String value, Map<String,String> parameters)
{
    if (value == null) return null;

    int i = value.indexOf(';');
    if (i < 0) return value;
    if (parameters == null) return value.substring(0, i).trim();

    StringTokenizer tok1 = new QuotedStringTokenizer(value.substring(i), ";", false, true);
    while (tok1.hasMoreTokens())
    {
        String token = tok1.nextToken();
        StringTokenizer tok2 = new QuotedStringTokenizer(token, "= ");
        if (tok2.hasMoreTokens())
        {
            String paramName = tok2.nextToken();
            String paramVal = null;
            if (tok2.hasMoreTokens()) paramVal = tok2.nextToken();
            parameters.put(paramName, paramVal);
        }
    }

    return value.substring(0, i).trim();
}
 
Example #7
Source File: JSON.java    From cmake4eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void appendMap(Appendable buffer, Map<?,?> map)
{
    try
    {
        if (map == null)
        {
            appendNull(buffer);
            return;
        }

        buffer.append('{');
        Iterator<?> iter = map.entrySet().iterator();
        while (iter.hasNext())
        {
            Map.Entry<?,?> entry = (Map.Entry<?,?>)iter.next();
            QuotedStringTokenizer.quote(buffer,entry.getKey().toString());
            buffer.append(':');
            append(buffer,entry.getValue());
            if (iter.hasNext())
                buffer.append(',');
        }

        buffer.append('}');
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #8
Source File: JSON.java    From cmake4eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void appendString(Appendable buffer, String string)
{
    if (string == null)
    {
        appendNull(buffer);
        return;
    }

    QuotedStringTokenizer.quote(buffer,string);
}