diff options
Diffstat (limited to 'Source/Library/Common/FileStream.class.cpp')
-rw-r--r-- | Source/Library/Common/FileStream.class.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/Source/Library/Common/FileStream.class.cpp b/Source/Library/Common/FileStream.class.cpp new file mode 100644 index 0000000..6154b2f --- /dev/null +++ b/Source/Library/Common/FileStream.class.cpp @@ -0,0 +1,67 @@ +#include "FileStream.class.h" + +//************************************ +// INPUT FILE STREAM +// ******************** + +FileIStream::FileIStream(const String &filename, u8int encoding, FSNode start) { + m_file = new File(filename, FM_READ, start); + m_encoding = encoding; +} + +FileIStream::~FileIStream() { + if (m_file != 0) { + m_file->close(); + delete m_file; + } +} + +void FileIStream::appendFile(const String &filename) { + if (m_filenames == 0) { + m_filenames = new SimpleList<String>(filename); + } else { + m_filenames->addAtEnd(filename); + } +} + +String FileIStream::read() { + if (m_file == 0) return ""; + while (m_file->eof() or !m_file->valid()) { + m_file->close(); + delete m_file; + m_file = 0; + if (m_filenames == 0) { + return ""; + } else { +#ifdef THIS_IS_MELON_KERNEL + m_file = new File(m_filenames->v(), FM_READ); +#else + m_file = new File(m_filenames->v(), FM_READ, FS::cwdNode()); +#endif + m_filenames = m_filenames->delThis(); + } + } + ByteArray temp; + temp.resize(512); + u32int r = m_file->read(temp); + temp.resize(r); + return temp.toString(m_encoding); +} + +//************************************ +// OUTPUT FILE STREAM +// ******************** + +FileOStream::FileOStream(const String& filename, u8int mode, u8int encoding, FSNode start) { + m_file = new File(filename, mode, start); + m_encoding = encoding; +} + +FileOStream::~FileOStream() { + delete m_file; +} + +void FileOStream::write(const String &s) { + ByteArray a(s, m_encoding); + m_file->write(a); +} |