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

DevResourceBundleReader

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

Fields Summary
private static com.sun.midp.security.SecurityToken
classSecurityToken
Security token to allow access to implementation APIs
com.sun.midp.io.j2me.storage.RandomAccessStream
storage
The RandomAccessStream private object.
Constructors Summary
public DevResourceBundleReader()
Creates a new instance of DevResourceBundleReader.


               
      
        super();
    
Methods Summary
public SerializableResourcedeserializeResource(SerializableResource sr, int resourceID)
Reads resource from the stream.

param
sr the resource that will be read from stream
param
resourceID the resource identifier
return
resource read from the stream
exception
IOException exception is thrown when error occurs while reading.

        moveStreamTo(resourceID);
        sr.read(istream);
        return sr;
    
protected voidfreeResourceBundle()
Closes resource bundle.

        if (storage == null) {
	        if (Logging.REPORT_LEVEL <= Logging.WARNING) {
	            Logging.report(Logging.WARNING, LogChannels.LC_JSR238,
	                           "Trying to close null storage");
	        }
        	return;
        }
        try {
        	istream.close();        	
		} catch (IOException e) {
	        if (Logging.REPORT_LEVEL <= Logging.WARNING) {
	            Logging.report(Logging.WARNING, LogChannels.LC_JSR238,
	                           "Exception while closing input stream: " + e.toString());
	        }
		}
        try {
        	storage.disconnect();        	
		} catch (IOException e) {
	        if (Logging.REPORT_LEVEL <= Logging.WARNING) {
	            Logging.report(Logging.WARNING, LogChannels.LC_JSR238,
	                           "Exception while disconnecting from storage: " + e.toString());
	        }
		}
    
public static ResourceBundleReadergetInstance(java.lang.String name)
Creates initialized instance of ResourceBundleReader, opens resource bundle and reads up header.

return
An initialized instance of ResourceBundleReader, null if resource bundle can't be read.
param
name path to resource bundle

        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
                           "DevResourceBundleReader: Get device resource " +
                           "bundle reader for \"" + name + "\"");
        }
        DevResourceBundleReader devreader = new DevResourceBundleReader();
        if (!devreader.initialize(name)) {
            return null;
        }
        // bundle wasn't found

        return devreader;
    
protected java.io.InputStreamgetResourceBundleAsStream()
Opens resource bundle and return its stream. Bundle is opened from storage root.

return
stream for reading resource bundle or null if stream can't be opened.

        try {
            if (storage == null) {
                storage = new RandomAccessStream(classSecurityToken);
            }
            if (storage == null) {
                throw new IOException("Cannot access storage.");
            }
	    storage.connect(File.getConfigRoot(Constants.INTERNAL_STORAGE_ID) + Configuration
                            .getProperty("microedition.global.root")
                            + resourceName, Connector.READ);
            return storage.openInputStream();
            
        } catch (IOException ioe) {
            if (Logging.TRACE_ENABLED) {
                Logging.trace(ioe, "");
            }
            return null;
        }