Methods Summary |
---|
public int | available()
return size - pos;
|
public synchronized void | close()
close(handle);
handle = null;
|
private static native void | close(java.lang.Object handle)
|
private static 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
try {
dirVector.removeElementAt(dirVector.size()-1);
} catch (ArrayIndexOutOfBoundsException aioobe) {
// "/../resource" Not allowed!
throw new IOException();
}
continue;
}
dirVector.addElement(curDir);
}
// save directory structure
StringBuffer dirName = new StringBuffer();
int nelements = dirVector.size();
for (int i = 0; i < nelements; ++i) {
dirName.append((String)dirVector.elementAt(i));
dirName.append("/");
}
// save filename
if (startIdx < name.length()) {
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 static native java.lang.Object | open(java.lang.String name)
|
private static native int | read(java.lang.Object handle)
|
public int | read()Reads the next byte of data from the input stream.
int result;
if ((result = read(handle)) != -1) {
pos++;
}
return result;
|
public int | read(byte[] b, int off, int len)
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 readLength;
if ((readLength = readBytes(handle, b, off, pos, len)) != -1) {
pos += readLength;
}
return readLength;
|
private static native int | readBytes(java.lang.Object handle, byte[] b, int offset, int pos, int len)
|
private static native int | size(java.lang.Object handle)
|