Methods Summary |
---|
public int | available()Gets the number of bytes remaining to be read.
return size - pos;
|
private native void | close(int handle)native interface to close the opened resource.
|
public void | close()closes the open resource stream.
close(handle);
handle = -1;
|
private native void | finalize()native finalizaion
|
private java.lang.String | fixResourceName(java.lang.String name)Fixes the resource name to be conformant with the CLDC 1.0
specification. We are not allowed to use "../" to get outside
of the .jar file.
Vector dirVector = new Vector();
int startIdx = 0;
int endIdx = 0;
String curDir;
while ((endIdx = name.indexOf('/", startIdx)) != -1) {
if (endIdx == startIdx) {
// We have a leading '/' or two consecutive '/'s
startIdx++;
continue;
}
curDir = name.substring(startIdx, endIdx);
startIdx = endIdx + 1;
if (curDir.equals(".")) {
// Ignore a single '.' directory
continue;
}
if (curDir.equals("..")) {
// Go up a level
int size = dirVector.size();
if (size > 0) {
dirVector.removeElementAt(size - 1);
} else {
// Do not allow "/../resource"
throw new IOException();
}
continue;
}
dirVector.addElement(curDir);
}
// save directory structure
int nameLength = name.length();
StringBuffer dirName = new StringBuffer(nameLength);
int numElements = dirVector.size();
for (int i = 0; i < numElements; i++) {
dirName.append((String)dirVector.elementAt(i));
dirName.append("/");
}
// save filename
if (startIdx < nameLength) {
String filename = name.substring(startIdx);
// Throw IOE if the resource ends with ".class", but, not
// if the entire name is ".class"
if ((filename.endsWith(".class")) &&
(! ".class".equals(filename))) {
throw new IOException();
}
dirName.append(name.substring(startIdx));
}
return dirName.toString();
|
private native int | open(byte[] name)native interface to open resource as stream.
|
public int | read()Reads the next byte of data from the input stream.
if (pos < size) {
pos++;
} else {
return -1;
}
return read(handle);
|
public int | read(byte[] b, int off, int len)Reads bytes into a byte array.
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
}
if (pos >= size) {
return -1;
}
if (pos + len > size) {
len = size - pos;
}
if (len <= 0) {
return 0;
}
int result = readBytes(handle, b, off, pos, len);
if (result > -1) {
pos += result;
}
return result;
|
private native int | read(int handle)native interface to read a byte from the opened resource.
|
private native int | readBytes(int handle, byte[] b, int offset, int pos, int len)native interface to read bytes from the opened resource.
|
public synchronized void | reset()Resets the buffer position to zero.
The value of pos is set to 0.
if (handle == -1) {
return;
}
pos = 0;
|