public class HttpUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static String[] |
add(String[] sa,
String s)
Creates and returns a new array one entry longer, with a new value at the end.
|
static void |
discard(BufferedReader r)
Discards the contents of a
BufferedReader. |
static String |
read(BufferedReader r)
Returns the contents of a
BufferedReader as a String. |
static byte[] |
read(InputStream stream)
Reads an input stream until EOF.
|
static int |
readFully(InputStream stream)
Reads an input stream until EOF.
|
static String |
readHttpLine(InputStream in)
Returns a single line from a 8-bit
InputStream
(which is assumed to be ASCII). |
static Map<String,String[]> |
urlDecode(InputStream is)
URL decodes an input stream.
|
static Map<String,String[]> |
urlDecode(String urlEncodedData)
URL decodes a string into a
Map. |
static String[] |
urlDecodeToArray(InputStream is)
URL decodes an input stream.
|
static String[] |
urlDecodeToArray(String urlEncodedData)
Performs the same operation as
urlDecode(java.lang.String), except the
returned data is in an ordered array. |
static void |
urlEncode(ByteArrayOutputStream os,
byte[] buf)
URL encodes a single value, writing its value to
an output stream.
|
static byte[] |
urlEncode(Map<String,String> map)
URL encodes a
Map. |
static byte[] |
urlEncode(Map<String,String> map,
String encoding)
URL encodes a
Map. |
static byte[] |
urlEncode(String[] nvPairs)
URL encodes a series of parameters, using the
Strings are converted to the default platform encoding.
|
static byte[] |
urlEncode(String[] nvPairs,
String encoding)
URL encodes a series of parameters.
|
static InputStream |
wrapInputStream(InputStream stream,
MessageHeaders hl)
Returns a character reader for reading HTTP data.
|
public static int readFully(InputStream stream) throws IOException
IOExceptionpublic static byte[] read(InputStream stream) throws IOException
IOExceptionpublic static InputStream wrapInputStream(InputStream stream, MessageHeaders hl) throws IOException
InputStreamReader, wrapping
either a ChunkedInputStream or
LimitedInputStream, based on the supplied headers.
If the headers did not indicate data was being sent, returns
an input stream for reading the rest of the document.IOExceptionpublic static String readHttpLine(InputStream in) throws IOException
InputStream
(which is assumed to be ASCII).IOExceptionpublic static byte[] urlEncode(String[] nvPairs, String encoding) throws UnsupportedEncodingException
byte[] buf;
buf = HttpUtil.urlEncode(new String[] { "name1", "value1", "name2", "value2" });
results in the byte array:
"name1=value1&name2=value2"Strings are converted to bytes using the given encoding.
nvPairs - array of name-value pairs, must be
even in lengthencoding - Java encoding, or null to use the default encodingEasyHttpClient.doPostUrlEncoded(byte[])UnsupportedEncodingException - if the encoding is invalidpublic static byte[] urlEncode(String[] nvPairs)
public static void urlEncode(ByteArrayOutputStream os, byte[] buf)
public static byte[] urlEncode(Map<String,String> map, String encoding) throws UnsupportedEncodingException
Map.map - a name-value map of entries to encodeencoding - Java encoding, or null to use the default encodingEasyHttpClient.doPostUrlEncoded(byte[])UnsupportedEncodingException - if the encoding is invalidpublic static byte[] urlEncode(Map<String,String> map)
Map.map - a name-value map of entries to encodeEasyHttpClient.doPostUrlEncoded(byte[])
Strings are converted to the default platform encoding.public static String[] add(String[] sa, String s)
sa - existing arrays - new valuepublic static Map<String,String[]> urlDecode(String urlEncodedData)
Map.
Names without values are placed in the map, but given a
null value. For example:
foo&bar=&bazresults in a map with keys
foo, bar,
baz mapped to "".
If the same key appears more than once, it is added to the array.
This method will not throw exceptions
even if the data is irregular.urlEncodedData - data in the URL encoded formatIllegalArgumentException - if null data is passed inurlEncode(java.lang.String[], java.lang.String)public static Map<String,String[]> urlDecode(InputStream is) throws IOException
IOExceptionpublic static String[] urlDecodeToArray(InputStream is) throws IOException
IOExceptionpublic static String[] urlDecodeToArray(String urlEncodedData)
urlDecode(java.lang.String), except the
returned data is in an ordered array.public static void discard(BufferedReader r) throws IOException
BufferedReader.
If the reader is null, does nothing:
This is to facilitate the coding of cases when the data is of
no use to the client.IOExceptionpublic static String read(BufferedReader r) throws IOException
BufferedReader as a String.
By default, each line is appended with
System.getProperty("line.separator").
This may or may not be the original line termination character used.IllegalArgumentException - if the reader is nullIOExceptionCopyright © 2012. All Rights Reserved.