\doxysection{Qore\+::File\+Output\+Stream Class Reference}
\hypertarget{class_qore_1_1_file_output_stream}{}\label{class_qore_1_1_file_output_stream}\index{Qore::FileOutputStream@{Qore::FileOutputStream}}


This class implements the \doxylink{class_qore_1_1_output_stream}{Output\+Stream} interface for writing bytes to a file.  




{\ttfamily \#include $<$QC\+\_\+\+File\+Output\+Stream.\+dox.\+h$>$}



Inheritance diagram for Qore\+::File\+Output\+Stream\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=211pt]{class_qore_1_1_file_output_stream__inherit__graph}
\end{center}
\end{figure}
\doxysubsubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{nothing}} \mbox{\hyperlink{class_qore_1_1_file_output_stream_a40dc875e057e1820a81b4e6bcb22bb49}{close}} ()
\begin{DoxyCompactList}\small\item\em Closes the output stream and releases any resources. \end{DoxyCompactList}\item 
\mbox{\hyperlink{class_qore_1_1_file_output_stream_aa431640a1a49b6e45f1c9d4ee784d1fa}{constructor}} (\mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} \mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{file\+Name}}, \mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{bool}} \mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{append}}=\mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}}, \mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{softint}} mode=0644, \mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{\+\_\+\+\_\+7\+\_\+}} \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} encoding)
\begin{DoxyCompactList}\small\item\em Creates the \doxylink{class_qore_1_1_file_output_stream}{File\+Output\+Stream} by opening or creating a file. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} \mbox{\hyperlink{class_qore_1_1_file_output_stream_a6682997dfb22ce5ea3ae6878e9c8b531}{get\+Encoding}} ()
\begin{DoxyCompactList}\small\item\em Returns the \doxylink{character_encoding}{character encoding} for the \doxylink{class_qore_1_1_file_output_stream}{File\+Output\+Stream}. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{nothing}} \mbox{\hyperlink{class_qore_1_1_file_output_stream_a92bead81e08e4a855c35d313b85a59cd}{write}} (\mbox{\hyperlink{group__type__conversion__functions_gaf11c7f5c43ced1e9b95bd2270ee87ed9}{binary}} data)
\begin{DoxyCompactList}\small\item\em Writes bytes to the output stream. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Public Member Functions inherited from \mbox{\hyperlink{class_qore_1_1_output_stream}{Qore\+::\+Output\+Stream}}}
\begin{DoxyCompactItemize}
\item 
\mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{abstract}} \mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{nothing}} \mbox{\hyperlink{class_qore_1_1_output_stream_a2125e17612767b9636554b282638e883}{close}} ()
\begin{DoxyCompactList}\small\item\em Flushes any buffered (unwritten) bytes, closes the output stream and releases all resources. \end{DoxyCompactList}\item 
\mbox{\hyperlink{class_qore_1_1_output_stream_a451b37ada0ac9331fd2c62c68dcbe286}{constructor}} ()
\begin{DoxyCompactList}\small\item\em Constructor. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{abstract}} \mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{nothing}} \mbox{\hyperlink{class_qore_1_1_output_stream_a9054b0475c4829d10f956d8f6df6f2ac}{write}} (\mbox{\hyperlink{group__type__conversion__functions_gaf11c7f5c43ced1e9b95bd2270ee87ed9}{binary}} data)
\begin{DoxyCompactList}\small\item\em Writes bytes to the output stream. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Public Member Functions inherited from \mbox{\hyperlink{class_qore_1_1_stream_base}{Qore\+::\+Stream\+Base}}}
\begin{DoxyCompactItemize}
\item 
\mbox{\hyperlink{class_qore_1_1_stream_base_ae1c3dbffc3da7bdc8e16e8ad41302552}{constructor}} ()
\begin{DoxyCompactList}\small\item\em Throws an exception if called directly; this class can only be instantiated by builtin subclasses. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int}} {\bfseries get\+Thread\+Id} ()
\begin{DoxyCompactList}\small\item\em Get the currently assigned thread id or -\/1 if not assigned to any thread. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{nothing}} \mbox{\hyperlink{class_qore_1_1_stream_base_ab6b33cb1944c46aca8e9984ddfd65452}{reassign\+Thread}} ()
\begin{DoxyCompactList}\small\item\em Reassigns current thread as thread used for stream manipulation. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{nothing}} \mbox{\hyperlink{class_qore_1_1_stream_base_a017fc847a42d5c670cb9640a94522666}{unassign\+Thread}} ()
\begin{DoxyCompactList}\small\item\em Unassigns current thread as thread used for stream manipulation. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
This class implements the \doxylink{class_qore_1_1_output_stream}{Output\+Stream} interface for writing bytes to a file. 

