wjhk.jupload2.upload.helper
Class HTTPInputStreamReader

java.lang.Object
  extended by wjhk.jupload2.upload.helper.HTTPInputStreamReader

public class HTTPInputStreamReader
extends java.lang.Object

A helper, to read the response coming from the server.

Author:
etienne_sf

Field Summary
private  byte[] body
           
private  java.lang.String charset
           
private  byte[] chunkbuf
           
private static int CHUNKBUF_SIZE
           
private  int clen
           
private  CookieJar cookies
           
private  boolean gotChunked
           
(package private)  boolean gotClose
           
private  boolean gotContentLength
           
private  HTTPConnectionHelper httpConnectionHelper
           
private  int httpStatusCode
          The server HTTP response.
private  java.lang.String line
           
private static java.util.regex.Pattern pChunked
           
private static java.util.regex.Pattern pClose
           
private static java.util.regex.Pattern pContentLen
           
private static java.util.regex.Pattern pContentTypeCs
           
private static java.util.regex.Pattern pHttpStatus
           
private static java.util.regex.Pattern pProxyClose
           
private static java.util.regex.Pattern pSetCookie
           
(package private)  java.lang.String responseBody
          Contains the HTTP response body, that is: the server response, without the headers.
(package private)  java.lang.String responseHeaders
          The headers of the HTTP response.
(package private)  java.lang.String responseMsg
          The status message from the first line of the response (e.g. "200 OK").
private  UploadPolicy uploadPolicy
          The current upload policy, always useful.
 
Constructor Summary
HTTPInputStreamReader(HTTPConnectionHelper httpConnectionHelper, UploadPolicy uploadPolicy)
          The standard constructor: does nothing !
 
Method Summary
(package private) static byte[] byteAppend(byte[] buf1, byte[] buf2)
          Concatenates two byte arrays.
(package private) static byte[] byteAppend(byte[] buf1, byte[] buf2, int len)
          Concatenates two byte arrays.
 int gethttpStatusCode()
          Return the last read http response (200, in case of success).
 java.lang.String getResponseBody()
          Get the last response body.
 java.lang.String getResponseHeaders()
          Get the headers of the HTTP response.
 java.lang.String getResponseMsg()
          Get the last response message.
private  void readBody(java.io.PushbackInputStream httpDataIn)
          Read the body from the given input stream.
private  void readHeaders(java.io.PushbackInputStream httpDataIn)
          Read the headers from the given input stream.
 int readHttpResponse()
          The main method: reads the response in the input stream.
static byte[] readLine(java.io.PushbackInputStream inputStream, boolean includeCR)
          Similar like BufferedInputStream#readLine() but operates on raw bytes.
static java.lang.String readLine(java.io.PushbackInputStream inputStream, java.lang.String charset, boolean includeCR)
          Similar like BufferedInputStream#readLine() but operates on raw bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

uploadPolicy

private UploadPolicy uploadPolicy
The current upload policy, always useful.


httpConnectionHelper

private HTTPConnectionHelper httpConnectionHelper

responseBody

java.lang.String responseBody
Contains the HTTP response body, that is: the server response, without the headers.


responseHeaders

java.lang.String responseHeaders
The headers of the HTTP response.


responseMsg

java.lang.String responseMsg
The status message from the first line of the response (e.g. "200 OK").


cookies

private CookieJar cookies

gotClose

boolean gotClose

gotChunked

private boolean gotChunked

gotContentLength

private boolean gotContentLength

clen

private int clen

httpStatusCode

private int httpStatusCode
The server HTTP response. Should be 200, in case of success.


line

private java.lang.String line

body

private byte[] body

charset

private java.lang.String charset

CHUNKBUF_SIZE

private static final int CHUNKBUF_SIZE
See Also:
Constant Field Values

chunkbuf

private final byte[] chunkbuf

pChunked

private static final java.util.regex.Pattern pChunked

pClose

private static final java.util.regex.Pattern pClose

pProxyClose

private static final java.util.regex.Pattern pProxyClose

pHttpStatus

