\hypertarget{class_qore_1_1_file_input_stream}{}\section{Qore\+:\+:File\+Input\+Stream Class Reference}
\label{class_qore_1_1_file_input_stream}\index{Qore\+::\+File\+Input\+Stream@{Qore\+::\+File\+Input\+Stream}}


This class implements the \hyperlink{class_qore_1_1_input_stream}{Input\+Stream} interface for reading bytes from a file.  




Inheritance diagram for Qore\+:\+:File\+Input\+Stream\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=202pt]{class_qore_1_1_file_input_stream__inherit__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{class_qore_1_1_file_input_stream_aaaa18b49402cb9fb889475b1bb018918}{constructor} (\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string} file\+Name, timeout timeout\+\_\+ms=-\/1, \+\_\+\+\_\+7\+\_\+ bool nonblocking\+\_\+open)
\begin{DoxyCompactList}\small\item\em Creates the \hyperlink{class_qore_1_1_file_input_stream}{File\+Input\+Stream} by opening a file. \end{DoxyCompactList}\item 
\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} \hyperlink{class_qore_1_1_file_input_stream_a898981029547b903c7a2ac661b621443}{peek} ()
\begin{DoxyCompactList}\small\item\em Peeks the next byte available from the input stream; returns -\/1 if no more data available. \end{DoxyCompactList}\item 
\+\_\+\+\_\+7\+\_\+ \hyperlink{group__type__conversion__functions_gaf11c7f5c43ced1e9b95bd2270ee87ed9}{binary} \hyperlink{class_qore_1_1_file_input_stream_a51429f08b73a1cac82cca23de4dc6c9c}{read} (\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} limit)
\begin{DoxyCompactList}\small\item\em Reads bytes (up to a specified limit) from the input stream; returns \hyperlink{basic_data_types_NOTHING}{N\+O\+T\+H\+I\+NG} if there are no more bytes in the stream. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
This class implements the \hyperlink{class_qore_1_1_input_stream}{Input\+Stream} interface for reading bytes from a file. 

\begin{DoxyParagraph}{Restrictions\+:}
\hyperlink{group__parse__options_ga5e466ed886222f0b57b0a399b455be71}{Qore\+::\+P\+O\+\_\+\+N\+O\+\_\+\+F\+I\+L\+E\+S\+Y\+S\+T\+EM}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+: File\+Input\+Stream basic usage}

\begin{DoxyCode}
FileInputStream fis(\textcolor{stringliteral}{"file.ext"});
binary *b;
\textcolor{keywordflow}{while} (b = fis.read(100)) \{
    \hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}(\textcolor{stringliteral}{"read %s\(\backslash\)n"}, \hyperlink{group__misc__functions_gae7be18717b0ed9010c48166a437c35b4}{make\_hex\_string}(b));
\}
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxyNote}{Note}
stream classes are not designed to be accessed from multiple threads; they have been implemented without locking for fast and efficient use when used from a single thread. For methods that would be unsafe to use in another thread, any use of such methods in threads other than the thread where the constructor was called will cause a {\ttfamily S\+T\+R\+E\+A\+M-\/\+T\+H\+R\+E\+A\+D-\/\+E\+R\+R\+OR} to be thrown, unless the stream is handed off to another thread using the \hyperlink{class_qore_1_1_stream_base_a017fc847a42d5c670cb9640a94522666}{Stream\+Base\+:\+:unassign\+Thread()} method in the thread that currently owns the stream, and the \hyperlink{class_qore_1_1_stream_base_ab6b33cb1944c46aca8e9984ddfd65452}{Stream\+Base\+:\+:reassign\+Thread()} method in the new thread.
\end{DoxyNote}
\begin{DoxySeeAlso}{See also}
\hyperlink{class_qore_1_1_stream_reader}{Stream\+Reader} for a class that can be used to \hyperlink{class_qore_1_1_file_input_stream_a51429f08b73a1cac82cca23de4dc6c9c}{read} various kinds of data from an \hyperlink{class_qore_1_1_input_stream}{Input\+Stream}
\end{DoxySeeAlso}
\begin{DoxySince}{Since}
Qore 0.\+8.\+13 
\end{DoxySince}


\subsection{Member Function Documentation}
\mbox{\Hypertarget{class_qore_1_1_file_input_stream_aaaa18b49402cb9fb889475b1bb018918}\label{class_qore_1_1_file_input_stream_aaaa18b49402cb9fb889475b1bb018918}} 
\index{Qore\+::\+File\+Input\+Stream@{Qore\+::\+File\+Input\+Stream}!constructor@{constructor}}
\index{constructor@{constructor}!Qore\+::\+File\+Input\+Stream@{Qore\+::\+File\+Input\+Stream}}
\subsubsection{\texorpdfstring{constructor()}{constructor()}}
{\footnotesize\ttfamily Qore\+::\+File\+Input\+Stream\+::constructor (\begin{DoxyParamCaption}\item[{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}}]{file\+Name,  }\item[{timeout}]{timeout\+\_\+ms = {\ttfamily -\/1},  }\item[{\+\_\+\+\_\+7\+\_\+ bool}]{nonblocking\+\_\+open }\end{DoxyParamCaption})}



Creates the \hyperlink{class_qore_1_1_file_input_stream}{File\+Input\+Stream} by opening a file. 