\begin{DoxyParagraph}{Restrictions\+:}
\doxylink{group__parse__options_ga5e466ed886222f0b57b0a399b455be71}{Qore\+::\+PO\+\_\+\+NO\+\_\+\+FILESYSTEM}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+: File\+Output\+Stream basic usage}

\begin{DoxyCode}{0}
\DoxyCodeLine{FileOutputStream\ fos(\textcolor{stringliteral}{"{}file.ext"{}});}
\DoxyCodeLine{fos.write(<01>);}
\DoxyCodeLine{fos.write(<0203>);}
\DoxyCodeLine{fos.close();}
\DoxyCodeLine{\textcolor{comment}{\#\ file.ext\ now\ contains\ three\ bytes:\ 01\ 02\ 03}}

\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 STREAM-\/\+THREAD-\/\+ERROR} to be thrown, unless the stream is handed off to another thread using the \doxylink{class_qore_1_1_stream_base_a017fc847a42d5c670cb9640a94522666}{Stream\+Base\+::unassign\+Thread()} method in the thread that currently owns the stream, and the \doxylink{class_qore_1_1_stream_base_ab6b33cb1944c46aca8e9984ddfd65452}{Stream\+Base\+::reassign\+Thread()} method in the new thread.
\end{DoxyNote}
\begin{DoxySeeAlso}{See also}
\doxylink{class_qore_1_1_stream_writer}{Stream\+Writer} \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{for} \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{a} \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{class} \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{that} \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{can} \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{be} \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{used} \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{to} \doxylink{class_qore_1_1_file_output_stream_a92bead81e08e4a855c35d313b85a59cd}{write} \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{various} \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{kinds} \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{of} data \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{to} \doxylink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{an} \doxylink{class_qore_1_1_output_stream}{Output\+Stream}
\end{DoxySeeAlso}
\begin{DoxySince}{Since}
Qore 0.\+8.\+13 
\end{DoxySince}


\doxysubsection{Member Function Documentation}
\Hypertarget{class_qore_1_1_file_output_stream_a40dc875e057e1820a81b4e6bcb22bb49}\label{class_qore_1_1_file_output_stream_a40dc875e057e1820a81b4e6bcb22bb49} 
\index{Qore::FileOutputStream@{Qore::FileOutputStream}!close@{close}}
\index{close@{close}!Qore::FileOutputStream@{Qore::FileOutputStream}}
\doxysubsubsection{\texorpdfstring{close()}{close()}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{nothing}} Qore\+::\+File\+Output\+Stream\+::close (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Closes the output stream and releases any resources. 

Any methods called on a closed output stream will throw an IO-\/\+ERROR exception.


\begin{DoxyExceptions}{Exceptions}
{\em IO-\/\+ERROR} & if an I/O error occurs \\
\hline
{\em OUTPUT-\/\+STREAM-\/\+CLOSED-\/\+ERROR} & the output stream has already been closed \\
\hline
{\em STREAM-\/\+THREAD-\/\+ERROR} & this exception is thrown if this method is called from any thread other than the thread that created the object \\
\hline
\end{DoxyExceptions}
\Hypertarget{class_qore_1_1_file_output_stream_aa431640a1a49b6e45f1c9d4ee784d1fa}\label{class_qore_1_1_file_output_stream_aa431640a1a49b6e45f1c9d4ee784d1fa} 
\index{Qore::FileOutputStream@{Qore::FileOutputStream}!constructor@{constructor}}
\index{constructor@{constructor}!Qore::FileOutputStream@{Qore::FileOutputStream}}
\doxysubsubsection{\texorpdfstring{constructor()}{constructor()}}
{\footnotesize\ttfamily Qore\+::\+File\+Output\+Stream\+::constructor (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}}}]{file\+Name,  }\item[{\mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{bool}}}]{append = {\ttfamily \mbox{\hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False}}},  }\item[{\mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{softint}}}]{mode = {\ttfamily 0644},  }\item[{\mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{\+\_\+\+\_\+7\+\_\+}} \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}}}]{encoding }\end{DoxyParamCaption})}



Creates the \doxylink{class_qore_1_1_file_output_stream}{File\+Output\+Stream} by opening or creating a file. 