private static final java.util.regex.Pattern pHttpStatus

pContentLen

private static final java.util.regex.Pattern pContentLen

pContentTypeCs

private static final java.util.regex.Pattern pContentTypeCs

pSetCookie

private static final java.util.regex.Pattern pSetCookie
Constructor Detail

HTTPInputStreamReader

public HTTPInputStreamReader(HTTPConnectionHelper httpConnectionHelper,
                             UploadPolicy uploadPolicy)
The standard constructor: does nothing ! Oh yes, it initialize some attribute from the given parameter... :-)

Parameters:
httpConnectionHelper - The connection helper, associated with this instance.
uploadPolicy - The current upload policy.
Method Detail

gethttpStatusCode

public int gethttpStatusCode()
Return the last read http response (200, in case of success).

Returns:
The last read http response

getResponseBody

public java.lang.String getResponseBody()
Get the last response body.

Returns:
The last read response body.

getResponseHeaders

public java.lang.String getResponseHeaders()
Get the headers of the HTTP response.

Returns:
The HTTP headers.

getResponseMsg

public java.lang.String getResponseMsg()
Get the last response message.

Returns:
The response message from the first line of the response (e.g. "200 OK").

readHttpResponse

public int readHttpResponse()
                     throws JUploadException
The main method: reads the response in the input stream.

Returns:
The response status (e.g.: 200 if everything was ok)
Throws:
JUploadException

byteAppend

static byte[] byteAppend(byte[] buf1,
                         byte[] buf2)
Concatenates two byte arrays.

Parameters:
buf1 - The first array
buf2 - The second array
Returns:
A byte array, containing buf2 appended to buf2

byteAppend

static byte[] byteAppend(byte[] buf1,
                         byte[] buf2,
                         int len)
Concatenates two byte arrays.

Parameters:
buf1 - The first array
buf2 - The second array
len - Number of bytes to copy from buf2
Returns:
A byte array, containing buf2 appended to buf2

readLine

public static java.lang.String readLine(java.io.PushbackInputStream inputStream,
                                        java.lang.String charset,
                                        boolean includeCR)
                                 throws java.io.IOException,
                                        JUploadException
Similar like BufferedInputStream#readLine() but operates on raw bytes. Line-Ending is always "\r\n".

Parameters:
inputStream -
charset - The input charset of the stream.
includeCR - Set to true, if the terminating CR/LF should be included in the returned byte array.
Returns:
The line, encoded from the input stream with the given charset
Throws:
java.io.IOException
JUploadException

readLine

public static byte[] readLine(java.io.PushbackInputStream inputStream,
                              boolean includeCR)
                       throws java.io.IOException,
                              JUploadException
Similar like BufferedInputStream#readLine() but operates on raw bytes. According to RFC 2616, and of line may be CR (13), LF (10) or CRLF. Line-Ending is always "\r\n" in header, but not in text bodies. Update done by TedA (sourceforge account: tedaaa). Allows to manage response from web server that send LF instead of CRLF ! Here is a part of the RFC: "we recommend that applications, when parsing such headers, recognize a single LF as a line terminator and ignore the leading CR".
Corrected again to manage line finished by CR only. This is not allowed in headers, but this method is also used to read lines in the body.

Parameters:
inputStream -
includeCR - Set to true, if the terminating CR/LF should be included in the returned byte array. In this case, CR/LF is always returned to the caller, whether the input stream got CR, LF or CRLF.
Returns:
The byte array from the input stream, with or without a trailing CRLF
Throws:
java.io.IOException
JUploadException

readHeaders

private void readHeaders(java.io.PushbackInputStream httpDataIn)
                  throws java.io.IOException,
                         JUploadException
Read the headers from the given input stream.

Parameters:
httpDataIn - The http input stream
Throws:
java.io.IOException
JUploadException

readBody

private void readBody(java.io.PushbackInputStream httpDataIn)
               throws java.io.IOException,
                      JUploadException
Read the body from the given input stream.

Parameters:
httpDataIn - The http input stream
Throws:
java.io.IOException
JUploadException
JUploadException