|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.noderunner.http.HttpUtil
public class HttpUtil
Contains utility functions for common HTTP I/O tasks.
Method Summary | |
---|---|
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 InputStream |
uncloseableInputStream(InputStream stream)
Returns a new input stream delegating to the given input stream that does nothing when closed. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static int readFully(InputStream stream) throws IOException
IOException
public static byte[] read(InputStream stream) throws IOException
IOException
public 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.
IOException
public static InputStream uncloseableInputStream(InputStream stream) throws IOException
IOException
public static String readHttpLine(InputStream in) throws IOException
InputStream
(which is assumed to be ASCII).
IOException
public 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 encoding
EasyHttpClient.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 encoding
EasyHttpClient.doPostUrlEncoded(byte[])
UnsupportedEncodingException
- if the encoding is invalidpublic static byte[] urlEncode(Map<String,String> map)
Map
.
map
- a name-value map of entries to encode
EasyHttpClient.doPostUrlEncoded(byte[])
Strings are converted to the default platform encoding.public static String[] add(String[] sa, String s)
sa
- existing arrays
- new value
public 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 format
IllegalArgumentException
- if null data is passed inurlEncode(java.lang.String[], java.lang.String)
public static Map<String,String[]> urlDecode(InputStream is) throws IOException
IOException
public static String[] urlDecodeToArray(InputStream is) throws IOException
IOException
public static String[] urlDecodeToArray(String urlEncodedData)
urlDecode(java.lang.String)
, except the
returned data is in an ordered array.
urlEncode(java.lang.String[], java.lang.String)
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.
IOException
public 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 null
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |