FileDocCategorySizeDatePackage
ResourceHandler.javaAPI DocphoneME MR2 API (J2ME)5425Wed May 02 18:00:10 BST 2007com.sun.midp.util

ResourceHandler

public class ResourceHandler extends Object
The ResourceHandler class is a system level utility class. Its purpose is to return system resources as an array of bytes based on a unique String identifier. All methods in this utility class should be protected through use of the SecurityToken.

Fields Summary
Constructors Summary
Methods Summary
public static byte[]getAmsResource(com.sun.midp.security.SecurityToken token, java.lang.String resource)
Load a resource from the system and return it as a byte array. This method is used to load AMS icons.

param
token the SecurityToken to use to grant permission to execute this method.
param
resource a String identifier which can uniquely describe the location of the resource to be loaded.
return
a byte[] containing the resource retrieved from the system. null if the resource could not be found.

        return getResourceImpl(token, File.getStorageRoot(
            Constants.INTERNAL_STORAGE_ID) + resource);
    
private static byte[]getResourceImpl(com.sun.midp.security.SecurityToken token, java.lang.String resourceFilename)
Load a resource from the system and return it as a byte array. This method is used to load system level resources, such as images, sounds, properties, etc.

param
token the SecurityToken to use to grant permission to execute this method.
param
resourceFilename full path to the file containing the resource.
return
a byte[] containing the resource retrieved from the system. null if the resource could not be found.

        token.checkIfPermissionAllowed(Permissions.MIDP);

        byte[] resourceBuffer = null;
        RandomAccessStream stream = new RandomAccessStream(token);

        try {
            stream.connect(resourceFilename, Connector.READ);
            resourceBuffer = new byte[stream.getSizeOf()];
            stream.readBytes(resourceBuffer, 0, resourceBuffer.length);
        } catch (java.io.IOException e) {
            resourceBuffer = null;
        } finally {
            try {
                stream.disconnect();
            } catch (java.io.IOException ignored) {
            }
        }

        return resourceBuffer;
    
public static byte[]getSystemImageResource(com.sun.midp.security.SecurityToken token, java.lang.String imageName)
Load a system image resource from the system and return it as a byte array. The images are stored in the configuration directory ($MIDP_HOME/lib).

param
token the SecurityToken to use to grant permission to execute this method.
param
imageName name of the image
return
a byte[] containing the resource retrieved from the system. null if the resource could not be found.
throws
IllegalArgumentException if imageName contains a "/" or "\\", or imageName is null or imageName is empty

        byte[] imageData = getAmsResource(token, imageName + ".raw");
        if (imageData == null) {
            imageData = getAmsResource(token, imageName + ".png");
        }
        
        return imageData;
    
public static byte[]getSystemResource(com.sun.midp.security.SecurityToken token, java.lang.String resource)
Load a resource from the system and return it as a byte array. This method is used to load system level resources, such as images, sounds, properties, etc.

param
token the SecurityToken to use to grant permission to execute this method.
param
resource a String identifier which can uniquely describe the location of the resource to be loaded.
return
a byte[] containing the resource retrieved from the system. null if the resource could not be found.

        return getResourceImpl(token, File.getConfigRoot(
            Constants.INTERNAL_STORAGE_ID) + resource);