public final class EntityUtils
extends java.lang.Object
HttpEntity
s.Modifier and Type | Method and Description |
---|---|
static void |
consume(HttpEntity entity)
Ensures that the entity content is fully consumed and the content stream, if exists,
is closed.
|
static void |
consumeQuietly(HttpEntity entity)
Ensures that the entity content is fully consumed and the content stream, if exists,
is closed.
|
static java.lang.String |
getContentCharSet(HttpEntity entity)
Deprecated.
(4.1.3) use
ContentType.getOrDefault(HttpEntity) |
static java.lang.String |
getContentMimeType(HttpEntity entity)
Deprecated.
(4.1.3) use
ContentType.getOrDefault(HttpEntity) |
static byte[] |
toByteArray(HttpEntity entity)
Read the contents of an entity and return it as a byte array.
|
static java.lang.String |
toString(HttpEntity entity)
Read the contents of an entity and return it as a String.
|
static java.lang.String |
toString(HttpEntity entity,
java.nio.charset.Charset defaultCharset)
Get the entity content as a String, using the provided default character set
if none is found in the entity.
|
static java.lang.String |
toString(HttpEntity entity,
java.lang.String defaultCharset)
Get the entity content as a String, using the provided default character set
if none is found in the entity.
|
static void |
updateEntity(HttpResponse response,
HttpEntity entity)
Updates an entity in a response by first consuming an existing entity, then setting the new one.
|
public static void consumeQuietly(HttpEntity entity)
entity
- the entity to consume.public static void consume(HttpEntity entity) throws java.io.IOException
entity
- the entity to consume.java.io.IOException
- if an error occurs reading the input streampublic static void updateEntity(HttpResponse response, HttpEntity entity) throws java.io.IOException
response
- the response with an entity to update; must not be null.entity
- the entity to set in the response.java.io.IOException
- if an error occurs while reading the input stream on the existing
entity.java.lang.IllegalArgumentException
- if response is null.public static byte[] toByteArray(HttpEntity entity) throws java.io.IOException
entity
- the entity to read from=HttpEntity.getContent()
is null.java.io.IOException
- if an error occurs reading the input streamjava.lang.IllegalArgumentException
- if entity is null or if content length > Integer.MAX_VALUE@Deprecated public static java.lang.String getContentCharSet(HttpEntity entity) throws ParseException
ContentType.getOrDefault(HttpEntity)
entity
- must not be nullParseException
- if header elements cannot be parsedjava.lang.IllegalArgumentException
- if entity is null@Deprecated public static java.lang.String getContentMimeType(HttpEntity entity) throws ParseException
ContentType.getOrDefault(HttpEntity)
entity
- must not be nullParseException
- if header elements cannot be parsedjava.lang.IllegalArgumentException
- if entity is nullpublic static java.lang.String toString(HttpEntity entity, java.nio.charset.Charset defaultCharset) throws java.io.IOException, ParseException
entity
- must not be nulldefaultCharset
- character set to be applied if none found in the entity,
or if the entity provided charset is invalid or not available.HttpEntity.getContent()
is null.ParseException
- if header elements cannot be parsedjava.lang.IllegalArgumentException
- if entity is null or if content length > Integer.MAX_VALUEjava.io.IOException
- if an error occurs reading the input streamjava.nio.charset.UnsupportedCharsetException
- Thrown when the named entity's charset is not available in
this instance of the Java virtual machine and no defaultCharset is provided.public static java.lang.String toString(HttpEntity entity, java.lang.String defaultCharset) throws java.io.IOException, ParseException
entity
- must not be nulldefaultCharset
- character set to be applied if none found in the entityHttpEntity.getContent()
is null.ParseException
- if header elements cannot be parsedjava.lang.IllegalArgumentException
- if entity is null or if content length > Integer.MAX_VALUEjava.io.IOException
- if an error occurs reading the input streamjava.nio.charset.UnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic static java.lang.String toString(HttpEntity entity) throws java.io.IOException, ParseException
entity
- the entity to convert to a string; must not be nullParseException
- if header elements cannot be parsedjava.lang.IllegalArgumentException
- if entity is null or if content length > Integer.MAX_VALUEjava.io.IOException
- if an error occurs reading the input streamjava.nio.charset.UnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machine