ot::io
class FileOutputStream
#include "ot/io/FileOutputStream.h"
An OutputStream that writes bytes to a file.
When a FileOutputStream is created, a connection is established with an open file in the file system. The open file is represented internally using a FileDescriptor which ensures that the file is closed when the FileOutputStream is destroyed.
Method Summary
|
virtual void |
close()
Any buffered data is written to the output file before it is closed and any system resources associated with the stream are released. |
RefPtr< FileDescriptor > |
getFD() const
Returns a reference to the FileDescriptor for the open file connected to this FileOutputStream. |
virtual void |
write(const Byte* pBuffer, size_t bufLen)
Writes an array of bytes to this output stream. |
Constructor/Destructor Detail |
FileOutputStream
FileOutputStream(const File& file)
-
Constructs a FileOutputStream by opening a connection to the file with the abstract pathname denoted by file.
If a file with the abstract pathname already exists then it is truncated and its contents discarded.
- Parameters:
file
-
the abstract pathname of the file to open
- Exceptions:
IOException
-
if the specified file could not be opened. This includes the case where file refers to a directory instead of a normal file.
FileOutputStream
FileOutputStream(const String& name)
-
Constructs a FileOutputStream by opening a connection to the named file name.
If the file already exists its contents are discarded.
- Parameters:
name
-
the name of the file to open
- Exceptions:
IOException
-
if the specified file name could not be opened. This includes the case where name refers to a directory instead of a normal file.
FileOutputStream
FileOutputStream(FileDescriptor* pFD)
-
Constructs a FileInputStream and connects it with an open file denoted by the FileDescriptor pFD.
- Parameters:
pFD
-
the FileDescriptor to connect to this FileInputStream
- Exceptions:
NullPointerException
-
if pFD is null.
FileOutputStream
FileOutputStream(const String& name,
bool bAppend)
-
Constructs a FileOutputStream by opening a connection to the named file name.
- Parameters:
name
-
the name of the file to open
bAppend
-
true if the contents of an existing file should be kept; false if the file should be truncated
- Exceptions:
IOException
-
if the specified file name could not be opened. This includes the case where name refers to a directory instead of a normal file.
close
virtual void close()
-
Any buffered data is written to the output file before it is closed and any system resources associated with the stream are released.
Once an OutputStream is closed further calls to write(), flush() or flushBuffers() will result in an IOException being thrown. Further calls to close() are legal but have no effect.
- Exceptions:
IOException
-
if an I/O error occurs.
getFD
RefPtr< FileDescriptor > getFD() const
-
Returns a reference to the FileDescriptor for the open file connected to this FileOutputStream.
write
virtual void write(const Byte* pBuffer,
size_t bufLen)
-
Writes an array of bytes to this output stream.
- Parameters:
pBuffer
-
pointer to the start of an array of bytes to be written
bufLen
-
length of the byte array
- Exceptions:
NullPointerException
-
if pBuffer is null.
IOException
-
if an I/O error occurs.
Found a bug or missing feature? Please email us at support@elcel.com