• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.1.1.43
RandomAccessFile Class Reference

Secure store replacement for the java.io.RandomAccessFile class. More...

Inheritance diagram for RandomAccessFile:
DataInput DataOutput Closeable

Description

This class is a replacement for the java.io.RandomAccessFile class for accessing the BlackBerry Dynamics secure file system.

See the com.good.gd.file package documentation for an introduction to the secure file system.

This class supports both read and write operations, and maintains a file pointer for every open file. The file pointer can be repositioned forwards or backwards to any position in the file. This is different to the FileInputStream and FileOutputStream classes. The FileInputStream class supports only read operations. The FileOutputStream class supports only write operations and doesn't support repositioning of the file pointer.

This class has the same programming interface as the java.io.RandomAccessFile class, with the following exceptions.

  • Only the following modes are supported: read-only "r", read-write "rw".

See also
java.io.RandomAccessFile class reference on the android.com developer website for details of all methods.

Notice

The following notice applies to the original API on which this API is based, and to its documentation. The documentation of this API has been revised from the original.

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Public Member Functions

 RandomAccessFile (File file, String mode) throws FileNotFoundException
 Constructor that opens a file in the secure store, from a File containing the path. More...
 
 RandomAccessFile (String file, String mode) throws FileNotFoundException
 Constructor that opens a file in the secure store, from a String containing the path. More...
 
int read () throws IOException
 Read one byte from a file in the secure store. More...
 
int read (byte[] b) throws IOException
 Fill a byte buffer with data read from a file in the secure store. More...
 
int read (byte[] b, int off, int len) throws IOException
 Read a specified amount of data from a file in the secure store into a byte buffer, at a specified offset. More...
 
long getFilePointer () throws IOException
 Returns the current position of the file pointer in an open file in the secure store. More...
 
void seek (long pos) throws IOException
 Reposition the file pointer of an open file in the secure store. More...
 
long length () throws IOException
 Get the length of a file in the secure store. More...
 
void setLength (long newLength) throws IOException
 Set the length of a file in the secure store. More...
 
void close ()
 Close a file in the secure store. More...
 
void write (int b) throws IOException
 Write one byte to a file in the secure store. More...
 
void write (byte[] b) throws IOException
 Write a byte buffer to a file in the secure store. More...
 
void write (byte[] b, int off, int len) throws IOException
 Write a specified amount of data, from a specified offset into a byte buffer, into a file in the secure store. More...
 
void writeBoolean (boolean val) throws IOException
 Write a boolean value to a file in the secure store, as a single byte. More...
 
void writeByte (int val) throws IOException
 Write one byte to a file in the secure store. More...
 
void writeBytes (String str) throws IOException
 Write bytes from a String to a file in the secure store. More...
 
void writeChar (int val) throws IOException
 Write a two-byte character to a file in the secure store. More...
 
void writeChars (String str) throws IOException
 Write two-byte characters from a String to a file in the secure store. More...
 
void writeDouble (double val) throws IOException
 Write a double value to a file in the secure store. More...
 
void writeFloat (float val) throws IOException
 Write a float value to a file in the secure store. More...
 
void writeInt (int val) throws IOException
 Write an int value to a file in the secure store. More...
 
void writeLong (long val) throws IOException
 Write a long value to a file in the secure store. More...
 
void writeShort (int val) throws IOException
 Write a short value to a file in the secure store. More...
 
void writeUTF (String str) throws IOException
 Write a UTF-8 representation of a String to a file in the secure store. More...
 
boolean readBoolean () throws IOException
 Read a boolean from a file in the secure store. More...
 
byte readByte () throws IOException
 Read a byte from a file in the secure store. More...
 
char readChar () throws IOException
 Read a two-byte character from a file in the secure store. More...
 
double readDouble () throws IOException
 Read a double from a file in the secure store. More...
 
float readFloat () throws IOException
 Read a float from a file in the secure store. More...
 
final void readFully (byte[] b) throws IOException
 Fill a byte buffer with data read from a file in the secure store. More...
 
final void readFully (byte[] b, int off, int len) throws IOException
 Read a specified amount of data from a file in the secure store into a byte buffer, at a specified offset. More...
 
int readInt () throws IOException
 Read an int from a file in the secure store. More...
 
String readLine () throws IOException
 Read a line of text from a file in the secure store. More...
 
long readLong () throws IOException
 Read a long from a file in the secure store. More...
 
short readShort () throws IOException
 Read a short from a file in the secure store. More...
 
