|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ecebs.rtd.enabler.common.HttpUtils
public class HttpUtils
Simple class that provides methods to help in carrying out HTTP requests.
Field Summary | |
---|---|
static String |
CONTENT_TYPE_TEXT_PLAIN
Default content type |
Method Summary | |
---|---|
static void |
checkValidAndThrow(HttpURLConnection con)
Checks that the response code is equal to HttpURLConnection.HTTP_OK |
static void |
copy(InputStream inStream,
OutputStream outStream)
Common helper method to copy from an input stream to an output stream |
static byte[] |
read(URLConnection con)
Reads the response from the connection |
static String |
readString(URLConnection con)
Reads the response data as a UTF-8 string. |
static void |
write(URLConnection con,
byte[] toWrite)
Writes the specified data to the connection, closing the output stream when finished. |
static void |
write(URLConnection con,
byte[] toWrite,
String contentType)
Writes the specified data to the connection, closing the output stream when finished |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String CONTENT_TYPE_TEXT_PLAIN
Method Detail |
---|
public static void checkValidAndThrow(HttpURLConnection con) throws IOException
HttpURLConnection.HTTP_OK
con
- The connection to check the response code of
IOException
- Thrown if there was an error getting a response code,
or the response code was not HttpURLConnection.HTTP_OK
public static void write(URLConnection con, byte[] toWrite) throws IOException
write(URLConnection, byte[], String)
,
passing in CONTENT_TYPE_TEXT_PLAIN
as the content type.
con
- Connection to write data totoWrite
- Data to write
IOException
- Thrown if there was an error writing the datapublic static void write(URLConnection con, byte[] toWrite, String contentType) throws IOException
con
- Connection to write data totoWrite
- Data to writecontentType
- content type of the data
IOException
- Thrown if there was an error writing the datapublic static String readString(URLConnection con) throws IOException
con
- Connection to read the response from
IOException
- Thrown if there was an error while reading the responsepublic static byte[] read(URLConnection con) throws IOException
con
- Connection to read the response from
IOException
- Thrown if there was an error reading the responsepublic static void copy(InputStream inStream, OutputStream outStream) throws IOException
inStream
- Stream to read fromoutStream
- Stream to write to
IOException
- Thrown if there was an error reading/writing
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |