Aztec® Programming Language
Version 1.1 Alpha 2

Copyright © 2010-2017, Aztec Development Group, All Rights Reserved

Download Aztec

Search        Contact Us

You're far too keen on where and how... and not so hot on why.

- Andrew Lloyd Webber and Tim Rice

 

aztec.io.FileStream

public class FileStream from<StreamIO>

Base

StreamIO

FileStream

The FileStream class provides buffered binary stream I/O for files. It provides an internal pointer position within the file where the next read or write operation will occur. It supports direct access, so the pointer position can be manually moved around to read or write anywhere within the file. Each read and write operation also advances the pointer position by the size of the read/write operation.

 

FileStream Methods

FileStream() Constructor for the FileStream class using a file name
FileStream() Constructor for the FileStream class using a File object
File() Returns reference to the File object it used in constructor
FileName() Returns the file name associated with this file stream
Open() Opens the file for I/O based on the parameters sent to constructor
Flush() Flush the contents of internal buffers to the file
Close() Close the file and flush all internal buffers to the file
Size() Returns the current size of the binary file
BytesAvailable() Virtual method to return the number of bytes available to read before end of file
Pos() Virtual method to return the current position within the file
SetPos() Virtual method to set the current position within the file
DirectAccess() Virtual method to return true since Direct Access I/O is available for files
EndOfStream() Virtual method to return true if currently at end of stream
Read() Virtual method to read a single 8 byte integer from the file
Read() Virtual method to read a single "small" integer from the file (1, 2 or 4 bytes)
Read() Virtual method to read a single float from the file (4 or 8 bytes)
Read() Virtual method to read a text string from the file (default length or specific length)
Read() Virtual method to read a boolean from the file
Read() Virtual method to read a binary buffer (stream) from the file
Write() Virtual method to write a single 8 byte integer to the file
Write() Virtual method to write a single "small" integer to the file (1, 2 or 4 bytes)
Write() Virtual method to write a single float to the file (4 or 8 bytes)
Write() Virtual method to write a single text string (default or specific length)
Write() Virtual method to write a single boolean to the file
Write() Virtual method to write a binary buffer (stream) to the file

Derived Classes

See Also

 


FileStream()

public method FileStream(string FileName, int IOMode = StreamIO.ReadMode, bool truncate = true, bool append = false, int BufferSize = 32767)

Parameters

FileName

File name to be used for I/O operations

IOMode

Indicates mode of I/O which is valid

Truncate

Clears the contents of the file for Write or ReadWrite modes

Append

Append data to file if true

BufferSize

Size of the internal memory buffer

Return Value

None

Description

Constructor for the FileStream class. The I/O mode (ReadMode, WriteMode or ReadWriteMode) is specified along with the file name to be associated with the I/O operations for this file stream. The file should contain a fully qualified path.

 

The truncate flag, the append flag and the buffer size are used when the file is opened using the Open() method. The file itself is not validated or opened in this constructor.

 

FileStream Class

 


FileStream()

public method FileStream(File FileRef, int IOMode = StreamIO.ReadMode, bool truncate = true, bool append = false, int BufferSize = 32767)

Parameters

FileRef

File object specifying file to be used for I/O operations

IOMode

Indicates mode of I/O which is valid

Truncate

Clears the contents of the file for Write or ReadWrite modes

Append

Append data to file if true

BufferSize

Size of the internal memory buffer

Return Value

None

Description

Constructor for the FileStream class. The I/O mode (ReadMode, WriteMode or ReadWriteMode) is specified along with the 'File' object which specifies the file name to be associated with the I/O operations for this file stream.

 

The truncate flag, the append flag and the buffer size are used when the file is opened using the Open() method. The file itself is not validated or opened in this constructor.

 

FileStream Class


File()

public method<File> File()

Parameters

None

Return Value

Returns File object associated with file stream or null

Description

Returns the File object which contains the file name associated with this file stream. If the "file name" version of the constructor was used, this method will return null.

 

FileStream Class


FileName()

public method<string> FileName()

Parameters

None

Return Value

Returns the file name

Description

Returns the file name associated with this file stream.

 

FileStream Class


Open()

public virtual method<bool> Open(bool FireException = true)

Parameters

FireException

If true, fires exception if error or file not found

Return Value

Returns true if file opened successfully

Description

Thie method opens the file associated with this file stream. If the IOType is 'ReadWrite' or 'Write' and the truncate flag was true in the constructor, the contents of the file are cleared. If the append flag is true, the file pointer is adjusted to the end of the file, otherwise the pointer is set at the beginning of the stream.

 

If the file is opened successfully, the method returns true. If the file does not exist or there was an access error, the method will fire a StreamException, as long as the FireException flag is true. If it's false, the method simply returns false.

 

