org.eobjects.metamodel.util
Class UrlResource

java.lang.Object
  extended by org.eobjects.metamodel.util.UrlResource
All Implemented Interfaces:
Serializable, HasName, Resource

public class UrlResource
extends Object
implements Resource, Serializable

Resource based on URL or URI.

See Also:
Serialized Form

Constructor Summary
UrlResource(String urlString)
           
UrlResource(URI uri)
           
UrlResource(URL url)
           
 
Method Summary
 void append(Action<OutputStream> appendCallback)
          Opens up an InputStream to append (write at the end of the existing stream) to the resource.
 long getLastModified()
          Gets the last modified timestamp value (measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)) of the resource, if available.
 String getName()
          Gets the name of the resource, typically a filename or other identifying string
 long getSize()
          Gets the size (in number of bytes) of this resource's data.
 URI getUri()
          Gets the URI associated with this resource.
 boolean isExists()
          Determines if the resource referenced by this object exists or not.
 boolean isReadOnly()
          Determines if the file is read only, or if writes are also possible.
 InputStream read()
          Opens up an InputStream to read from the resource.
 void read(Action<InputStream> readCallback)
          Opens up an InputStream to read from the resource, and allows a callback to perform writing actions on it.
<E> E
read(Func<InputStream,E> readCallback)
          Opens up an InputStream to read from the resource, and allows a callback function to perform writing actions on it and return the function's result.
 String toString()
           
 void write(Action<OutputStream> writeCallback)
          Opens up an OutputStream to write to the resource, and allows a callback to perform writing actions on it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UrlResource

public UrlResource(URL url)

UrlResource

public UrlResource(URI uri)

UrlResource

public UrlResource(String urlString)
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getUri

public URI getUri()
Gets the URI associated with this resource.

Returns:

getName

public String getName()
Description copied from interface: Resource
Gets the name of the resource, typically a filename or other identifying string

Specified by:
getName in interface HasName
Specified by:
getName in interface Resource

isReadOnly

public boolean isReadOnly()
Description copied from interface: Resource
Determines if the file is read only, or if writes are also possible.

Specified by:
isReadOnly in interface Resource
Returns:

write

public void write(Action<OutputStream> writeCallback)
           throws ResourceException
Description copied from interface: Resource
Opens up an OutputStream to write to the resource, and allows a callback to perform writing actions on it.

Specified by:
write in interface Resource
Parameters:
writeCallback - a callback which should define what to write to the resource.
Throws:
ResourceException - if an error occurs while writing

append

public void append(Action<OutputStream> appendCallback)
            throws ResourceException
Description copied from interface: Resource
Opens up an InputStream to append (write at the end of the existing stream) to the resource.

Specified by:
append in interface Resource
Parameters:
appendCallback - a callback which should define what to append to the resource.
Throws:
ResourceException - if an error occurs while appending

read

public void read(Action<InputStream> readCallback)
          throws ResourceException
Description copied from interface: Resource
Opens up an InputStream to read from the resource, and allows a callback to perform writing actions on it.

Specified by:
read in interface Resource
Throws:
ResourceException - if an error occurs while reading

read

public <E> E read(Func<InputStream,E> readCallback)
       throws ResourceException
Description copied from interface: Resource
Opens up an InputStream to read from the resource, and allows a callback function to perform writing actions on it and return the function's result.

Specified by:
read in interface Resource
Returns:
the result of the function
Throws:
ResourceException - if an error occurs while reading

isExists

public boolean isExists()
Description copied from interface: Resource
Determines if the resource referenced by this object exists or not.

Specified by:
isExists in interface Resource
Returns:

getSize

public long getSize()
Description copied from interface: Resource
Gets the size (in number of bytes) of this resource's data. An approximated number is allowed. If the size is not determinable without actually reading through the whole contents of the resource, -1 is returned.

Specified by:
getSize in interface Resource
Returns:

getLastModified

public long getLastModified()
Description copied from interface: Resource
Gets the last modified timestamp value (measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)) of the resource, if available. If the last modified date is not available, -1 is returned.

Specified by:
getLastModified in interface Resource
Returns:

read

public InputStream read()
                 throws ResourceException
Description copied from interface: Resource
Opens up an InputStream to read from the resource. Consumers of this method are expected to invoke the InputStream.close() method manually. If possible, the other read(...) methods are preferred over this one, since they guarantee proper closing of the resource's handles.

Specified by:
read in interface Resource
Returns:
Throws:
ResourceException


Copyright © 2007-2013. All Rights Reserved.