Qore::FileInputStream Class Reference

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

Inheritance diagram for Qore::FileInputStream:
[legend]

## 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
  FileInputStream fis("file.ext");
  while ((int i = fis.read()) != -1) {
  printf("read %d\n", i);
  }

## 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

  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:
  FileInputStream fis("file.ext");
  *binary b;
  while (b = fis.bulkRead(2)) {
  printf("read %s\n", make_hex_string(b));
  }

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:
  FileInputStream fis("file.ext");
  while ((int i = fis.read()) != -1) {
  printf("read %d\n", i);
  }

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.