Cogitek RIATest 6 Documentation Copyright © Cogitek Inc.

FileStream Object

FileStream object is used for reading and writting files.

Methods

MethodDescription

FileStream

FileStream()
Create a FileStream object.

close

close()
Close the file

getBytesAvailable

getBytesAvailable()
Returns number of bytes available for reading. For example:
var fs = new FileStream();

// Open a file for reading
fs.open("filename.txt",FileMode.READ);

verifyEqual(fs.getPosition(),0);
var fileSize = fs.getBytesAvailable();
verify(fileSize>0);

getPosition

getPosition()
Returns current file position

getTypeName

getTypeName()
Get the name of the object type.

hasOwnProperty

hasOwnProperty(propName)
Returns true if this object has a property with name equal to propName.

open

open(fileName, mode)
Open a file. mode is one of FileMode.READ, FileMode.WRITE, FileMode.APPEND, FileMode.UPDATE. See FileMode for modes. For example this will open a file for updating:
var fs = new FileStream();
fs.open("testfile.bin",FileMode.UPDATE);

readBoolean

readBoolean()
Reads a boolean value

readByte

readByte()
Reads a signed byte value

readBytes

readBytes(length)
Reads a sequence of length raw bytes and returns a ByteArray containing the bytes.

readDouble

readDouble()
Reads a 64 bit floating point value

readFloat

readFloat()
Reads a 32 bit floating point value

readInt

readInt()
Reads a signed 32 bit integer value

readMultibyte

readMultibyte(length,charset)
Reads a sequence of length bytes using specified charset and returns a String. Possible charsets are iso-8859-1 and utf-8. An example to read 6 bytes in CHARSET_ISO_8859_1 charset:
var fs = new FileStream();
fs.open("afile.txt",FileMode.READ);
var str = fs.readMultibyte(6,"iso-8859-1");

readShort

readShort()
Reads a signed 16 bit integer value

readUTFBytes

readUTFBytes(length)
Reads a sequence of UTF-8 bytes of specified length and returns a String. For example open a file in read mode and read a UTF string:
var fs = new FileStream();
fs.open("testfile.txt",FileMode.READ);
var str = fs.readUTFBytes(fs.getBytesAvailable());

readUnsignedByte

readUnsignedByte()
Reads an unsigned byte value

readUnsignedInt

readUnsignedInt()
Reads an unsigned 32 bit integer value

readUnsignedShort

readUnsignedShort()
Reads an unsigned 16 bit integer value

setPosition

setPosition(argument)
Sets current file position

toPrintableString

toPrintableString(maxLevels)
Returns full string representation of the object. maxLevels parameter will control how many levels of sub-objects to print for nested objects.

writeBoolean

writeBoolean(argument)
Writes a boolean value

writeByte

writeByte(argument)
Writes a signed byte value

writeBytes

writeBytes(byteArray)
Write a sequence of raw bytes stored in the byteArray parameter to the file. The number of bytes written is equal to the size of byteArray.

writeDouble

writeDouble(argument)
Writes a 64 bit floating point value

writeFloat

writeFloat(argument)
Writes a 32 bit floating point value

writeInt

writeInt(argument)
Writes a signed 32 bit integer value

writeMultibyte

writeMultibyte(string,charset)
Writes a String in specified charset encoding. Possible charsets are iso-8859-1 and utf-8

writeShort

writeShort(argument)
Writes a signed 16 bit integer value

writeUTFBytes

writeUTFBytes(argument)
Writes a String in UTF-8 encoding For example to append a string to file:
var fs = new FileStream();
fs.open("mylogfile.txt",FileMode.APPEND);
fs.writeUTFBytes("some string to append\n");
fs.close();

writeUnsignedByte

writeUnsignedByte(argument)
Writes an unsigned byte value

writeUnsignedInt

writeUnsignedInt(argument)
Writes an unsigned 32 bit integer value

writeUnsignedShort

writeUnsignedShort(argument)
Writes an unsigned 16 bit integer value

Found a typo? Have a suggestion? Please submit your request here.