net.sf.javaprinciples.resource
Interface Resource<T>

Type Parameters:
T - - resource type

public interface Resource<T>

The Resource object encapsulates the content. It is flexible on whether the content is stored in memory or on disk. The resource support a window of time for when the resource is valid.

Author:
wslade

Method Summary
 T getContent()
          Get content of the resource.
 String getEncoding()
          The resource may have a specific encoding.
 InputStream getInputStream()
           
 String getMimeType()
          Each resource holds content of a specific type.
 long getResourceLength()
          The length of the resource in bytes
 long getValidFrom()
          A resource may be valid from a point in time.
 long getValidUntil()
          A resource may be valid only up to a point in time.
 void setContent(T content)
          Apply content to the resource.
 

Method Detail

getValidFrom

long getValidFrom()
A resource may be valid from a point in time. This typically will be the time the resource was created. It may not be the time the resource was first served.

Returns:
A time in milliseconds since 1970 relative to UTC.

getValidUntil

long getValidUntil()
A resource may be valid only up to a point in time. This typically will be the time the resource may be updated.

Returns:
A time in milliseconds since 1970 relative to UTC.

getMimeType

String getMimeType()
Each resource holds content of a specific type.

Returns:
The mime type of the content.

getEncoding

String getEncoding()
The resource may have a specific encoding.

Returns:
A standard encoding, may be null

getResourceLength

long getResourceLength()
The length of the resource in bytes


setContent

void setContent(T content)
Apply content to the resource.

Parameters:
content - May be the content itself or a reference such as a file url.

getContent

T getContent()
Get content of the resource.

Returns:
content of resource.

getInputStream

InputStream getInputStream()
                           throws IOException
Returns:
A stream to the content. May be null if the content is no longer present.
Throws:
IOException - If a problem occurs opening the stream. Retrying wont help.


Copyright © 2013. All Rights Reserved.