00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <Basics.H>
00022 #include <FS.H>
00023 #include <VestaLog.H>
00024 #include <Recovery.H>
00025 #include "TextIO.H"
00026
00027 using std::ostream;
00028 using std::istream;
00029 using std::streamoff;
00030 using std::ios;
00031
00032 void TextIO::Log(VestaLog &log, const Text &t)
00033 throw (VestaLog::Error)
00034 {
00035 unsigned long len = t.Length();
00036 Basics::uint16 len_short = (Basics::uint16) len;
00037
00038 assert(((unsigned long) len_short) == len);
00039 log.write((char *)(&len_short), sizeof(len_short));
00040 log.write(t.chars(), len);
00041 }
00042
00043 void TextIO::Recover(RecoveryReader &rd, Text &t)
00044 throw (VestaLog::Error, VestaLog::Eof)
00045 {
00046 Basics::uint16 len;
00047 rd.readAll((char *)(&len), sizeof(len));
00048 char *buff = NEW_PTRFREE_ARRAY(char, len+1);
00049 rd.readAll(buff, len);
00050 buff[len] = '\0';
00051 t.Init((const char *) buff);
00052 }
00053
00054 void TextIO::Write(ostream &ofs, const Text &t)
00055 throw (FS::Failure)
00056 {
00057 unsigned long len = t.Length();
00058 Basics::uint16 len_short = (Basics::uint16) len;
00059
00060 assert(((unsigned long) len_short) == len);
00061 FS::Write(ofs, (char *)(&len_short), sizeof(len_short));
00062 FS::Write(ofs, t.chars(), len);
00063 }
00064
00065 void TextIO::Read(istream &ifs, Text &t)
00066 throw (FS::Failure, FS::EndOfFile)
00067 {
00068 Basics::uint16 len;
00069 FS::Read(ifs, (char *)(&len), sizeof(len));
00070 char *buff = NEW_PTRFREE_ARRAY(char, len+1);
00071 FS::Read(ifs, buff, len);
00072 buff[len] = '\0';
00073 t.Init((const char *) buff);
00074 }
00075
00076 int TextIO::Skip(istream &ifs) throw (FS::Failure, FS::EndOfFile)
00077 {
00078 Basics::uint16 len;
00079 FS::Read(ifs, (char *)(&len), sizeof(len));
00080 FS::Seek(ifs, (streamoff)len, ios::cur);
00081 return sizeof(len) + len;
00082 }