String readUTF () throws IOException
 Read a UTF-8 String from a file in the secure store. More...
 
int readUnsignedByte () throws IOException
 Read an unsigned byte from a file in the secure file system. More...
 
int readUnsignedShort () throws IOException
 Read an unsigned short from a file in the secure file system. More...
 
int skipBytes (int n) throws IOException
 Skip a number of bytes in an open file in the secure system. More...
 

Constructor & Destructor Documentation

◆ RandomAccessFile() [1/2]

RandomAccessFile ( File  file,
String  mode 
) throws FileNotFoundException

Call this constructor to open a file in the secure store, in the specified mode. The specified mode can be read-only or read-write.

Parameters
fileFile containing the path of the file to open, in the secure file system.
modeString specifying the mode: "r" for read-only, "rw" for read-write.
Exceptions
FileNotFoundException
com.good.gd.error.GDNotAuthorizedErrorif BlackBerry Dynamics authorization processing has not yet completed.

◆ RandomAccessFile() [2/2]

RandomAccessFile ( String  file,
String  mode 
) throws FileNotFoundException

Call this constructor to open a file in the secure store, in the specified mode. The specified mode can be read-only or read-write.

Parameters
fileString containing the path of the file to open, in the secure file system.
modeString specifying the mode: "r" for read-only, "rw" for read-write.
Exceptions
FileNotFoundException
com.good.gd.error.GDNotAuthorizedErrorif BlackBerry Dynamics authorization processing has not yet completed.

Member Function Documentation

◆ read() [1/3]

int read ( ) throws IOException

Call this method to read one byte from an open file in the secure store. Reading this data advances the file pointer by one byte.

Returns
int representation of the next byte of data, or -1 if the end of the file has been reached.
Exceptions
IOException

◆ read() [2/3]

int read ( byte[]  b) throws IOException

Call this method to read data from a file in the secure store into a byte buffer. Reading data advances the file pointer by the number of bytes read. No more data will be read than can be stored in the buffer.

Parameters
bbyte array into which data will be read.
Returns
int representation of the number of bytes actually read, or -1 if the end of the file has been reached.
Exceptions
IOException

◆ read() [3/3]

int read ( byte[]  b,
int  off,
int  len 
) throws IOException

Call this method to read data from a file in the secure store into a byte buffer. The data that is read will be written into the buffer starting at a specified offset. Reading data advances the file pointer by the number of bytes read. No more data will be read than a specified maximum.

Parameters
bbyte array for the buffer into which data will be written.
offint offset into the buffer, at which writing is to begin.
lenint maximum number of bytes to read.
Returns
int representation of the number of bytes actually read, or -1 if the end of the file has been reached.
Exceptions
IOException

◆ getFilePointer()

long getFilePointer ( ) throws IOException

Call this method to get the current position of the file pointer in an open file in the secure store. The position is returned as a number of bytes offset from the start of the file.

Returns
long representation of the current position of the file pointer.
Exceptions
IOException

◆ seek()

void seek ( long  pos) throws IOException

Call this method to set the position of the file pointer in an open file in the secure store. The required position is specified as a number of bytes offset from the start of the file.

Parameters
poslong representation of the required position of the file pointer.
Exceptions
IOException

◆ length()

long length ( ) throws IOException
Returns
long representation of the length of the file in bytes.
Exceptions
IOException

◆ setLength()

void setLength ( long  newLength) throws IOException

Call this method to set the length of an open file in the secure store. The required length is specified as a number of bytes.

If the specified length is greater than the current file length, then the file will be padded out to the specified length. If the length is less than the current file length, then the file will be truncated.

Parameters
newLengthlong representation of the required length of the file.
Exceptions
IOException

◆ close()

void close ( )

Call this method to close an open file in the secure store. Any resources associated with the open file's stream will be released. Data that is pending write will be committed to the secure store.

Calling this method is the only way to confirm finalisation of writing data to the secure file system.

◆ write() [1/3]

void write ( int  b) throws IOException

Call this method to write one byte of data to a file in the secure store. Writing this data advances the file pointer by one byte.

Parameters
bint representation of the byte to write.
Exceptions
IOException

◆ write() [2/3]

void write ( byte[]  b) throws IOException

Call this method to write bytes from an array into a file in the secure store. The file pointer will advance by the number of bytes written.

Parameters
bbyte array from which to write.
Exceptions
IOException

◆ write() [3/3]