FileStream Class


Flush()

public virtual method Flush()

Parameters

None

Return Value

None

Description

This method flushes the contents of the internal memory buffers to the file. A StreamException is fired if an error occurs.

 

FileStream Class


Close()

public virtual method Close()

Parameters

None

Return Value

None

Description

This method flushes the contents of the internal memory buffers to the file and then closes the file. A StreamException is fired if an error occurs.

 

No more stream I/O can be performed on the file once it is closed.

 

FileStream Class


Size()

public virtual method<int> Size()

Parameters

None

Return Value

Number of bytes in file

Description

Returns the total number of bytes currentlly in the file (based on original file size plus adjustments based on all read and write operations performed on the stream).

 

FileStream Class


BytesAvailable()

public virtual method<int> BytesAvailable()

Parameters

None

Return Value

Number of bytes available to read

Description

Returns the number of bytes available to read from the file. It is based on the current pointer position and the total size of the file.

 

FileStream Class


Pos()

public virtual method<int> Pos()

Parameters

None

Return Value

Current read/write pointer position

Description

Virtual method to return the current pointer position within the file (one based). The next read or write operation takes place at this position.

 

FileStream Class


SetPos()

public virtual method<bool> SetPos(int PointerPosition)

Parameters

PointerPosition

One based position in stream to read/write

Return Value

true if successful

Description

Virtual method to set the current read/write pointer position with the file (one based). The next read or write operation will take place at this position.

 

FileStream Class


DirectAccess()

public virtual method<bool> DirectAccess()

Parameters

None

Return Value

Returns true

Description

Virtual method to return the direct access mode, which is always 'true' for files.

 

FileStream Class


EndOfStream()

public virtual method<bool> EndOfStream()

Parameters

None

Return Value

Returns true if at end of stream

Description

Virtual method to return the value of the "end of stream" flag. If there are no bytes available in the file to read, this method returns true and false if there are one or more bytes available to read.

 

FileStream Class


Read()

public virtual method Read(int ref IntBucket, bool PeekOnly = false)

Parameters

IntBucket

Integer reference to receive the value

PeekOnly

If true, peek without reading/removing

Return Value

None

Description

Virtual method to read a single binary 8 byte integer value from the file and copy the value into the IntBucket.

 

If the stream is specified as "WriteMode", this method will fire a StreamException.

 

FileStream Class


Read()

public virtual method Read(int ref IntBucket, SmallInt IntSizeEnum, bool IsSigned = true, bool PeekOnly = false)

Parameters

IntBucket

Integer reference to receive the value

IntSizeEnum

Enumeration to indicate 1, 2 or 4 byte integer

IsSigned

Treat as signed integer If true, and unsigned if false (default is false)

PeekOnly

Peek without reading/removing if true (default is false)

Return Value

None

Description

Virtual method to read a single "small" binary integer value from the file and copy the value into the IntBucket. The size of the integer read operation is specified by IntSizeEnum, and represents 1, 2 or 4 bytes. The "IsSigned" flag is also used to affect how the binary integer buffer is interpreted, signed or unsiged.

 

If the stream is specified as "WriteMode", this method will fire a StreamException.

 

FileStream Class


Read()

public virtual method Read(float ref FloatBucket, bool Read32BitFloat = false, bool PeekOnly = false)

Parameters

FloatBucket

Float reference to receive the value

Read32BitFloat

Read 32 bit (4 byte) float if true (default is false)

PeekOnly

If true, read without advancing pointer

Return Value

None

Description

Virtual method to read a single binary floating point value from the file and copy the value into the FloatBucket. The default size of the float read operation is 8 bytes, but can be changed to 4 bytes by setting the "Read32BitFloat" flag. If the "PeekOnly" flag is true, the value is read but the file pointer position is not advanced, so the next read operation will read the same data.

 

If the stream is specified as "WriteMode", this method will fire a StreamException.

 

FileStream Class


Read()

public virtual method Read(string ref StringBucket, bool ExtractLength = true, int ReadSize = 0, bool PeekOnly = false)

Parameters

StringBucket

String reference to receive the value

ExtractLength

Read the string length from the stream if true

ReadSize

Size of the read operation if ExtractLength is false

PeekOnly

If true, read without advancing pointer

Return Value

None

Description

Virtual method to read a single string from the file and copy the value into the StringBucket. This supports reading a variable length string, and there are two ways of handling this. If the "ExtractLength" flag is true, the size of the string is actually read from the file (as a 4 byte integer) and then the string read operation is dictacted by that size. If the "ExtractLength" flag is false, the "ReadSize" value is then used to dictate the length of the string to be read.

 

