org.jrabbit.base.data.loading
Class URLLoader

java.lang.Object
  extended by org.jrabbit.base.data.loading.URLLoader
All Implemented Interfaces:
Loader

public class URLLoader
extends java.lang.Object
implements Loader

A convenience object for loading data from the web. NOTE: Some of the methods that access data can have a chance of failing - things like Internet connection and web access are out of the developer's control.

Author:
Chris Molini

Field Summary
private  java.net.URL address
          The URL that data is retrieved from.
 
Constructor Summary
URLLoader(java.lang.String webAddress)
          Creates a URLLoader from the String representation of the web address.
URLLoader(java.net.URL address)
          Creates a URLLoader with the indicated, preconstructed URL.
 
Method Summary
 java.io.File file()
          Accesses a file created from the URL.
 java.lang.String path()
          Accesses a String version of the URL.
 java.io.InputStream stream()
          Accesses an InputStream from the URL.
 java.lang.String type()
          Learns the type of data being pointed to by the URL.
 java.net.URL url()
          Accesses the URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

address

private java.net.URL address
The URL that data is retrieved from.

Constructor Detail

URLLoader

public URLLoader(java.net.URL address)
Creates a URLLoader with the indicated, preconstructed URL.

Parameters:
address - The URL to load data from.

URLLoader

public URLLoader(java.lang.String webAddress)
          throws java.net.MalformedURLException
Creates a URLLoader from the String representation of the web address.

Parameters:
webAddress - The address of the URL.
Throws:
java.net.MalformedURLException - if the supplied web address is invalid.
Method Detail

path

public java.lang.String path()
Accesses a String version of the URL.

Specified by:
path in interface Loader
Returns:
A String representation of the web address.

stream

public java.io.InputStream stream()
Accesses an InputStream from the URL.

Specified by:
stream in interface Loader
Returns:
An InputStream of data from the target web resource. If a problem occurred reading the data, then null is returned.

url

public java.net.URL url()
Accesses the URL.

Specified by:
url in interface Loader
Returns:
The URL being used to load data.

file

public java.io.File file()
Accesses a file created from the URL.

Specified by:
file in interface Loader
Returns:
A file pointing to the same data as the URL. This check may fail, if it does, null is returned.

type

public java.lang.String type()
Learns the type of data being pointed to by the URL.

Specified by:
type in interface Loader
Returns:
A String representing the type of the file, in all caps.