void write ( byte[]  b,
int  off,
int  len 
) throws IOException

Call this method to write a specified amount of data from a byte buffer into a file in the secure store. The data will be read from the buffer, starting at a specified offset. The file pointer will advance by the number of bytes written.

Parameters
bbyte array for the buffer from which data will be read.
offint offset into the buffer, from which reading is to begin.
lenint maximum number of bytes to write.
Exceptions
IOException

◆ writeBoolean()

void writeBoolean ( boolean  val) throws IOException

Call this method to write a boolean value to a file in the secure store. The value is written as a single byte, so the file pointer advances by one byte when this data is written.

Parameters
valboolean value to write.
Exceptions
IOException

◆ writeByte()

void writeByte ( int  val) throws IOException

Call this method to write one byte of data to a file in the secure store. Writing this data advances the file pointer by one byte.

Parameters
valint representation of the byte to write.
Exceptions
IOException

◆ writeBytes()

void writeBytes ( String  str) throws IOException

Call this method to write bytes from a String into a file in the secure store. One byte will be written for each character in the string, with the high eight bits of each character being discarded. The file pointer will advance by the number of bytes written.

Parameters
strString from which to write bytes.
Exceptions
IOException

◆ writeChar()

void writeChar ( int  val) throws IOException

Call this method to write a two-byte character to a file in the secure store. The high byte will be written first. The file pointer will advance by two bytes.

Parameters
valint representation of the character to write.
Exceptions
IOException

◆ writeChars()

void writeChars ( String  str) throws IOException

Call this method to write two-byte characters from a String into a file in the secure store. Each character is written as if the writeChar method had been called. The file pointer will advance by the number of bytes written.

Parameters
strString to write.
Exceptions
IOException

◆ writeDouble()

void writeDouble ( double  val) throws IOException

Call this method to write a double value to a file in the secure store. The doubleToLongBits method in the Double class is used to generate a byte representation of the value. The file pointer will advance by the number of bytes written.

Parameters
valdouble to write.
Exceptions
IOException
See also
doubleToLongBits reference documentation in the java.lang.Double class reference on the android.com developer website.

◆ writeFloat()

void writeFloat ( float  val) throws IOException

Call this method to write a float value to a file in the secure store. The floatToIntBits method in the Float class is used to generate a byte representation of the value. The file pointer will advance by the number of bytes written.

Parameters
valfloat to write.
Exceptions
IOException
See also
floatToIntBits method documentation in the java.lang.Float class reference on the android.com developer website.

◆ writeInt()

void writeInt ( int  val) throws IOException

Call this method to write an int value to a file in the secure store. The bytes are written in order from most significant to least significant. The file pointer will advance by the number of bytes written.

Parameters
valint to write.
Exceptions
IOException

◆ writeLong()

void writeLong ( long  val) throws IOException

Call this method to write a long value to a file in the secure store. The bytes are written in order from most significant to least significant. The file pointer will advance by the number of bytes written.

Parameters
vallong to write.
Exceptions
IOException

◆ writeShort()

void writeShort ( int  val) throws IOException

Call this method to write a short value to a file in the secure store. The bytes are written in order from most significant to least significant. The file pointer will advance by the number of bytes written.

Parameters
valshort to write.
Exceptions
IOException

◆ writeUTF()

void writeUTF ( String  str) throws IOException

Call this method to write the characters from a String into a file in the secure store. The UTF-8 representations of the string will be written, which will include an explicit length. The file pointer will advance by the number of bytes written.

Parameters
strString to write.
Exceptions
IOException

◆ readBoolean()

boolean readBoolean ( ) throws IOException

Call this method to read a boolean value from a file in the secure store. Representation of the data in the file is assumed to be the same as that used by the writeBoolean method. The file pointer will advance by one byte.

Returns
boolean representation of the byte at the file pointer.
Exceptions
IOException

◆ readByte()

byte readByte ( ) throws IOException

Call this method to read a byte from a file in the secure store. Representation of the data in the file is assumed to be the same as that used by the writeByte method. The file pointer will advance by one byte.

Returns
int representation of the byte at the file pointer.
Exceptions
IOException

◆ readChar()

char readChar ( ) throws IOException

Call this method to read a two-byte character from a file in the secure store. Representation of the data in the file is assumed to be the same as that used by the writeChar method. The file pointer will advance by two bytes.

Returns
char representation of the data at the file pointer.
Exceptions
IOException

◆ readDouble()

