This class implements the InputStream interface for reading bytes from a file.
More...
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) {
*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
-
limit | the maximum number of bytes to read |
timeout_ms | a 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");
3 while (b = fis.bulkRead(2)) {
- Exceptions
-
FILE-READ-ERROR | if an I/O error occurs |
FILE-READ-TIMEOUT-ERROR | if 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-ERROR | if an I/O error occurs |
Implements Qore::InputStream.
Qore::FileInputStream::constructor |
( |
string |
fileName | ) |
|
Creates the FileInputStream by opening a file.
- Parameters
-
fileName | the 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_ms | a 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) {
- Exceptions
-
FILE-READ-ERROR | if an I/O error occurs |
FILE-READ-TIMEOUT-ERROR | if no byte could be read in the specified timeout |
Implements Qore::InputStream.