⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 recordstorefile.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * starting at offset <code>offset</code> in <code>recordStream     * </code> and continuing for up to <code>numBytes</code> bytes.     *     * @param buf buffer to read in to.     * @param offset starting point read offset, from beginning of buffer.     * @param numBytes the number of bytes to read.     *     * @return the number of bytes read.     *     * @exception IOException if a read error occurs.     */    public int read(byte[] buf, int offset, int numBytes) throws IOException    {	return recordStream.readBytes(buf, offset, numBytes);    }      /**     * Disconnect from <code>recordStream</code> if it is     * non null.  May be called more than once without error.     *     * @exception IOException if an error occurs closing      *            <code>recordStream</code>.     */    public void close() throws IOException    {	// close recordStream if it exists	if (recordStream != null) {	    recordStream.disconnect();	    recordStream = null;	}    }    /**     * Sets the length of this <code>RecordStoreFile</code>      * <code>size</code> bytes.  If this file was previously     * larger than <code>size</code> the extra data is lost.     *     * <code>size</code> must be <= the current length of     * <code>recordStream</code>     *     * @param size new size for this file.     *     * @exception IOException if an error occurs, or if     * <code>size</code> is less than zero.     */    public void truncate(int size) throws IOException    {	if (recordStream != null) {    	    recordStream.truncate(size);	}        }    /**     * Returns an array of the names of record stores owned by the      * MIDlet suite. Note that if the MIDlet suite does not      * have any record stores, this function will return NULL.      *     * @return an array of record store names.      */     public static String[] listRecordStores() {        return listRecordStoresForSuite(new File(classSecurityToken),            getStoragePath(null), false);    }    /**     * Returns an array of the names of record stores owned by the      * MIDlet suite. Note that if the MIDlet suite does not      * have any record stores, this function will return NULL.      *     * @param storage persisent storage access object     * @param suiteStorageRoot storage root name of the suite     * @param rawNames if true, raw filenames will be output instead of     *  processed record store names.     *     * @return an array of record store names.      */     private static String[] listRecordStoresForSuite(File storage,                                                     String suiteStorageRoot,                                                     boolean rawNames) {	Vector files;	Vector names;	String file;	String asciiName;		files = storage.filenamesThatStartWith(suiteStorageRoot);	names = new Vector();		// work through list of strings from the directory	for (int i = 0; i < files.size(); i++) {	    file = (String)files.elementAt(i);	    if (file.endsWith(dbExtension)) {                if (rawNames) {                    names.addElement(file);                } else {                    /*                     * some or all of the strings in foo may be encoded                      * into a system specific format.  decode them before                     * adding to names.                     */                    asciiName = file.substring(suiteStorageRoot.length(), 					   file.length() - 3);                    names.addElement(File.asciiFilenameToUnicode(asciiName));                }	    }	}	if (names.size() == 0) {	    return null;	}		String[] rv = new String[names.size()];	names.copyInto(rv);	return rv;    }        /**     * Remove all the Record Stores for a suite.     *     * @param token security token with MIDP internal permisison     * @param suiteStorageRoot storage root name of the suite     */     public static void removeRecordStoresForSuite(SecurityToken token,            String suiteStorageRoot) {        File storage;	String[] filenames;		storage = new File(token);        filenames = listRecordStoresForSuite(storage, suiteStorageRoot, true);        if (filenames == null) {            return;        }        for (int i = 0; i < filenames.length; i++) {            try {                storage.delete(filenames[i]);            } catch (IOException ioe) {                // move on to the next suite            }        }    }        /**     * Returns true if the suite has created at least one record store.     *     * @param suiteStorageRoot storage root name of the suite     *     * @return true if the suite has at least one record store     */     public static boolean suiteHasRmsData(String suiteStorageRoot) {	File storage = new File(classSecurityToken);	Vector files = storage.filenamesThatStartWith(suiteStorageRoot);	for (int i = 0; i < files.size(); i++) {	    String file = (String)files.elementAt(i);	    if (file.endsWith(dbExtension)) {                return true;            }        }        return false;    }    /**     * Approximation of remaining space in storage.     *     * Usage Warning:  This may be a slow operation if     * the platform has to look at the size of each file     * stored in the MIDP memory space and include its size     * in the total.     *     * @return the aproximate space available to grow the     *         record store in bytes.     */    public static int spaceAvailable()    {	return new File(classSecurityToken).getBytesAvailableForFiles();    }    /**      * Given a null argument this helper functions returns a      * path to where record stores should be stored for the     * MIDlet suite of the calling MIDlet process.  If <code>name     * </code> is non null it returns the full path of that     * record store in the file system:     * <storage_path><ascii_converted_'name'>.db     *      * @param name name of target record store, or null if only the     *        storage path for the current MIDlet suite is desired.     *     * @return the relative path to where record store files for the     *         current MIDlet suite are stored if <code>name</code>      *         is null, or the complete system path for storage     *         of the record store <code>name</code>.     */    private static String getStoragePath(String name)    {	String str;	MIDletSuite mSuite;	StringBuffer path;		mSuite = Scheduler.getScheduler().getMIDletSuite();		// MIDletSuite msuite should not be null.	str = mSuite.getStorageRoot();	if (name != null) {	    path = new StringBuffer(str);	    // convert the unicode filename into a system acceptable string	    path.append(File.unicodeToAsciiFilename(name));	    path.append(dbExtension);	    str = path.toString();	}	return str;    }        /**     * If <code>name</code>, <code>suite</code>, and <code>vendor</code>      * are all non null, returns the full path of that record store     * in the file system:     * <storage_path><ascii_converted_'name'>.db     *     * @param vendor vendor of target record store     * @param suite suite of target record store     * @param name name of target record store     *     * @return the complete system path for storage     *         of the record store <code>name</code>.     */    private static String getStoragePath(String vendor, String suite, 					 String name) {	String str = File.getStorageRoot();	StringBuffer path = new StringBuffer(str);	if (vendor != null && suite != null) { 	    path.append(File.unicodeToAsciiFilename(vendor));	    path.append('_');	    path.append(File.unicodeToAsciiFilename(suite));	    path.append('_');	} 	if (name != null) {	    path.append(File.unicodeToAsciiFilename(name));	    path.append(dbExtension);	    str = path.toString();	}	return str;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -