net.datacrow.core.http
Class HttpConnection

java.lang.Object
  extended by net.datacrow.core.http.HttpConnection

public class HttpConnection
extends java.lang.Object

This class wraps a HttpURLConnection and offers detailed methods for retrieving information from an URL. Proxies are supported.

Author:
Robert Jan van der Waals

Constructor Summary
protected HttpConnection(java.net.URL url)
          Create a new connection.
 
Method Summary
 void close()
          Disconnect, closes the connection.
 boolean exists()
          Checks if the URL is valid.
 byte[] getBytes()
          Retrieves the underlying bytes and closes the connection.
 int getContentLength()
          Retrieves the content length.
 java.io.InputStream getInputStream()
          Create an output stream for uploading purposes.
 java.io.OutputStream getOutputStream()
          Create an output stream for uploading purposes.
 java.lang.String getString()
          Retrieves the underlying text (as UTF8).
 java.lang.String getString(java.lang.String charset)
          Retrieves the underlying text using the specified encoding.
 void setContentLength(int length)
          Set the content length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpConnection

protected HttpConnection(java.net.URL url)
                  throws HttpConnectionException
Create a new connection.

Parameters:
url -
Throws:
HttpConnectionException
Method Detail

exists

public boolean exists()
Checks if the URL is valid.

Returns:

getString

public java.lang.String getString()
                           throws HttpConnectionException
Retrieves the underlying text (as UTF8).

Throws:
java.io.IOException
HttpConnectionException

getString

public java.lang.String getString(java.lang.String charset)
                           throws HttpConnectionException
Retrieves the underlying text using the specified encoding.

Parameters:
charset -
Returns:
Throws:
java.io.IOException
HttpConnectionException

getBytes

public final byte[] getBytes()
                      throws HttpConnectionException
Retrieves the underlying bytes and closes the connection.

Throws:
java.io.IOException
HttpConnectionException

getContentLength

public int getContentLength()
Retrieves the content length.

Returns:

setContentLength

public void setContentLength(int length)
Set the content length.

Parameters:
length -

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Create an output stream for uploading purposes.

Throws:
java.io.IOException

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Create an output stream for uploading purposes.

Throws:
java.io.IOException

close

public void close()
Disconnect, closes the connection.