|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jcontrol.io.Resource
public final class Resource
Implements ROM (and Flash EEPROM) resource read access for JControl.
JControls read only memories are organised primary by banks
(internal ROM, and one of external flash memory) and secondary by archives.
All archives of these banks are merged to a flat structure,
there are no directories (the path marker '/
' is part of the resource-name).
Resource
combines parts of classes typically known as File
and
FileInputStream
for memory reasons. The use of this class can be simple for
opening a single resource by name and reading the resource and quite complex for browsing
the contents of archives, for example:
try{ // opening a single Resource Resource r=new Resource("readme.txt"); String s=r.readLine(); // contents of the first line inside "readme.txt" [...] // listing all Resources in the first archive of the flash memory r=new Resource(FLASHACCESS); Resource bak=r; // second reference while(r!=null){ s=r.getName(); // name of the Resource [...] r=r.next(); // opens the next Resource } r=bak.nextArchive(); s=r.getName(); // name of the first Resource of the second archive } catch(IOException ioe) {}Resources are also used by other parts of the JControl API, e.g. in
Display
Resources are used to get access to bitmap graphics and fonts.
Field Summary | |
---|---|
static int |
FLASHACCESS
Constructor parameter for access to the external flash memory. |
static int |
ROMACCESS
Constructor parameter for access to the internal ROM. |
Fields inherited from interface jcontrol.comm.ConsoleInputStream |
---|
LF_CHARS |
Constructor Summary | |
---|---|
Resource(int access)
Constructs access to the first resource in the first archive of the requested bank. |
|
Resource(String name)
Constructs access to a namely known resource. |
Method Summary | |
---|---|
int |
available()
Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. |
void |
close()
Closes the resource, further reads are not possible. |
String |
getName()
Returns the name of the current resource. |
int |
length()
Returns the length of the current resource. |
void |
mark(int readlimit)
NOTE: not supported! |
boolean |
markSupported()
NOTE: not supported! |
Resource |
next()
Returns itself but now accessing the next resource in the current archive or null if there is no further resource or if the archive is protected from listing. |
Resource |
nextArchive()
Returns always null, because we don't known multiple archives in 1 rom-filesystem. |
int |
read()
Reads a single byte from the resource. |
int |
read(byte[] b)
Reads some number of bytes from the input stream and stores them into the buffer array b . |
int |
read(byte[] buffer,
int startindex,
int length)
Reads to a byte array from the resource. |
String |
readLine()
Reads a single String from the resource. |
void |
reset()
NOTE: not supported! |
int |
seek(int offset,
boolean absolute)
Sets the read-pointer of this Resource to a new position. |
int |
skip(int n)
Skips over and discards n bytes of data from this input
stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, notifyAll, toString, wait |
Field Detail |
---|
public static final int ROMACCESS
public static final int FLASHACCESS
Constructor Detail |
---|
public Resource(String name) throws IOException
read()
method.
name
- the resource to search
IOException
- if the named resource ist not foundpublic Resource(int access) throws IOException
Resource
is only for accessing the default flash bank (the bank the application is running from), for
access to other banks use Flash
.
access
- to get access to internal ROM or external flash memory
IOException
- if there is no resource in the bank
(or the bank is protected from reading)ROMACCESS
,
FLASHACCESS
Method Detail |
---|
public Resource next()
nextArchive()
,
getName()
public Resource nextArchive()
public String getName()
public int length()
public int read() throws IOException
read
in interface BasicInputStream
IOException
public int read(byte[] buffer, int startindex, int length) throws IOException
read
in interface BasicInputStream
buffer
- the buffer to fillstartindex
- the index to start filling the arraylength
- number of bytes to read; the array is filled from startindex
to
startindex
+length
-1
-1
if there is no more data because the end of
the stream has been reached.
IOException
- if the read is past resouce endInputStream.read()
public int read(byte[] b) throws IOException
BasicInputStream
b
. The number of bytes actually read is
returned as an integer. This method blocks until input data is
available, end of file is detected, or an exception is thrown.
If b
is null
, a
NullPointerException
is thrown. If the length of
b
is zero, then no bytes are read and 0
is
returned; otherwise, there is an attempt to read at least one byte. If
no byte is available because the stream is at end of file, the value
-1
is returned; otherwise, at least one byte is read and
stored into b
.
The first byte read is stored into element b[0]
, the
next one into b[1]
, and so on. The number of bytes read is,
at most, equal to the length of b
. Let k be the
number of bytes actually read; these bytes will be stored in elements
b[0]
through b[
k-1]
,
leaving elements b[
k]
through
b[b.length-1]
unaffected.
If the first byte cannot be read for any reason other than end of
file, then an IOException
is thrown. In particular, an
IOException
is thrown if the input stream has been closed.
The read(b)
method for class InputStream
has the same effect as:
read(b, 0, b.length)
read
in interface BasicInputStream
b
- the buffer into which the data is read.
-1
is there is no more data because the end of
the stream has been reached.
IOException
- if an I/O error occurs.InputStream.read(byte[], int, int)
public void close()
close()
isn't nessecary for cleanup. After close()
it's still possible to use any file and archive access methods except for reading.
close
in interface BasicInputStream
public String readLine() throws IOException
String
from the resource.
The String is received character-by-character until an linefeed character defined in ConsoleInputStream
is received. There is a buffer if size BUFFERSIZE
allocated to store the received bytes, if the buffer
is full a linefeed is forced.
readLine
in interface ConsoleInputStream
String
read
IOException
- if an error occursString
public int seek(int offset, boolean absolute) throws IOException
Resource
to a new position.
offset
- the new positionabsolute
- if set offset
is relative to begin of FILE
otherwise relative to the
current read-pointer position
IOException
- if the new position is out of rangepublic int available() throws IOException
BasicInputStream
available
in interface BasicInputStream
IOException
- if an I/O error occurs.public int skip(int n) throws IOException
BasicInputStream
n
bytes of data from this input
stream. The skip
method may, for a variety of reasons, end
up skipping over some smaller number of bytes, possibly 0
.
This may result from any of a number of conditions; reaching end of file
before n
bytes have been skipped is only one possibility.
The actual number of bytes skipped is returned. If n
is
negative, no bytes are skipped.
The skip
method of InputStream
creates a
byte array and then repeatedly reads into it until n
bytes
have been read or the end of the stream has been reached. Subclasses are
encouraged to provide a more efficient implementation of this method.
skip
in interface BasicInputStream
n
- the number of bytes to be skipped.
IOException
- if an I/O error occurs.public void mark(int readlimit)
mark
in interface BasicInputStream
readlimit
- the maximum limit of bytes that can be read before
the mark position becomes invalid.public boolean markSupported()
markSupported
in interface BasicInputStream
true
if this stream instance supports the mark
and reset methods; false
otherwise.public void reset() throws IOException
reset
in interface BasicInputStream
IOException
- if this stream has not been makred or if the
mark has been invalidated.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |