All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tesseract::InputBuffer Class Reference

#include <fileio.h>

Public Member Functions

 InputBuffer (FILE *stream)
 
 InputBuffer (FILE *stream, size_t size)
 
 ~InputBuffer ()
 
bool Read (string *out)
 
bool CloseFile ()
 

Detailed Description

Definition at line 58 of file fileio.h.

Constructor & Destructor Documentation

tesseract::InputBuffer::InputBuffer ( FILE *  stream)
explicit

Definition at line 135 of file fileio.cpp.

136  : stream_(stream) {
137  fseek(stream_, 0, SEEK_END);
138  filesize_ = ftell(stream_);
139  fseek(stream_, 0, SEEK_SET);
140 }
tesseract::InputBuffer::InputBuffer ( FILE *  stream,
size_t  size 
)

Definition at line 142 of file fileio.cpp.

143  : stream_(stream) {
144  fseek(stream_, 0, SEEK_END);
145  filesize_ = ftell(stream_);
146  fseek(stream_, 0, SEEK_SET);
147 }
tesseract::InputBuffer::~InputBuffer ( )

Definition at line 149 of file fileio.cpp.

149  {
150  if (stream_ != NULL) {
151  fclose(stream_);
152  }
153 }
#define NULL
Definition: host.h:144

Member Function Documentation

bool tesseract::InputBuffer::CloseFile ( )

Definition at line 169 of file fileio.cpp.

169  {
170  int ret = fclose(stream_);
171  stream_ = NULL;
172  return ret == 0;
173 }
#define NULL
Definition: host.h:144
bool tesseract::InputBuffer::Read ( string *  out)

Definition at line 155 of file fileio.cpp.

155  {
156  char buf[BUFSIZ + 1];
157  int l;
158  while ((l = fread(buf, 1, BUFSIZ, stream_)) > 0) {
159  if (ferror(stream_)) {
160  clearerr(stream_);
161  return false;
162  }
163  buf[l] = 0;
164  out->append(buf);
165  }
166  return true;
167 }

The documentation for this class was generated from the following files: