public final class

EntityUtils

extends Object
java.lang.Object
   ↳ org.apache.http.util.EntityUtils

Class Overview

Static helpers for dealing with HttpEntitys.

Summary

Public Methods
static void consume(HttpEntity entity)
Ensures that the entity content is fully consumed and the content stream, if exists, is closed.
static String getContentCharSet(HttpEntity entity)
Obtains character set of the entity, if known.
static String getContentMimeType(HttpEntity entity)
Obtains mime type of the entity, if known.
static byte[] toByteArray(HttpEntity entity)
Read the contents of an entity and return it as a byte array.
static String toString(HttpEntity entity, String defaultCharset)
Get the entity content as a String, using the provided default character set if none is found in the entity.
static String toString(HttpEntity entity)
Read the contents of an entity and return it as a String.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static void consume (HttpEntity entity)

Ensures that the entity content is fully consumed and the content stream, if exists, is closed.

Throws
IOException if an error occurs reading the input stream

public static String getContentCharSet (HttpEntity entity)

Obtains character set of the entity, if known.

Parameters
entity must not be null
Returns
  • the character set, or null if not found
Throws
ParseException if header elements cannot be parsed
IllegalArgumentException if entity is null

public static String getContentMimeType (HttpEntity entity)

Obtains mime type of the entity, if known.

Parameters
entity must not be null
Returns
  • the character set, or null if not found
Throws
ParseException if header elements cannot be parsed
IllegalArgumentException if entity is null

public static byte[] toByteArray (HttpEntity entity)

Read the contents of an entity and return it as a byte array.

Returns
  • byte array containing the entity content. May be null if getContent() is null.
Throws
IOException if an error occurs reading the input stream
IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE

public static String toString (HttpEntity entity, String defaultCharset)

Get the entity content as a String, using the provided default character set if none is found in the entity. If defaultCharset is null, the default "ISO-8859-1" is used.

Parameters
entity must not be null
defaultCharset character set to be applied if none found in the entity
Returns
  • the entity content as a String. May be null if getContent() is null.
Throws
ParseException if header elements cannot be parsed
IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE
IOException if an error occurs reading the input stream

public static String toString (HttpEntity entity)

Read the contents of an entity and return it as a String. The content is converted using the character set from the entity (if any), failing that, "ISO-8859-1" is used.

Returns
  • String containing the content.
Throws
ParseException if header elements cannot be parsed
IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE
IOException if an error occurs reading the input stream