00001
00011 #ifndef BUFFERED_READER_H
00012 #define BUFFERED_READER_H
00013
00014 #include <basic.h>
00015 #include <btron/file.h>
00016 #include "Exception.h"
00017
00019
00022 class BufferedReader {
00023
00024 W filedes;
00025
00026 static const int bufsize = 1024;
00027
00028 B buff[bufsize];
00029
00030 int bcur;
00031 int blen;
00032
00033 W offset;
00034
00035 mutable bool eof_state;
00036
00038
00042 void renewEOFState() const {
00043 W rsize, err;
00044 err = rea_rec(filedes, offset, NULL, 0, &rsize, NULL);
00045 if (err < 0){
00046 throw FileReadException(filedes, err);
00047 }
00048 eof_state = (rsize <= 0);
00049 }
00050
00051 public:
00052
00054
00059 BufferedReader(W fd)
00060 : filedes(fd), bcur(0), blen(0), offset(0)
00061 {
00062 renewEOFState();
00063 }
00064
00066
00071 bool isEOF() const {
00072 return eof_state && (blen == bcur);
00073 }
00074
00076
00083 int read(B* target, int size);
00084
00086
00092 int skip(int size);
00093
00094 };
00095
00096 #endif // BUFFERED_READER_H