org.apache.http.entity
Class ContentType

java.lang.Object
  extended by org.apache.http.entity.ContentType

@Immutable
public final class ContentType
extends Object

Content type information consisting of a MIME type and an optional charset.

This class makes no attempts to verify validity of mime-type and charset attributes. The input parameters of the create(String, String) method, however, may not contain characters <">, <;>, <,> reserved by the HTTP specification.

Since:
4.2

Field Summary
static ContentType DEFAULT_BINARY
           
static ContentType DEFAULT_TEXT
           
 
Method Summary
static ContentType create(String mimeType, String charset)
          Creates a new instance of ContentType.
static ContentType get(HttpEntity entity)
          Extracts Content-Type value from HttpEntity exactly as specified by the Content-Type header of the entity.
 String getCharset()
           
 String getMimeType()
           
static ContentType getOrDefault(HttpEntity entity)
          Extracts Content-Type value from HttpEntity or returns default value if not explicitly specified.
static ContentType parse(String s)
          Parses textual representation of Content-Type value.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_TEXT

public static final ContentType DEFAULT_TEXT

DEFAULT_BINARY

public static final ContentType DEFAULT_BINARY
Method Detail

getMimeType

public String getMimeType()

getCharset

public String getCharset()

toString

public String toString()
Overrides:
toString in class Object

create

public static ContentType create(String mimeType,
                                 String charset)
Creates a new instance of ContentType.

Parameters:
mimeType - MIME type. It may not be null or empty. It may not contain characters <">, <;>, <,> reserved by the HTTP specification.
charset - charset. It may not contain characters <">, <;>, <,> reserved by the HTTP specification. This parameter is optional.
Returns:
content type

parse

public static ContentType parse(String s)
                         throws ParseException
Parses textual representation of Content-Type value.

Parameters:
s - text
Returns:
content type
Throws:
ParseException - if the given text does not represent a valid Content-Type value.

get

public static ContentType get(HttpEntity entity)
                       throws ParseException
Extracts Content-Type value from HttpEntity exactly as specified by the Content-Type header of the entity. Returns null if not specified.

Parameters:
entity - HTTP entity
Returns:
content type
Throws:
ParseException - if the given text does not represent a valid Content-Type value.

getOrDefault

public static ContentType getOrDefault(HttpEntity entity)
                                throws ParseException
Extracts Content-Type value from HttpEntity or returns default value if not explicitly specified.

Parameters:
entity - HTTP entity
Returns:
content type
Throws:
ParseException - if the given text does not represent a valid Content-Type value.


Copyright © 2005-2011 The Apache Software Foundation. All Rights Reserved.