32 #ifndef _QORE_BUFFEREDSTREAMREADER_H 33 #define _QORE_BUFFEREDSTREAMREADER_H 37 #include "qore/qore_bitopts.h" 38 #include "qore/InputStream.h" 39 #include "qore/intern/StreamReader.h" 42 #define DefaultStreamBufferSize 4096 49 bufCapacity((
size_t)bufsize),
53 xsink->
raiseException(
"STREAM-BUFFER-ERROR",
"the buffer size must be > 0 (value provided: " QLLD
")", bufsize);
58 buf =
new char[bufCapacity + 1];
61 DLLLOCAL
virtual ~BufferedStreamReader() {
66 DLLLOCAL
virtual const char* getName()
const override {
return "BufferedStreamReader"; }
81 char* destPtr =
static_cast<char*
>(dest);
86 memmove(destPtr, buf, read);
87 if (limit < bufCount) {
98 size_t to_read = limit -
read;
99 if (to_read <= (bufCapacity / 2))
101 int64 rc =
in->
read(destPtr + read, to_read, xsink);
106 xsink->
raiseException(
"END-OF-STREAM-ERROR",
"there is not enough data available in the stream; " QSD
" bytes were requested, and " QSD
" were read", limit, read);
117 size_t to_read = limit -
read;
122 int64 rc = fillBuffer(bufCapacity, xsink);
127 xsink->
raiseException(
"END-OF-STREAM-ERROR",
"there is not enough data available in the stream; " QSD
" bytes were requested, and " QSD
" were read", limit, read);
133 size_t len =
QORE_MIN((
size_t)rc, to_read);
134 memcpy(destPtr + read, buf, len);
137 assert(((limit - read) && !bufCount) || !(limit - read));
150 int rc = fillBuffer(bufCapacity, xsink);
162 assert(bufCount + bytes <= bufCapacity);
171 if (bytes > bufCapacity) {
172 xsink->
raiseException(
"STREAM-BUFFER-ERROR",
"a read of " QSD
" bytes was attempted on a BufferedStreamReader with a capacity of " QSD
" bytes", bytes, bufCapacity);
175 if (bufCount < bytes) {
177 int64 rc = fillBuffer(bytes - bufCount, xsink);
182 xsink->
raiseException(
"END-OF-STREAM-ERROR",
"a read of " QSD
" bytes cannot be performed because there is not enough data available in the stream to satisfy the request", bytes);
185 if (bufCount >= bytes)
193 assert(bytes <= bufCount && bytes > 0);
195 memmove(buf, buf+bytes, bufCount);
203 DLLLOCAL
const char* findEolInBuffer(
const QoreStringNode* eol,
qore_size_t& eolLen,
bool endOfStream,
char& pmatch)
const {
206 const char* p = strstr(buf, eol->
getBuffer());
211 const char* p = strpbrk(buf,
"\n\r");
217 if (*(p+1) ==
'\n') {
222 else if (static_cast<qore_size_t>(p - buf + 1) == bufCount) {
247 #endif // _QORE_BUFFEREDSTREAMREADER_H Private data for the Qore::BufferedStreamReader class.
Definition: BufferedStreamReader.h:45
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
ReferenceHolder< InputStream > in
Source input stream.
Definition: StreamReader.h:348
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:73
virtual DLLLOCAL qore_offset_t read(ExceptionSink *xsink, void *dest, qore_size_t limit, bool require_all=true)
Read data until a limit.
Definition: StreamReader.h:337
DLLEXPORT AbstractQoreNode * raiseException(const char *err, const char *fmt,...)
appends a Qore-language exception to the list
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
DLLEXPORT const char * getBuffer() const
returns the string's buffer; this data should not be changed
DLLEXPORT qore_size_t strlen() const
returns number of bytes in the string (not including the null pointer)
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
#define QORE_MIN(a, b)
macro to return the minimum of 2 numbers
Definition: QoreLib.h:535
Private data for the Qore::StreamReader class.
Definition: StreamReader.h:45