ants.gnutant
Class UrlResource

java.lang.Object
  |
  +--ants.gnutant.UrlResource
All Implemented Interfaces:
Externalizable, Resource, Serializable

public class UrlResource
extends Object
implements Resource, Externalizable

An UrlResource is an object containing the URL from which the content of a resource may be downloaded. When a UrlResource is inserted in a Storage object, the storage may perform a local copy of the resource by downloading the contents through the input stream obtained through the getInputStream() method.

Version:
$Revision: 1.2 $
Author:
Alberto Montresor
, Hein Meling
See Also:
Serialized Form

Constructor Summary
UrlResource()
          Default constructor for externalization.
UrlResource(String url)
          Constructs a new UrlResource identified by the specified name.
UrlResource(String url, ants.gnutant.DocumentKey dockey)
          Constructs a new UrlResource identified by the specified name and dockey.
UrlResource(URL url)
          Constructs a new UrlResource identified by the specified name.
 
Method Summary
 boolean equals(Object obj)
          Check whether this UrlResource is equal to the specified object.
 String getAttribute(String name)
          Returns the value associated to the specified attribute name, or null if there is no attribute with that name.
 long getContentLength()
          Return the lenght of the content of the resource, if available.
 String getFile()
          Returns the file part of this URL.
 InputStream getInputStream()
          Return an input stream to download the contents of the resource.
 Object getKey()
          Return the document key for this Url resource as the key.
 String getName()
          Returns the string identifier of the object.
 String getURL()
          Return the stringified url for this Url resource.
 int hashCode()
          Returns a hash code value for the object.
 void readExternal(ObjectInput in)
          Marshals this UrlResource to the specified output stream.
 long size()
          Return the space required to store the resource object.
 String toString()
          Returns a string representation of the object.
 void writeExternal(ObjectOutput out)
          Marshals this UrlResource to the specified output stream.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UrlResource

public UrlResource()
Default constructor for externalization.


UrlResource

public UrlResource(URL url)
            throws IOException
Constructs a new UrlResource identified by the specified name. This will compute the hash and the length of the referenced file. NON-SIMULATION VERSION

Parameters:
url - url from which the resource may be downloaded

UrlResource

public UrlResource(String url)
Constructs a new UrlResource identified by the specified name. This is for simulation and will generate a random document identifier for the referenced file. SIMULATION VERSION.

Parameters:
url - url from which the resource may be downloaded

UrlResource

public UrlResource(String url,
                   ants.gnutant.DocumentKey dockey)
Constructs a new UrlResource identified by the specified name and dockey. SIMULATION VERSION.

Parameters:
url - url from which the resource may be downloaded
dockey - DocumentKey for the specified URL.
Method Detail

getName

public String getName()
Returns the string identifier of the object.

Specified by:
getName in interface Resource

getAttribute

public String getAttribute(String name)
Returns the value associated to the specified attribute name, or null if there is no attribute with that name.

Specified by:
getAttribute in interface Resource
Parameters:
name - the name of the attribute

getInputStream

public InputStream getInputStream()
                           throws IOException
Return an input stream to download the contents of the resource. Depending on the implementation, the contents may be read from the local storage, if the resource has been copied locally; or downloaded remotely, otherwise.

Specified by:
getInputStream in interface Resource
Returns:
an input stream to read the contents of a resource;
IOException

getContentLength

public long getContentLength()
Return the lenght of the content of the resource, if available.

Specified by:
getContentLength in interface Resource
Returns:
the lenght of the content of the resource

size

public long size()
Description copied from interface: Resource
Return the space required to store the resource object.

Specified by:
size in interface Resource

getKey

public Object getKey()
Return the document key for this Url resource as the key.

Specified by:
getKey in interface Resource

getURL

public String getURL()
Return the stringified url for this Url resource.


getFile

public String getFile()
Returns the file part of this URL.

Returns:
a String value

equals

public boolean equals(Object obj)
Check whether this UrlResource is equal to the specified object.

Overrides:
equals in class Object

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class Object

toString

public String toString()
Returns a string representation of the object.

Overrides:
toString in class Object

readExternal

public void readExternal(ObjectInput in)
                  throws IOException
Marshals this UrlResource to the specified output stream.

Specified by:
readExternal in interface Externalizable
IOException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Marshals this UrlResource to the specified output stream.

Specified by:
writeExternal in interface Externalizable
IOException