public class HurlStackConnection extends Object implements HttpConnection
HttpConnection
implementation using HttpURLConnection
.Constructor and Description |
---|
HurlStackConnection(String method,
String url,
boolean followRedirects,
boolean useCaches,
int connectTimeout,
int readTimeout) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the connection and frees all the allocated resources.
|
byte[] |
getServerResponseBody()
Gets the server response body.
|
int |
getServerResponseCode()
Gets the HTTP response code from the server.
|
void |
setHeaders(List<NameValue> requestHeaders,
boolean isFixedLengthStreamingMode,
long totalBodyBytes)
Set request headers.
|
void |
writeBody(byte[] bytes)
Write a byte array into the request body.
|
void |
writeBody(byte[] bytes,
int lengthToWriteFromStart)
Write a portion of a byte array into the request body.
|
public HurlStackConnection(String method, String url, boolean followRedirects, boolean useCaches, int connectTimeout, int readTimeout) throws IOException
IOException
public void setHeaders(List<NameValue> requestHeaders, boolean isFixedLengthStreamingMode, long totalBodyBytes) throws IOException
HttpConnection
setHeaders
in interface HttpConnection
requestHeaders
- request headers to setisFixedLengthStreamingMode
- true if the fixed length streaming mode must be used. If
it's false, chunked streaming mode has to be usedtotalBodyBytes
- total number of bytesIOException
- if an error occurs while setting request headerspublic void writeBody(byte[] bytes) throws IOException
HttpConnection
writeBody
in interface HttpConnection
bytes
- array with the bytes to writeIOException
- if an error occurs while writingpublic void writeBody(byte[] bytes, int lengthToWriteFromStart) throws IOException
HttpConnection
writeBody
in interface HttpConnection
bytes
- array with the bytes to writelengthToWriteFromStart
- how many bytes to write, starting from the first one in
the arrayIOException
- if an error occurs while writingpublic int getServerResponseCode() throws IOException
HttpConnection
getServerResponseCode
in interface HttpConnection
IOException
- if an error occurs while getting the server response codepublic byte[] getServerResponseBody() throws IOException
HttpConnection
getServerResponseBody
in interface HttpConnection
IOException
- if an error occurs while getting the server response bodypublic void close()
HttpConnection
close
in interface HttpConnection