org.eobjects.metamodel.util
Interface Resource

All Superinterfaces:
HasName
All Known Implementing Classes:
ClasspathResource, FileResource, InMemoryResource, UrlResource

public interface Resource
extends HasName

Represents a resource from which we can read and write bytes


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.
 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.
 void write(Action<OutputStream> writeCallback)
          Opens up an OutputStream to write to the resource, and allows a callback to perform writing actions on it.
 

Method Detail

getName

String getName()
Gets the name of the resource, typically a filename or other identifying string

Specified by:
getName in interface HasName

isReadOnly

boolean isReadOnly()
Determines if the file is read only, or if writes are also possible.

Returns:

isExists

boolean isExists()
Determines if the resource referenced by this object exists or not.

Returns:

getSize

long getSize()
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.

Returns:

getLastModified

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. If the last modified date is not available, -1 is returned.

Returns:

write

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

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

append

void append(Action<OutputStream> appendCallback)
            throws ResourceException
Opens up an InputStream to append (write at the end of the existing stream) to the resource.

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

read

InputStream read()
                 throws ResourceException
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.

Returns:
Throws:
ResourceException

read

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

Parameters:
readCallback -
Throws:
ResourceException - if an error occurs while reading

read

<E> E read(Func<InputStream,E> readCallback)
       throws ResourceException
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.

Parameters:
readCallback -
Returns:
the result of the function
Throws:
ResourceException - if an error occurs while reading


Copyright © 2007-2013. All Rights Reserved.