|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecthmi.util.Resources
public class Resources
Resources are objects that serve as an ``anchor'' for loading files called ``resources''. Such files are assumed to be at a fixed place within the directory structure associated with a project, so no interactive file dialog is needed. They are, however, not assumed to be at a fixed place within the file system of the OS, so as to avoid undesirable system dependencies. Think of a situation where an application is packaged in the form of a single executable jar file, that has to run from within some unknown directory on an unknown machine. In this case, about the only location that we can rely on is the jar archive itself, so resource files should be specified relative to the jar archive. A Resources object determines a data directory inside such a jar archive, and will open files inside this directory, via the getReader() or getFileStream method. By convention the name of this data directory follows the package structure, so for example, the data used by some class inside the project.vmr package shouold read data from files inside the project/vmr data directory. When the application is not run from a jar archive, the same data directory should be available, and should be included in the java run time classpath. By convention, we use a "data" or "resources" directory inside java projects, which is included in the the java classpath, either inside the Java development tool or inside the ant build scripts.
| Field Summary | |
|---|---|
private static ClassLoader |
loader
|
private static Logger |
logger
|
private boolean |
logging
|
private String |
resourceDir
|
private String |
resourceRoot
|
| Constructor Summary | |
|---|---|
private |
Resources()
|
|
Resources(String resourceDir)
Create a new Resources object, for a specified resource directory. |
| Method Summary | |
|---|---|
private static String |
adjustPath2(String rootPath)
|
BufferedInputStream |
getInputStream(String fileName)
Like getReader(filename), but returns a buffered InputStream, rather than a buffered Reader. |
BufferedReader |
getReader(String fileName)
Opens a file, and returns a buffered Reader for that file. |
String |
getResourceDirectory()
returns the resource directory for this Resources object |
String |
getResourceRoot()
returns the resource root directory for this Resources object |
private InputStream |
getUnbufferedInputStream(String fileName)
|
String |
read(String fileName)
Tries to read the specified file, and returns the contents as a String. |
void |
setLogging(boolean logging)
Turns logging on or off |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private String resourceRoot
private static ClassLoader loader
private static Logger logger
private boolean logging
private String resourceDir
| Constructor Detail |
|---|
private Resources()
public Resources(String resourceDir)
| Method Detail |
|---|
public String getResourceDirectory()
public BufferedInputStream getInputStream(String fileName)
private InputStream getUnbufferedInputStream(String fileName)
public BufferedReader getReader(String fileName)
public String read(String fileName)
throws IOException
IOExceptionpublic void setLogging(boolean logging)
private static String adjustPath2(String rootPath)
public String getResourceRoot()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||