\begin{DoxyParams}{Parameters}
{\em file\+Name} & the name of the file to open \\
\hline
{\em timeout\+\_\+ms} & a timeout period with a resolution of milliseconds (a \hyperlink{basic_data_types_relative_dates}{relative date/time value}; integer arguments will be assumed to be milliseconds); if not given or negative the operations will never time out \\
\hline
{\em nonblocking\+\_\+open} & if \hyperlink{basic_data_types_True}{True}, then the {\ttfamily O\+\_\+\+N\+O\+N\+B\+L\+O\+CK} flag will be set in the call to {\ttfamily open() (2)}\\
\hline
\end{DoxyParams}

\begin{DoxyExceptions}{Exceptions}
{\em F\+I\+L\+E-\/\+O\+P\+E\+N2-\/\+E\+R\+R\+OR} & if the file cannot be opened (does not exist, permission error, etc)\\
\hline
\end{DoxyExceptions}
\begin{DoxySince}{Since}
Qore 0.\+9.\+3 added the {\itshape nonblocking\+\_\+open} flag 
\end{DoxySince}
\mbox{\Hypertarget{class_qore_1_1_file_input_stream_a898981029547b903c7a2ac661b621443}\label{class_qore_1_1_file_input_stream_a898981029547b903c7a2ac661b621443}} 
\index{Qore\+::\+File\+Input\+Stream@{Qore\+::\+File\+Input\+Stream}!peek@{peek}}
\index{peek@{peek}!Qore\+::\+File\+Input\+Stream@{Qore\+::\+File\+Input\+Stream}}
\subsubsection{\texorpdfstring{peek()}{peek()}}
{\footnotesize\ttfamily \hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} Qore\+::\+File\+Input\+Stream\+::peek (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}



Peeks the next byte available from the input stream; returns -\/1 if no more data available. 

\begin{DoxyReturn}{Returns}
the next byte available from the input stream or -\/1 if no more data is available
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
FileInputStream fis(\textcolor{stringliteral}{"file.ext"});
int nextByte = fis.peek();
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em F\+I\+L\+E-\/\+R\+E\+A\+D-\/\+E\+R\+R\+OR} & if an I/O error occurs \\
\hline
{\em F\+I\+L\+E-\/\+R\+E\+A\+D-\/\+T\+I\+M\+E\+O\+U\+T-\/\+E\+R\+R\+OR} & if no byte could be read in the timeout specified in the constructor\\
\hline
{\em S\+T\+R\+E\+A\+M-\/\+T\+H\+R\+E\+A\+D-\/\+E\+R\+R\+OR} & this exception is thrown if this method is called from any thread other than the thread that created the object \\
\hline
\end{DoxyExceptions}


Implements \hyperlink{class_qore_1_1_input_stream_a165db4108c3a1f4bbb6b619972fd131c}{Qore\+::\+Input\+Stream}.

\mbox{\Hypertarget{class_qore_1_1_file_input_stream_a51429f08b73a1cac82cca23de4dc6c9c}\label{class_qore_1_1_file_input_stream_a51429f08b73a1cac82cca23de4dc6c9c}} 
\index{Qore\+::\+File\+Input\+Stream@{Qore\+::\+File\+Input\+Stream}!read@{read}}
\index{read@{read}!Qore\+::\+File\+Input\+Stream@{Qore\+::\+File\+Input\+Stream}}
\subsubsection{\texorpdfstring{read()}{read()}}
{\footnotesize\ttfamily \+\_\+\+\_\+7\+\_\+ \hyperlink{group__type__conversion__functions_gaf11c7f5c43ced1e9b95bd2270ee87ed9}{binary} Qore\+::\+File\+Input\+Stream\+::read (\begin{DoxyParamCaption}\item[{\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int}}]{limit }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}



Reads bytes (up to a specified limit) from the input stream; returns \hyperlink{basic_data_types_NOTHING}{N\+O\+T\+H\+I\+NG} if there are no more bytes in the stream. 


\begin{DoxyParams}{Parameters}
{\em limit} & the maximum number of bytes to read \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the read bytes (the length is between 1 and `limit` inclusive) or \hyperlink{basic_data_types_NOTHING}{N\+O\+T\+H\+I\+NG} if no more bytes are available
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
FileInputStream fis(\textcolor{stringliteral}{"file.ext"});
*binary b;
\textcolor{keywordflow}{while} (b = fis.read(2)) \{
    \hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}(\textcolor{stringliteral}{"read %s\(\backslash\)n"}, \hyperlink{group__misc__functions_gae7be18717b0ed9010c48166a437c35b4}{make\_hex\_string}(b));
\}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em F\+I\+L\+E-\/\+R\+E\+A\+D-\/\+E\+R\+R\+OR} & if an I/O error occurs \\
\hline
{\em F\+I\+L\+E-\/\+R\+E\+A\+D-\/\+T\+I\+M\+E\+O\+U\+T-\/\+E\+R\+R\+OR} & if no byte could be read in the timeout specified in the constructor\\
\hline
{\em I\+N\+P\+U\+T-\/\+S\+T\+R\+E\+A\+M-\/\+E\+R\+R\+OR} & {\itshape limit} is not positive \\
\hline
{\em S\+T\+R\+E\+A\+M-\/\+T\+H\+R\+E\+A\+D-\/\+E\+R\+R\+OR} & this exception is thrown if this method is called from any thread other than the thread that created the object\\
\hline
\end{DoxyExceptions}
\begin{DoxySeeAlso}{See also}
File\+Input\+Stream\+::read\+String() 
\end{DoxySeeAlso}


Implements \hyperlink{class_qore_1_1_input_stream_a74ba0bc85bb86988a0f8b3255d1dbf01}{Qore\+::\+Input\+Stream}.

