Qore Programming Language Reference Manual  0.8.12
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

*binary bulkRead (int limit, timeout timeout_ms=-1)
 Reads bytes (up to a specified limit) from the input stream; returns NOTHING if there are no more bytes in the stream. More...
 
nothing close ()
 Closes the input stream and releases any resources. More...
 
 constructor (string fileName)
 Creates the FileInputStream by opening a file. More...
 
int read (timeout timeout_ms=-1)
 Reads a single byte from the input stream; returns -1 if the end of the stream has been reached. 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.12
Restrictions:
Qore::PO_NO_FILESYSTEM
Example: FileInputStream basic usage
1 FileInputStream fis("file.ext");
2 while ((int i = fis.read()) != -1) {
3  printf("read %d\n", i);
4 }

Member Function Documentation

*binary Qore::FileInputStream::bulkRead ( int  limit,
timeout  timeout_ms = -1 
)
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
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 call will never time out
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.bulkRead(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 specified timeout

Implements Qore::InputStream.

nothing Qore::FileInputStream::close ( )
virtual

Closes the input stream and releases any resources.

Any methods called on a closed input stream will thrown an IO-ERROR exception.

Exceptions
IO-ERRORif an I/O error occurs

Implements Qore::InputStream.

Qore::FileInputStream::constructor ( string  fileName)

Creates the FileInputStream by opening a file.

Parameters
fileNamethe name of the file to open
int Qore::FileInputStream::read ( timeout  timeout_ms = -1)
virtual

Reads a single byte from the input stream; returns -1 if the end of the stream has been reached.

Parameters
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 call will never time out
Returns
the next byte (0 - 255) in the input stream or -1 if the end of the stream has been reached
Example:
1 FileInputStream fis("file.ext");
2 while ((int i = fis.read()) != -1) {
3  printf("read %d\n", i);
4 }
Exceptions
FILE-READ-ERRORif an I/O error occurs
FILE-READ-TIMEOUT-ERRORif no byte could be read in the specified timeout

Implements Qore::InputStream.