| org.jicengine.io.Resource
All known Subclasses: org.jicengine.io.AbstractResource,
Resource | public interface Resource (Code) | |
Provides a common interface for reading resources and resolving relative
path-references.
A resource is typically a file that contains data to be used by an
application. Java provides various ways for reading resources: java.io.File,
java.net.URL, java.lang.Class.getResourceAsStream(),
java.lang.ClassLoader.getResourceAsStream(), etc.
This class encapsulates all these under a common interface.
Copyright (C) 2004 Timo Laitinen
author: .timo version: 1.0 |
Method Summary | |
public String | getIdentifier()
Returns the identifier of this resource.
Depending on the kind of resource, the
identifier could be a file-path, url, etc.
The identifier is descriptive - it will help a human to find out what kind
of resource is in question. | public InputStream | getInputStream() A primary way reading the resource. | public String | getMimeType()
Returns the http mime-type of this Resource, if this Resource has one.
Mime-type information is an easy way to find out something about the
type of content in a Resource. | public Reader | getReader() Alternative way for reading text-based resources. | public Resource | getResource(String relativePath)
Locates another Resource whose path is defined relative to this Resource.
the path scheme used with files and urls is used for specifying relative
paths.
the method generally returns instances of the same Resource-subclass than
the current instance, but this is not obligatory.
NOTE:
NOTE: there is no support for absolute paths. | public boolean | isAvailable()
Tests whether the resource is available i.e. | public void | writeTo(OutputStream out) Writes the content of this resource into an OutputStream. | public void | writeTo(Writer writer)
Writes the content of this resource into a Writer. |
getIdentifier | public String getIdentifier()(Code) | |
Returns the identifier of this resource.
Depending on the kind of resource, the
identifier could be a file-path, url, etc.
The identifier is descriptive - it will help a human to find out what kind
of resource is in question. It CAN NOT be used for creating new Resources or
for reading resources. the format of the identifier varies and may be changed
in the future.
|
getInputStream | public InputStream getInputStream() throws IOException(Code) | | A primary way reading the resource.
InputStream throws: IOException - if the reading fails - if the resource doesn't exist,for example. |
getMimeType | public String getMimeType()(Code) | |
Returns the http mime-type of this Resource, if this Resource has one.
Mime-type information is an easy way to find out something about the
type of content in a Resource. it also makes it easier to write Resource
data into http-responses.
NOTE: this property is optional! null is returned if the mime-typeinformation is not available. and most in cases it probably isn't. |
getReader | public Reader getReader() throws IOException(Code) | | Alternative way for reading text-based resources.
A Reader that returns data from this Resource. throws: IOException - if the reading fails - if the resource doesn't exist,for example. |
getResource | public Resource getResource(String relativePath) throws IOException(Code) | |
Locates another Resource whose path is defined relative to this Resource.
the path scheme used with files and urls is used for specifying relative
paths.
the method generally returns instances of the same Resource-subclass than
the current instance, but this is not obligatory.
NOTE:
NOTE: there is no support for absolute paths. yet.
Parameters: relativePath - name of the neighbouring resource. only relative pathsare allowed, don't put the root mark '/' in the beginning. notationslike '../' can be used (in most of the cases, at least) Windows-likepaths '\joku\jotain.txt' won't work. a new Resource. The returned Resource is most likely ofthe same type as this resource (although there's no guarantee). Inother words, if this Resource is a FileResource, the returned Resourcewill also be a FileResource.NOTE: this method doesn't necessary check the availability of the relativeresource, because that may be too slow. if you want to make sure that thereturned resource is available, you must examine the availability of thereturned resource by your self. throws: IOException - if a reference to the neighbouring resource couldn't becreated. |
isAvailable | public boolean isAvailable()(Code) | |
Tests whether the resource is available i.e. can be read.
If this method returns true, the attempt to read this Resource (with getInputStream()
or other methods) is not likely to fail. Unless the resource is somehow
removed between the two method calls.
If a false is return, the resource is not available.
NOTE: testing whether a resource is available can be as
resource-intensive as actually reading the resource.
|
writeTo | public void writeTo(OutputStream out) throws IOException(Code) | | Writes the content of this resource into an OutputStream. This is an
alternative way for obtaining the data of this Resource.
throws: IOException - if the content of this Resource isn't available - ifthe resource doesn't exist, for example. |
writeTo | public void writeTo(Writer writer) throws IOException(Code) | |
Writes the content of this resource into a Writer. This is an
alternative way for obtaining the data of this Resource.
throws: IOException - if the content of this Resource isn't available - ifthe resource doesn't exist, for example. |
|
|