\begin{DoxyParams}{Parameters}
{\em file\+Name} & the name of the file to open \\
\hline
{\em append} & if true, then bytes will be written to the end of the file \\
\hline
{\em mode} & permission bits for when the file is to be created (default\+: 0644) \\
\hline
{\em encoding} & the \doxylink{character_encoding}{character encoding} of the file; if not present, defaults to the \doxysectlink{character_encoding_default_encoding}{default encoding}{1}\\
\hline
\end{DoxyParams}
\begin{DoxyNote}{Note}
raw binary data is written to the output stream, so it\textquotesingle{}s up to the caller to ensure that only valid character data for the given encoding is written to the \doxylink{class_qore_1_1_file_output_stream}{File\+Output\+Stream} object 
\end{DoxyNote}
\Hypertarget{class_qore_1_1_file_output_stream_a6682997dfb22ce5ea3ae6878e9c8b531}\label{class_qore_1_1_file_output_stream_a6682997dfb22ce5ea3ae6878e9c8b531} 
\index{Qore::FileOutputStream@{Qore::FileOutputStream}!getEncoding@{getEncoding}}
\index{getEncoding@{getEncoding}!Qore::FileOutputStream@{Qore::FileOutputStream}}
\doxysubsubsection{\texorpdfstring{getEncoding()}{getEncoding()}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} Qore\+::\+File\+Output\+Stream\+::get\+Encoding (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Returns the \doxylink{character_encoding}{character encoding} for the \doxylink{class_qore_1_1_file_output_stream}{File\+Output\+Stream}. 

\begin{DoxyParagraph}{Code Flags\+:}
\doxysectlink{code_flags_CONSTANT}{CONSTANT}{1}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{FileOutputStream\ fos(filname);}
\DoxyCodeLine{string\ encoding\ =\ fos.getEncoding();}

\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxyReturn}{Returns}
the \doxylink{character_encoding}{character encoding} for the \doxylink{class_qore_1_1_file_output_stream}{File\+Output\+Stream}
\end{DoxyReturn}
\begin{DoxyNote}{Note}
raw binary data is written to the output stream, so it\textquotesingle{}s up to the caller to ensure that only valid character data for the given encoding is written to the \doxylink{class_qore_1_1_file_output_stream}{File\+Output\+Stream} object 
\end{DoxyNote}
\Hypertarget{class_qore_1_1_file_output_stream_a92bead81e08e4a855c35d313b85a59cd}\label{class_qore_1_1_file_output_stream_a92bead81e08e4a855c35d313b85a59cd} 
\index{Qore::FileOutputStream@{Qore::FileOutputStream}!write@{write}}
\index{write@{write}!Qore::FileOutputStream@{Qore::FileOutputStream}}
\doxysubsubsection{\texorpdfstring{write()}{write()}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__type__conversion__functions_ga9a401e5112c58f63c05e7ee1e15968ef}{nothing}} Qore\+::\+File\+Output\+Stream\+::write (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__type__conversion__functions_gaf11c7f5c43ced1e9b95bd2270ee87ed9}{binary}}}]{data }\end{DoxyParamCaption})}



Writes bytes to the output stream. 


\begin{DoxyParams}{Parameters}
{\em data} & the data to write\\
\hline
\end{DoxyParams}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{FileOutputStream\ fos(\textcolor{stringliteral}{"{}file.ext"{}});}
\DoxyCodeLine{fos.write(<01>);}
\DoxyCodeLine{fos.write(<0203>);}
\DoxyCodeLine{fos.close();}
\DoxyCodeLine{\textcolor{comment}{\#\ file.ext\ now\ contains\ three\ bytes:\ 01\ 02\ 03}}

\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em FILE-\/\+WRITE-\/\+ERROR} & if an I/O error occurs \\
\hline
{\em OUTPUT-\/\+STREAM-\/\+CLOSED-\/\+ERROR} & the output stream has already been closed \\
\hline
{\em STREAM-\/\+THREAD-\/\+ERROR} & this exception is thrown if this method is called from any thread other than the thread that created the object\\
\hline
\end{DoxyExceptions}
\begin{DoxyNote}{Note}
raw binary data is written to the output stream, so it\textquotesingle{}s up to the caller to ensure that only valid character data for the given encoding is written to the \doxylink{class_qore_1_1_file_output_stream}{File\+Output\+Stream} object 
\end{DoxyNote}
