FileDocCategorySizeDatePackage
ContentType.javaAPI DocExample4010Tue May 29 16:57:14 BST 2007com.sun.xml.ws.transport.tcp.util

ContentType

public final class ContentType extends Object
author
Alexey Stashok

Fields Summary
private String
mimeType
private final Map
parameters
Constructors Summary
public ContentType()

    
      
    
Methods Summary
public booleanequals(java.lang.Object o)

        if (o != null && o instanceof ContentType) {
            ContentType ctToCompare = (ContentType) o;
            return ctToCompare.mimeType == mimeType && ctToCompare.parameters.equals(parameters);
        }
        
        return false;
    
public java.lang.StringgetMimeType()

        return mimeType;
    
public java.util.MapgetParameters()

        return parameters;
    
public inthashCode()

        return mimeType.hashCode() ^ parameters.hashCode();
    
public voidparse(java.lang.String contentType)

        parameters.clear();
        
        final int mimeDelim = contentType.indexOf(';");
        if (mimeDelim == -1) { // If the contentType doesn't have params
            mimeType = contentType.trim().toLowerCase();
            return;
        } else {
            mimeType = contentType.substring(0, mimeDelim).trim().toLowerCase();
        }
        
        int delim = mimeDelim + 1;
        // Scan ContentType string's params, decode them
        while(delim < contentType.length()) {
            int nextDelim = contentType.indexOf(';", delim);
            if (nextDelim == -1) nextDelim = contentType.length();
            
            int eqDelim = contentType.indexOf('=", delim);
            if (eqDelim == -1) eqDelim = nextDelim;
            
            final String key = contentType.substring(delim, eqDelim).trim();
            final String value = contentType.substring(eqDelim + 1, nextDelim).trim();
            parameters.put(key, value);
            
            delim = nextDelim + 1;
        }