double readDouble ( ) throws IOException

Call this method to read a double value from a file in the secure store. Representation of the data in the file is assumed to be the same as that used by the writeDouble method. The longBitsToDouble method in the Double class is used to generate a value from the data in the file. The file pointer will advance by the number of bytes read.

Returns
double representation of the data at the file pointer.
Exceptions
IOException
See also
longBitsToDouble method documentation in the java.lang.Double class reference on the android.com developer website.

◆ readFloat()

float readFloat ( ) throws IOException

Call this method to read a float value from a file in the secure store. Representation of the data in the file is assumed to be the same as that used by the writeFloat method. The intBitsToFloat method in the Double class is used to generate a value from the data in the file. The file pointer will advance by the number of bytes read.

Returns
float representation of the data at the file pointer.
Exceptions
IOException
See also
intBitsToFloat method documentation in the java.lang.Float class reference on the android.com developer website.

◆ readFully() [1/2]

final void readFully ( byte[]  b) throws IOException

Call this method to read data from a file in the secure store into a byte buffer. Enough data to fill the buffer will be read from the file, if possible. If there isn't enough data remaining in the file, an exception will be thrown. The file pointer will advance by the number of bytes read.

Parameters
bbyte array for the buffer into which data will be read from the file pointer.
Exceptions
IOException

◆ readFully() [2/2]

final void readFully ( byte[]  b,
int  off,
int  len 
) throws IOException

Call this method to read data from a file in the secure store into a byte buffer. The data that is read will be written into the buffer starting at a specified offset. A specified number of bytes will be read from the file, if possible. If there isn't enough data remaining in the file, an exception will be thrown. The file pointer will advance by the number of bytes read.

Parameters
bbyte array for the buffer into which data will be written.
offint offset into the buffer, at which writing is to begin.
lenint maximum number of bytes to read.
Exceptions
IOException

◆ readInt()

int readInt ( ) throws IOException

Call this method to read an int value from a file in the secure store. Representation of the data in the file is assumed to be the same as that used by the writeInt method. The file pointer will advance by the number of bytes read.

Returns
int representation of the data at the file pointer.
Exceptions
IOException

◆ readLine()

String readLine ( ) throws IOException

Call this method to read a line of text from a file in the secure store. The file pointer will advance past the line termination sequence, if there is one, or to the end of the file otherwise.

Returns
String representation of the line read from the file pointer. The line termination sequence, if any, is discarded.
Exceptions
IOException

◆ readLong()

long readLong ( ) throws IOException

Call this method to read an long value from a file in the secure store. Representation of the data in the file is assumed to be the same as that used by the writeLong method. The file pointer will advance by the number of bytes read.

Returns
long representation of the data at the file pointer.
Exceptions
IOException

◆ readShort()

short readShort ( ) throws IOException

Call this method to read a short value from a file in the secure store. Representation of the data in the file is assumed to be the same as that used by the writeShort method. The file pointer will advance by the number of bytes read.

Returns
short representation of the data at the file pointer.
Exceptions
IOException

◆ readUTF()

String readUTF ( ) throws IOException

Call this method to read a UTF-8 String value from a file in the secure store. Representation of the data in the file is assumed to be the same as that used by the writeUTF method. The file pointer will advance by the number of bytes read.

Returns
String representation of the data at the file pointer.
Exceptions
IOException

◆ readUnsignedByte()

int readUnsignedByte ( ) throws IOException

Call this method to read an unsigned byte from a file in the secure store. Representation of the data in the file is assumed to be the same as that used by the writeByte method when passed an unsigned value. The file pointer will advance by one byte.

Returns
int representation of the byte at the file pointer.
Exceptions
IOException

◆ readUnsignedShort()

int readUnsignedShort ( ) throws IOException

Call this method to read an unsigned short from a file in the secure store. Representation of the data in the file is assumed to be the same as that used by the writeShort method when passed an unsigned value. The file pointer will advance by the number of bytes read.

Returns
int representation of the unsigned short at the file pointer.
Exceptions
IOException

◆ skipBytes()

int skipBytes ( int  n) throws IOException

Call this method to advance the file pointer of an open file in the secure store without reading or writing data.

Advancing the specified number of bytes specified might be impossible, for example if there are fewer bytes remaining after the file pointer. In that case, the file pointer will advance to the end of the file.

Parameters
nint specifying the number of bytes to advance.
Returns
int representation of the number of bytes actually advanced.
Exceptions
IOException