public class HTTPConnectionHelper extends OutputStream
initRequest(URL, String, boolean, boolean) ByteArrayEncoderHTTP. The connection
switches to this status when the
initRequest(URL, String, boolean, boolean) is called. sendRequest() method changes the connection to this
status. readHttpResponse() is responsible to put the HttpConnectionHelper to
this status. initRequest(URL, String, boolean, boolean), to start a new request
to the server. Using the same HttpConnectionHelper allows to use the same
network connection, when the allowHttpPersistent applet parameter is used.
| Constructor and Description |
|---|
HTTPConnectionHelper(UploadPolicy uploadPolicy)
The standard constructor for this class.
|
HTTPConnectionHelper(URL url,
String method,
boolean bChunkEnabled,
boolean bLastChunk,
UploadPolicy uploadPolicy)
The standard constructor for this class.
|
| Modifier and Type | Method and Description |
|---|---|
HTTPConnectionHelper |
append(byte[] bytes)
Append bytes to the current query.
|
HTTPConnectionHelper |
append(byte[] bytes,
int off,
int len)
Append bytes to the current query.
|
HTTPConnectionHelper |
append(ByteArrayEncoder bae)
Appends a string to the current HTTP request.
|
HTTPConnectionHelper |
append(int b)
Append bytes to the current query.
|
HTTPConnectionHelper |
append(String str)
write a string to the current HTTP request.
|
void |
close()
This method is the override of
OutputStream.close() one. |
void |
dispose()
Releases all reserved resources.
|
void |
flush()
Flushes the output stream.
|
String |
getBoundary() |
ByteArrayEncoder |
getByteArrayEncoder()
Return the current
ByteArrayEncoder. |
PushbackInputStream |
getInputStream()
get the input stream, where HTTP server response can be read.
|
String |
getMethod()
Get the HTTP method (HEAD, POST, GET...)
|
OutputStream |
getOutputStream()
get the output stream, where HTTP data can be written.
|
String |
getResponseBody()
Get the last response body.
|
String |
getResponseHeaders()
Get the headers of the HTTP response.
|
String |
getResponseMsg()
Get the last response message.
|
String |
getStatusLabel()
Get the label describing the current state of this connection helper.
|
void |
initRequest(URL url,
String method,
boolean bChunkEnabled,
boolean bLastChunk)
The standard constructor for this class.
|
int |
readHttpResponse()
Read the response of the server.
|
void |
sendRequest()
Closes the byteArrayEncoder, create the socket (or not, depending on the
current uploadPolicy, and upload history), send the request, and create
the InputStream to read the server response.
|
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
public HTTPConnectionHelper(UploadPolicy uploadPolicy)
uploadPolicy - The current upload policy.public HTTPConnectionHelper(URL url, String method, boolean bChunkEnabled, boolean bLastChunk, UploadPolicy uploadPolicy) throws JUploadIOException
url - The target URLmethod - The HTTP method (POST, GET, HEAD...)bChunkEnabled - Indicates if chunkUpload is enabled for this query.
Put false, if non chunked request or if it is not relevant.bLastChunk - Indicates whether this chunk is the last one. Put true,
if non chunked request or if it is not relevant.uploadPolicy - The current upload policy.JUploadIOExceptionpublic void initRequest(URL url, String method, boolean bChunkEnabled, boolean bLastChunk) throws JUploadIOException
url - The target URLbChunkEnabled - Indicates if chunkUpload is enabled for this query.
Put false, if non chunked request or if it is not relevant.method - The HTTP method (POST, GET, HEAD...)bLastChunk - Indicates whether this chunk is the last one. Put true,
if non chunked request or if it is not relevant.JUploadIOExceptionpublic ByteArrayEncoder getByteArrayEncoder() throws JUploadIOException
ByteArrayEncoder. If it was not created, it is
initialized.ByteArrayEncoder, null if called before the
first initialization.JUploadIOExceptioninitRequest(URL, String, boolean, boolean)public String getBoundary()
public void sendRequest()
throws JUploadIOException
JUploadIOExceptionpublic void dispose()
throws JUploadIOException
JUploadIOExceptionpublic OutputStream getOutputStream()
public PushbackInputStream getInputStream()
public String getMethod()
public String getResponseBody()
public String getResponseHeaders()
public String getResponseMsg()
public String getStatusLabel()
public HTTPConnectionHelper append(int b) throws JUploadIOException
b - The byte to send to the server.JUploadIOExceptionpublic HTTPConnectionHelper append(byte[] bytes) throws JUploadIOException
bytes - The bytes to send to the server.JUploadIOExceptionpublic HTTPConnectionHelper append(byte[] bytes, int off, int len) throws JUploadIOException
bytes - The bytes to send to the server.off - The first byte to sendlen - Number of bytes to send.JUploadIOExceptionpublic HTTPConnectionHelper append(String str) throws JUploadIOException
str - The string to writeJUploadIOException - If any problem occurs during the writing
operation.append(byte[])public HTTPConnectionHelper append(ByteArrayEncoder bae) throws JUploadIOException
bae - The ByteArrayEncoder to write. It is expected to be correctly
encoded. That is: it is up to the caller to check that its
encoding is the same as the current HTTP request encoding.JUploadIOException - If any problem occurs during the writing
operation.append(byte[])public int readHttpResponse()
throws JUploadException
JUploadExceptionpublic void write(int b)
throws IOException
write in class OutputStreamIOExceptionpublic void write(byte[] b,
int off,
int len)
throws IOException
write in class OutputStreamIOExceptionpublic void write(byte[] b)
throws IOException
write in class OutputStreamIOExceptionpublic void close()
throws IOException
OutputStream.close() one. It may
not been called. You must use the sendRequest() or
readHttpResponse() methods instead.close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOExceptionOutputStream.close()public void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOExceptionOutputStream.flush()Copyright © 2012. All Rights Reserved.