Qore Programming Language Reference Manual  0.8.12.3
Qore::FileInputStream Class Reference

This class implements the InputStream interface for reading bytes from a file. More...

Inheritance diagram for Qore::FileInputStream:

Public Member Functions

 constructor (string fileName, timeout timeout_ms=-1)
 Creates the FileInputStream by opening a file. More...
 
*binary read (int limit)
 Reads bytes (up to a specified limit) from the input stream; returns NOTHING if there are no more bytes in the stream. More...
 
- Public Member Functions inherited from Qore::InputStream
 constructor ()
 Constructor. More...
 

Detailed Description

This class implements the InputStream interface for reading bytes from a file.

Since
Qore 0.8.13
Restrictions:
Qore::PO_NO_FILESYSTEM
Example: FileInputStream basic usage
1 FileInputStream fis("file.ext");
2 binary *b;
3 while (b = fis.read(100)) {
4  printf("read %s\n", make_hex_string(b));
5 }

Member Function Documentation

Qore::FileInputStream::constructor ( string  fileName,
timeout  timeout_ms = -1 
)

Creates the FileInputStream by opening a file.

Parameters
fileNamethe name of the file to open
timeout_msa timeout period with a resolution of milliseconds (a relative date/time value; integer arguments will be assumed to be milliseconds); if not given or negative the operations will never time out
*binary Qore::FileInputStream::read ( int  limit)
virtual

Reads bytes (up to a specified limit) from the input stream; returns NOTHING if there are no more bytes in the stream.

Parameters
limitthe maximum number of bytes to read
Returns
the read bytes (the length is between 1 and `limit` inclusive) or NOTHING if no more bytes are available
Example:
1 FileInputStream fis("file.ext");
2 *binary b;
3 while (b = fis.read(2)) {
4  printf("read %s\n", make_hex_string(b));
5 }
Exceptions
FILE-READ-ERRORif an I/O error occurs
FILE-READ-TIMEOUT-ERRORif no byte could be read in the timeout specified in the constructor

Implements Qore::InputStream.