org.jasen.util
Class WebUtils

java.lang.Object
  extended byorg.jasen.util.WebUtils

public class WebUtils
extends Object

General WWW and net utility methods.

Author:
Jason Polites

Field Summary
static String URL_REGEX
           
 
Constructor Summary
WebUtils()
           
 
Method Summary
static void get(URL url, OutputStream out, int bufferSize, long timeout)
          Attempts to download the file given by the URL and saves it to the output stream provided
NOTE: The given output stream will NOT be closed within this method
static void get(URL url, OutputStream out, int bufferSize, long timeout, StreamReaderListener listener)
          Attempts to download the file given by the URL and saves it to the output stream provided
NOTE: The given output stream will NOT be closed within this method
static boolean isUrl(String text)
          Returns true iff the text passed represents a url.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL_REGEX

public static final String URL_REGEX
See Also:
Constant Field Values
Constructor Detail

WebUtils

public WebUtils()
Method Detail

isUrl

public static boolean isUrl(String text)
Returns true iff the text passed represents a url.

A url may take many forms:

For example:

Unfortunately there doesn't seem to be an "elegant" way to determine
definatively if an unknown String is in fact a URL. We are just going
to use the java.net.URL class and assume a MalformedURLException implies
that the string is not a url.

Parameters:
text -
Returns:
True if the text is a valid URL, false otherwise

get

public static void get(URL url,
                       OutputStream out,
                       int bufferSize,
                       long timeout)
                throws IOException
Attempts to download the file given by the URL and saves it to the output stream provided
NOTE: The given output stream will NOT be closed within this method

Parameters:
url - The fully qualified url path to the remote resource
out - The output stream to which the data read will be written
bufferSize - The buffer size to use for reading bytes
timeout - The timeout (in milliseconds) to wait for a response from the remote server
Throws:
IOException - If an error occurred during transit

get

public static void get(URL url,
                       OutputStream out,
                       int bufferSize,
                       long timeout,
                       StreamReaderListener listener)
                throws IOException
Attempts to download the file given by the URL and saves it to the output stream provided
NOTE: The given output stream will NOT be closed within this method

Parameters:
url - The fully qualified url path to the remote resource
out - The output stream to which the data read will be written
bufferSize - The buffer size to use for reading bytes
timeout - The timeout (in milliseconds) to wait for a response from the remote server
listener - A listener which will report when bytes have been written to the output stream
Throws:
IOException - If an error occurred during transit