recordstorefile.jpp

来自「This is a resource based on j2me embedde」· JPP 代码 · 共 459 行 · 第 1/2 页

JPP
459
字号
     *        pointer to.     *     * @exception IOException if there is a problem with the seek.     */    public void seek(int pos) throws IOException {        setPosition(handle, pos);    }    /**     * Sets the position within <code>recordStream</code> to     * <code>pos</code>.  This will implicitly grow     * the underlying stream if <code>pos</code> is made greater     * than the current length of the storage stream.     *     * @param handle handle to a record store file     * @param pos position within the file to move the current_pos     *        pointer to.     *     * @exception IOException if there is a problem with the seek.     */    private static native void setPosition(int handle, int pos)        throws IOException;    /**     * Write all of <code>buf</code> to <code>recordStream</code>.     *     * @param buf buffer to read out of.     *     * @exception IOException if a write error occurs.     */    public void write(byte[] buf) throws IOException {        write(buf, 0, buf.length);    }    /**     * Write <code>buf</code> to <code>recordStream</code>, starting     * at <code>offset</code> and continuing for <code>numBytes</code>     * bytes.     *     * @param buf buffer to read out of.     * @param offset starting point write offset, from beginning of buffer.     * @param numBytes the number of bytes to write.     *     * @exception IOException if a write error occurs.     */    public void write(byte[] buf, int offset, int numBytes)            throws IOException {        if (numBytes == 0) {            return;        }        // Test before we goto the native code        // This expression will cause a ArrayOutOfBoundsException if the values        // passed for offset and numBytes is not valid and is much faster then        // explicitly checking the values with if statements.        int test = buf[offset] + buf[numBytes - 1] +            buf[offset + numBytes - 1];        writeBytes(handle, buf, offset, numBytes);    }    /**     * Write <code>buf</code> to <code>recordStream</code>, starting     * at <code>offset</code> and continuing for <code>numBytes</code>     * bytes.     *     * @param handle handle to a record store file     * @param buf buffer to read out of.     * @param offset starting point write offset, from beginning of buffer.     * @param numBytes the number of bytes to write.     *     * @exception IOException if a write error occurs.     */    private static native void writeBytes(int handle, byte[] buf, int offset,                                   int numBytes) throws IOException;    /**     * Commit pending writes     *     * @exception IOException if an error occurs while flushing     *            <code>recordStream</code>.     */    public void commitWrite() throws IOException {        commitWrite(handle);    }    /**     * Commit pending writes     *     * @param handle handle to a record store file     *     * @exception IOException if an error occurs while flushing     *            <code>recordStream</code>.     */    private native static void commitWrite(int handle) throws IOException;    /**     * Read up to <code>buf.length</code> into <code>buf</code>.     *     * @param buf buffer to read in to.     *     * @return the number of bytes read.     *     * @exception IOException if a read error occurs.     */    public int read(byte[] buf) throws IOException {        return read(buf, 0, buf.length);    }    /**     * Read up to <code>buf.length</code> into <code>buf</code>     * 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 {        if (numBytes == 0) {            return 0;        }        // Test before we goto the native code        // This expression will cause a ArrayOutOfBoundsException if the values        // passed for offset and numBytes is not valid and is much faster then        // explicitly checking the values with if statements.        int test = buf[offset] + buf[numBytes - 1] +            buf[offset + numBytes - 1];        return readBytes(handle, buf, offset, numBytes);    }    /**     * Read up to <code>buf.length</code> into <code>buf</code>     * starting at offset <code>offset</code> in <code>recordStream     * </code> and continuing for up to <code>numBytes</code> bytes.     *     * @param handle handle to a record store file     * @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.     */    private static native int readBytes(int handle, byte[] buf, int offset,                                        int numBytes) throws IOException;    /**     * 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 {        int temp;        if (handle == -1) {            return;        }        temp = handle;        handle = -1;        closeFile(temp);    }    /**     * Disconnect from <code>recordStream</code> if it is     * non null.  May be called more than once without error.     *     * @param handle handle to a record store file     *     * @exception IOException if an error occurs closing     *            <code>recordStream</code>.     */    private native static void closeFile(int handle) throws IOException;    /**     * 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 {        truncateFile(handle, size);    }    /**     * 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 handle handle to a record store file     * @param size new size for this file.     *     * @exception IOException if an error occurs, or if     * <code>size</code> is less than zero.     */    private static native void truncateFile(int handle,                                            int size) throws IOException;    /**     * Ensures native resources are freed when Object is collected.     */// #ifdef ENABLE_CDC    protected native void finalize();// #else    private native void finalize();// #endif}

⌨️ 快捷键说明

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