public final class EntityUtils extends Object
HttpEntity
.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 List<NameValuePair> |
parse(HttpEntity entity)
Returns a list of
NameValuePairs as parsed from an HttpEntity . |
static List<NameValuePair> |
parse(HttpEntity entity,
int maxStreamLength)
Returns a list of
NameValuePairs as parsed from an HttpEntity . |
static byte[] |
toByteArray(HttpEntity entity)
Reads the contents of an entity and return it as a byte array.
|
static byte[] |
toByteArray(HttpEntity entity,
int maxResultLength)
Reads the contents of an entity and return it as a byte array.
|
static String |
toString(HttpEntity entity)
Reads the contents of an entity and return it as a String.
|
static String |
toString(HttpEntity entity,
Charset defaultCharset)
Gets the entity content as a String, using the provided default character set
if none is found in the entity.
|
static String |
toString(HttpEntity entity,
Charset defaultCharset,
int maxResultLength)
Gets the entity content as a String, using the provided default character set
if none is found in the entity.
|
static String |
toString(HttpEntity entity,
int maxResultLength)
Reads the contents of an entity and return it as a String.
|
static String |
toString(HttpEntity entity,
String defaultCharset)
Gets the entity content as a String, using the provided default character set
if none is found in the entity.
|
static String |
toString(HttpEntity entity,
String defaultCharset,
int maxResultLength)
Gets the entity content as a String, using the provided default character set
if none is found in the entity.
|
public static void consumeQuietly(HttpEntity entity)
entity
- the entity to consume.public static void consume(HttpEntity entity) throws IOException
entity
- the entity to consume.IOException
- if an error occurs reading the input streampublic static byte[] toByteArray(HttpEntity entity) throws IOException
entity
- the entity to read from=HttpEntity.getContent()
is null.IOException
- if an error occurs reading the input streamIllegalArgumentException
- if entity is null or if content length > Integer.MAX_VALUEpublic static byte[] toByteArray(HttpEntity entity, int maxResultLength) throws IOException
entity
- the entity to read from=maxResultLength
- The maximum size of the String to return; use it to guard against unreasonable or malicious processing.HttpEntity.getContent()
is null.IOException
- if an error occurs reading the input streamIllegalArgumentException
- if entity is null or if content length > Integer.MAX_VALUEpublic static String toString(HttpEntity entity, Charset defaultCharset) throws 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 parsedIllegalArgumentException
- if entity is null or if content length > Integer.MAX_VALUEIOException
- if an error occurs reading the input streamUnsupportedCharsetException
- 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 String toString(HttpEntity entity, Charset defaultCharset, int maxResultLength) throws 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.maxResultLength
- The maximum size of the String to return; use it to guard against unreasonable or malicious processing.HttpEntity.getContent()
is null.ParseException
- if header elements cannot be parsedIllegalArgumentException
- if entity is null or if content length > Integer.MAX_VALUEIOException
- if an error occurs reading the input streamUnsupportedCharsetException
- 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 String toString(HttpEntity entity, String defaultCharset) throws 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 parsedIllegalArgumentException
- if entity is null or if content length > Integer.MAX_VALUEIOException
- if an error occurs reading the input streamUnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic static String toString(HttpEntity entity, String defaultCharset, int maxResultLength) throws IOException, ParseException
entity
- must not be nulldefaultCharset
- character set to be applied if none found in the entitymaxResultLength
- The maximum size of the String to return; use it to guard against unreasonable or malicious processing.HttpEntity.getContent()
is null.ParseException
- if header elements cannot be parsedIllegalArgumentException
- if entity is null or if content length > Integer.MAX_VALUEIOException
- if an error occurs reading the input streamUnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic static String toString(HttpEntity entity) throws IOException, ParseException
entity
- the entity to convert to a string; must not be nullParseException
- if header elements cannot be parsedIllegalArgumentException
- if entity is null or if content length > Integer.MAX_VALUEIOException
- if an error occurs reading the input streamUnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic static String toString(HttpEntity entity, int maxResultLength) throws IOException, ParseException
entity
- the entity to convert to a string; must not be nullmaxResultLength
- The maximum size of the String to return; use it to guard against unreasonable or malicious processing.ParseException
- if header elements cannot be parsedIllegalArgumentException
- if entity is null or if content length > Integer.MAX_VALUEIOException
- if an error occurs reading the input streamUnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic static List<NameValuePair> parse(HttpEntity entity) throws IOException
NameValuePairs
as parsed from an HttpEntity
.
The encoding is taken from the entity's Content-Encoding header.
This is typically used while parsing an HTTP POST.
entity
- The entity to parseNameValuePair
as built from the URI's query portion.IOException
- If there was an exception getting the entity's data.public static List<NameValuePair> parse(HttpEntity entity, int maxStreamLength) throws IOException
NameValuePairs
as parsed from an HttpEntity
.
The encoding is taken from the entity's Content-Encoding header.
This is typically used while parsing an HTTP POST.
entity
- The entity to parsemaxStreamLength
- The maximum size of the stream to read; use it to guard against unreasonable or malicious processing.NameValuePair
as built from the URI's query portion.IOException
- If there was an exception getting the entity's data.Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.