If the "PeekOnly" flag is true, the value is read but the file pointer position is not advanced, so the next read operation will read the same data.

 

If the stream is specified as "WriteMode", this method will fire a StreamException.

 

FileStream Class


Read()

public virtual method Read(bool ref BoolBucket, bool PeekOnly = false)

Parameters

BoolBucket

Boolean reference to receive the value

PeekOnly

If true, read without advancing pointer

Return Value

None

Description

Virtual method to read a single binary boolean value from the file and copy the value into the BoolBucket. It is read as a one byte value. If the "PeekOnly" flag is true, the value is read but the file pointer position is not advanced, so the next read operation will read the same data.

 

If the stream is specified as "WriteMode", this method will fire a StreamException.

 

FileStream Class


Read()

public virtual method Read(StreamIO StreamBucket, int ReadSize = 0, bool PeekOnly = false)

Parameters

StreamBucket

Stream reference to receive the data

ReadSize

Size of the binary read operation

PeekOnly

If true, read without advancing pointer

Return Value

None

Description

Virtual method to read a binary block of data from the file and write it into the target stream (StreamBucket). The size of the read operation is specified. If the target stream supports "random access", the data is written at the current pointer position within that target stream. If the "PeekOnly" flag is true, the value is read but the file pointer position is not advanced, so the next read operation will read the same data.

 

If the ReadSize is specified as zero, the read operation goes all the way to the end of this stream.

 

If the stream is specified as "WriteMode", this method will fire a StreamException.

 

FileStream Class


Write()

public virtual method Write(int Value)

Parameters

Value

Integer value to be written

Return Value

None

Description

Virtual method to write a single 8 byte binary integer value to the file.

 

If the stream is specified as "ReadMode", this method will fire a StreamException.

 

FileStream Class


Write()

public virtual method Write(int Value, SmallInt IntSizeEnum)

Parameters

Value

Integer value to be written

IntSizeEnum

Enumeration to indicate 1, 2 or 4 byte integer

Return Value

None

Description

Virtual method to write a single "small" binary integer value to the file. The size of the integer write operation is specified by IntSizeEnum, and represents 1, 2 or 4 bytes. The integer value must fit within one of the two valid ranges for the integer size that was specified. For each integer size, there is a valid "signed" range and a separate value "unsigned" range. Refer to the 'int' class documention for more details.

 

If the stream is specified as "ReadMode", this method will fire a StreamException.

 

FileStream Class


Write()

public virtual method Write(float Value, bool Write32BitFloat = false)

Parameters

Value

Float value to be written

Write32BitFloat

Write 32 bit (4 byte) float if true (default is false)

Return Value

None

Description

Virtual method to write a single binary floating point value to the file. The default size of the float write operation is 8 bytes, but can be changed to 4 bytes by setting the "Write32BitFloat" flag. If the "Write32BitFlag" is set, the floating point value must fit within the valid range for a 4 byte float. Refer to the 'float' class documention for more details.

 

If the stream is specified as "ReadMode", this method will fire a StreamException.

 

FileStream Class


Write()

public virtual method Write(string Value, bool EmbedLength = true, int OverrideLength = 0)

Parameters

Value

String value to be written to stream

EmbedLength

If true, embed string length into stream before the string

OverrideLength

Override length for string to be written

Return Value

None

Description

Virtual method to write a single string to the file. If the "EmbedLength" flag is true, the length of the string is embedded in the file before the text string itself (as a 4 byte integer). By default, the entire string is written to the file, but if "OverrideLength" is greater than zero, then the override length will be used instead.

 

If the stream is specified as "ReadMode", this method will fire a StreamException.

 

FileStream Class


Write()

public virtual method Write(bool Value)

Parameters

Value

Boolean value to be written

Return Value

None

Description

Virtual method to write a single binary boolean value to the file. It is written as a one byte value.

 

If the stream is specified as "ReadMode", this method will fire a StreamException.

 

FileStream Class


Write()

public virtual method Write(StreamIO SourceStream, int WriteSize = 0)

Parameters

SourceStream

Source stream reference

WriteSize

Size of the binary write operation

Return Value

None

Description

Virtual method to read a binary block of data from the source stream and write it into this file. The size of the read and write operation is specified by "WriteSize". If the source stream supports "random access", the data is read from the current pointer position within that source stream and then written into this file (at current file pointer position). If the WriteSize is specified as zero, the read operation from the source stream goes all the way to the end of that stream.

 

If the stream is specified as "ReadMode", this method will fire a StreamException.

 

FileStream Class

 

Copyright © 2010-2017

Aztec Development Group

All Rights Reserved

Download Aztec