ResourceHandlerpublic final class ResourceHandler extends Object This class provides a way to securely access platform resources.
On some versions of the Java platform, there is a need to specify
a security token to access resources. This allows different
versions of the security features. |
Fields Summary |
---|
private static final String | DEFAULT_FONT_FACE_FILELocation of the default font face resource file | private static final String | INITIAL_FONT_FACE_FILELocation of the intial font face resource file | private static com.sun.midp.security.SecurityToken | securityToken |
Constructors Summary |
---|
private ResourceHandler()Don't allow instances to be created.
try {
securityToken =
com.sun.midp.security.SecurityInitializer.requestToken(new SecurityTrusted());
} catch (SecurityException se) {
// Just log the error. This may happen in development context
// when running a midlet which bundles the SVG engine.
se.printStackTrace();
} catch (NoClassDefFoundError e) {
// Just log the error. This may happen in development context
// when running a midlet which bundles the SVG engine.
e.printStackTrace();
}
|
Methods Summary |
---|
public static final java.io.InputStream | getDefaultFontResource()
InputStream is = null;
try {
is = getSystemResource(DEFAULT_FONT_FACE_FILE, securityToken);
} catch (SecurityException se) {
//log security exceptions
se.printStackTrace();
}
return is;
| public static final java.io.InputStream | getInitialFontResource()
InputStream is = null;
try {
is = getSystemResource(INITIAL_FONT_FACE_FILE, securityToken);
} catch (SecurityException se) {
//log security exceptions
se.printStackTrace();
}
return is;
| private static java.io.InputStream | getSystemResource(java.lang.String resourceName, java.lang.Object securityToken)
if (securityToken == null) {
return ResourceHandler.class.getResourceAsStream(resourceName);
} else {
InputStream is = null;
RandomAccessStream storage =
new RandomAccessStream((SecurityToken) securityToken);
try {
// extract the file name part of the full resource name
int namePartIdx = resourceName.lastIndexOf('/");
String namePart = (namePartIdx != -1) ?
resourceName.substring(namePartIdx + 1) : resourceName;
storage.connect(File.getConfigRoot(
Constants.INTERNAL_STORAGE_ID) + namePart,
Connector.READ);
byte[] data = new byte[storage.getSizeOf()];
storage.readBytes(data, 0, data.length);
is = new ByteArrayInputStream(data);
} catch (IOException e) {
System.out.println("Error in getSystemResource");
} finally {
try {
storage.disconnect();
} catch (IOException ignored) {
}
}
return is;
}
|
|