FileDocCategorySizeDatePackage
DevResourceBundleReader.javaAPI DocphoneME MR2 API (J2ME)6159Wed May 02 18:00:46 BST 2007com.sun.j2me.global

DevResourceBundleReader

public class DevResourceBundleReader extends Object implements ResourceBundleReader
An instance of this class is used to access device resource files.

Fields Summary
private int
locale_index
Locale index in the list of supported locales for specific DevResourceBundleReader instance.
Constructors Summary
public DevResourceBundleReader(int locale_index)
Creates a new instance of DevResourceBundleReader.

param
locale_index index of locale in array of supported locales

        this.locale_index = locale_index;
    
Methods Summary
public byte[]getRawResourceData(int resourceID)
Get raw binary data for resource id.

param
resourceID resource identifier
return
resource as array of bytes or null if resource wasn't found.
throws
ResourceException if resource couldn't be read

        int rsize = getResourceLength(resourceID);
		if (rsize<0){
			throw new ResourceException(ResourceException.RESOURCE_NOT_FOUND,
					"Resource not found.");
		}
        byte[] res = new byte[rsize];
        if (rsize != getRawResourceData0(locale_index, resourceID, res, 0, rsize)) {
			throw new ResourceException(ResourceException.DATA_ERROR,
					"Could not read resource.");
        }
        return res;
    
private static native intgetRawResourceData0(int locale_index, int resourceID, byte[] res, int offset, int length)
Method retrieves resource data for the given ID and locale.

param
resourceID resource identifier
param
res byte array to store resource data
param
locale_index index of locale in array of supported locales
param
offset offset of resource to start with
param
length length in bytes to copy
return
length in bytes of copied data

public intgetResourceLength(int resourceID)
Gives length of the resource in bytes.

param
resourceID resource identifier
return
length of resource in bytes, -1 if resource doesn't exist in this bundle.

        return getResourceLength0(locale_index, resourceID);
    
private static native intgetResourceLength0(int locale_index, int resourceID)
Method retrieves resource length for the given ID and locale.

param
resourceID resource identifier
param
locale_index index of locale in array of supported locales
return
length of the resource with the given ID and locale

public java.lang.StringgetResourceName()
Method returns name of resource file used by this reader.

return
resource file name

        return new String("DEVICE");
    
public bytegetResourceType(int resourceID)
Get type of resource.

param
resourceID resource identifier
return
resource type

        int res_type = getResourceType0(locale_index, resourceID);
        if (res_type != -1) {
            return (byte)res_type;
        }
        throw new ResourceException(ResourceException.RESOURCE_NOT_FOUND,
                "Resource not found.");
    
private static native intgetResourceType0(int locale_index, int resourceID)
Method retrieves resource type for the given ID and locale.

param
resourceID resource identifier
param
locale_index index of locale in array of supported locales
return
resource type (0..FF), -1 if something is wrong

public booleanisValidResourceID(int resourceID)
Checks if given resource id exits in the bundle.

param
resourceID resource identifier
return
true if resource of given id exists in bundle.

        return isValidResourceID0(locale_index, resourceID);
    
private static native booleanisValidResourceID0(int locale_index, int resourceID)
Determine if a resource with the given ID and locale exists.

param
resourceID resource identifier
param
locale_index index of locale in array of supported locales
return
true if resource with the given ID exists for the given locale, false otherwise