net.sourceforge.atunes.kernel.utils
Class NetworkUtils

java.lang.Object
  extended by net.sourceforge.atunes.kernel.utils.NetworkUtils

public class NetworkUtils
extends java.lang.Object

Utility methods for network access.


Constructor Summary
NetworkUtils()
           
 
Method Summary
static java.lang.String encodeString(java.lang.String s)
          Encodes a string in a format suitable to send a http request.
static java.net.HttpURLConnection getConnection(java.lang.String urlString, Proxy proxy)
          Returns a HttpURLConnection specified by a given URL and Proxy.
static java.awt.Image getImage(java.net.URLConnection connection)
          Reads a Image from a given URLConnection.
static Proxy getProxy(ProxyBean proxy)
          Returns a net.sourceforge.atunes.kernel.modules.proxy.Proxy for a given ProxyBean
static java.lang.String readPostURL(java.net.HttpURLConnection connection, java.lang.String post)
          Sends a HTTP-Post query to a given URLConnection and reads and returns the answer.
static java.lang.String readURL(java.net.URLConnection connection)
          Reads a String from a given URLConnection.
static java.lang.String readURL(java.net.URLConnection connection, java.lang.String charset)
          Reads a String from a given URLConnection with a given charset encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetworkUtils

public NetworkUtils()
Method Detail

encodeString

public static java.lang.String encodeString(java.lang.String s)
Encodes a string in a format suitable to send a http request.

Parameters:
s - The String that should be encoded
Returns:
A suitable encoded String

getConnection

public static java.net.HttpURLConnection getConnection(java.lang.String urlString,
                                                       Proxy proxy)
                                                throws java.io.IOException
Returns a HttpURLConnection specified by a given URL and Proxy.

Parameters:
urlString - A URL as String
proxy - A proxy
Returns:
A HttpURLConnection
Throws:
java.io.IOException - If an IO exception occurs

getImage

public static java.awt.Image getImage(java.net.URLConnection connection)
                               throws java.io.IOException
Reads a Image from a given URLConnection.

Parameters:
connection - A URLConnection
Returns:
The Image that was read from the URLConnection
Throws:
java.io.IOException - If an IO exception occurs

getProxy

public static Proxy getProxy(ProxyBean proxy)
                      throws java.net.UnknownHostException,
                             java.io.IOException
Returns a net.sourceforge.atunes.kernel.modules.proxy.Proxy for a given ProxyBean

Parameters:
proxy - A ProxyBean
Returns:
A net.sourceforge.atunes.kernel.modules.proxy.Proxy
Throws:
java.net.UnknownHostException - If the host is unknown
java.io.IOException - If an IO exception occurs

readPostURL

public static java.lang.String readPostURL(java.net.HttpURLConnection connection,
                                           java.lang.String post)
                                    throws java.io.IOException
Sends a HTTP-Post query to a given URLConnection and reads and returns the answer.

Parameters:
connection - A URLConnection
post - The HTTP-Post query
Returns:
The answer of the query
Throws:
java.io.IOException - If an IO exception occurs

readURL

public static java.lang.String readURL(java.net.URLConnection connection)
                                throws java.io.IOException
Reads a String from a given URLConnection.

Parameters:
connection - A URLConnection
Returns:
A String read from a given URLConnection
Throws:
java.io.IOException - If an IO exception occurs

readURL

public static java.lang.String readURL(java.net.URLConnection connection,
                                       java.lang.String charset)
                                throws java.io.IOException
Reads a String from a given URLConnection with a given charset encoding.

Parameters:
connection - A URLConnection
charset - A charset as String, e.g. "UTF-8"
Returns:
A String read from a given URLConnection
Throws:
java.io.IOException - If an IO exception occurs


Copyright © 2006-2008 The aTunes Team. All Rights Reserved.