Class EntityUtils
- java.lang.Object
-
- org.apache.hc.core5.http.io.entity.EntityUtils
-
public final class EntityUtils extends java.lang.ObjectSupport methods forHttpEntity.- Since:
- 4.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidconsume(HttpEntity entity)Ensures that the entity content is fully consumed and the content stream, if exists, is closed.static voidconsumeQuietly(HttpEntity entity)Ensures that the entity content is fully consumed and the content stream, if exists, is closed.static java.util.List<NameValuePair>parse(HttpEntity entity)Deprecated.static java.util.List<NameValuePair>parse(HttpEntity entity, int maxStreamLength)Returns a list ofNameValuePairsas parsed from anHttpEntity.static byte[]toByteArray(HttpEntity entity)Deprecated.static byte[]toByteArray(HttpEntity entity, int maxResultLength)Reads the contents of an entity and return it as a byte array.static java.lang.StringtoString(HttpEntity entity)Deprecated.static java.lang.StringtoString(HttpEntity entity, int maxResultLength)Reads the contents of an entity and return it as a String.static java.lang.StringtoString(HttpEntity entity, java.lang.String defaultCharset)Gets the entity content as a String, using the provided default character set if none is found in the entity.static java.lang.StringtoString(HttpEntity entity, java.lang.String defaultCharset, int maxResultLength)Deprecated.static java.lang.StringtoString(HttpEntity entity, java.nio.charset.Charset defaultCharset)Deprecated.static java.lang.StringtoString(HttpEntity entity, java.nio.charset.Charset defaultCharset, int maxResultLength)Gets the entity content as a String, using the provided default character set if none is found in the entity.
-
-
-
Method Detail
-
consumeQuietly
public static void consumeQuietly(HttpEntity entity)
Ensures that the entity content is fully consumed and the content stream, if exists, is closed. The process is done, quietly , without throwing any IOException.- Parameters:
entity- the entity to consume, may be null.- Since:
- 4.2
-
consume
public static void consume(HttpEntity entity) throws java.io.IOException
Ensures that the entity content is fully consumed and the content stream, if exists, is closed.- Parameters:
entity- the entity to consume, may be null.- Throws:
java.io.IOException- if an error occurs reading the input stream.- Since:
- 4.1
-
toByteArray
@Deprecated public static byte[] toByteArray(HttpEntity entity) throws java.io.IOException
Deprecated.Reads the contents of an entity and return it as a byte array.- Parameters:
entity- the entity to read from=- Returns:
- byte array containing the entity content. May be null if
HttpEntity.getContent()is null. - Throws:
java.io.IOException- if an error occurs reading the input streamjava.lang.IllegalArgumentException- if the content length > Integer.MAX_VALUEjava.lang.NullPointerException- if the entity is null.
-
toByteArray
public static byte[] toByteArray(HttpEntity entity, int maxResultLength) throws java.io.IOException
Reads the contents of an entity and return it as a byte array.- Parameters:
entity- the entity to read from=maxResultLength- The maximum size of the String to return; use it to guard against unreasonable or malicious processing.- Returns:
- byte array containing the entity content. May be null if
HttpEntity.getContent()is null. - Throws:
java.io.IOException- if an error occurs reading the input streamjava.lang.IllegalArgumentException- if the content length > Integer.MAX_VALUEjava.lang.NullPointerException- if the entity is null.
-
toString
@Deprecated public static java.lang.String toString(HttpEntity entity, java.nio.charset.Charset defaultCharset) throws java.io.IOException, ParseException
Deprecated.Gets 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 "UTF-8" is used.- Parameters:
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.- Returns:
- the entity content as a String; may be null if
HttpEntity.getContent()is null. - Throws:
ParseException- if header elements cannot be parsedjava.lang.IllegalArgumentException- if the 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.java.lang.NullPointerException- if the entity is null.
-
toString
public static java.lang.String toString(HttpEntity entity, java.nio.charset.Charset defaultCharset, int maxResultLength) throws java.io.IOException, ParseException
Gets 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 "UTF-8" is used.- Parameters:
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.- Returns:
- the entity content as a String; may be null if
HttpEntity.getContent()is null. - Throws:
ParseException- if header elements cannot be parsedjava.lang.IllegalArgumentException- if the 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.java.lang.NullPointerException- if the entity is null.
-
toString
public static java.lang.String toString(HttpEntity entity, java.lang.String defaultCharset) throws java.io.IOException, ParseException
Gets 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 "UTF-8" is used.- Parameters:
entity- must not be nulldefaultCharset- character set to be applied if none found in the entity- Returns:
- the entity content as a String; may be null if
HttpEntity.getContent()is null. - Throws:
ParseException- if header elements cannot be parsedjava.lang.IllegalArgumentException- if the 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 machinejava.lang.NullPointerException- if the entity is null.
-
toString
@Deprecated public static java.lang.String toString(HttpEntity entity, java.lang.String defaultCharset, int maxResultLength) throws java.io.IOException, ParseException
Deprecated.Gets 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 "UTF-8" is used.- Parameters:
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.- Returns:
- the entity content as a String; may be null if
HttpEntity.getContent()is null. - Throws:
ParseException- if header elements cannot be parsedjava.lang.IllegalArgumentException- if the 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 machinejava.lang.NullPointerException- if the entity is null.
-
toString
@Deprecated public static java.lang.String toString(HttpEntity entity) throws java.io.IOException, ParseException
Deprecated.Reads 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, "UTF-8" is used.- Parameters:
entity- the entity to convert to a string; must not be null- Returns:
- the entity content as a String; may be null if
HttpEntity.getContent()is null. - Throws:
ParseException- if header elements cannot be parsedjava.lang.IllegalArgumentException- if the 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 machinejava.lang.NullPointerException- if the entity is null.
-
toString
public static java.lang.String toString(HttpEntity entity, int maxResultLength) throws java.io.IOException, ParseException
Reads 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, "UTF-8" is used.- Parameters:
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.- Returns:
- the entity content as a String; may be null if
HttpEntity.getContent()is null. - Throws:
ParseException- if header elements cannot be parsedjava.lang.IllegalArgumentException- the 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 machinejava.lang.NullPointerException- if the entity is null.
-
parse
@Deprecated public static java.util.List<NameValuePair> parse(HttpEntity entity) throws java.io.IOException
Deprecated.Returns a list ofNameValuePairsas parsed from anHttpEntity. The encoding is taken from the entity's Content-Encoding header.This is typically used while parsing an HTTP POST.
- Parameters:
entity- The entity to parse- Returns:
- a list of
NameValuePairas built from the URI's query portion. - Throws:
java.io.IOException- If there was an exception getting the entity's data.java.lang.NullPointerException- if the entity is null.
-
parse
public static java.util.List<NameValuePair> parse(HttpEntity entity, int maxStreamLength) throws java.io.IOException
Returns a list ofNameValuePairsas parsed from anHttpEntity. The encoding is taken from the entity's Content-Encoding header.This is typically used while parsing an HTTP POST.
- Parameters:
entity- The entity to parsemaxStreamLength- The maximum size of the stream to read; use it to guard against unreasonable or malicious processing.- Returns:
- a list of
NameValuePairas built from the URI's query portion. - Throws:
java.io.IOException- If there was an exception getting the entity's data.java.lang.NullPointerException- if the entity is null.
-
-