dbms: IO: fixed error [#CONV-2546].

This commit is contained in:
Alexey Milovidov 2011-06-26 21:30:59 +00:00
parent 36e74d86b3
commit 123e3f8e76
5 changed files with 29 additions and 25 deletions

View File

@ -26,13 +26,6 @@ private:
std::vector<char> compressed_buffer;
char scratch[QLZ_SCRATCH_DECOMPRESS];
public:
CompressedReadBuffer(ReadBuffer & in_)
: in(in_),
compressed_buffer(QUICKLZ_HEADER_SIZE)
{
}
bool nextImpl()
{
if (in.eof())
@ -63,6 +56,13 @@ public:
return true;
}
public:
CompressedReadBuffer(ReadBuffer & in_)
: in(in_),
compressed_buffer(QUICKLZ_HEADER_SIZE)
{
}
};
}

View File

@ -23,9 +23,6 @@ private:
size_t compressed_bytes;
public:
CompressedWriteBuffer(WriteBuffer & out_) : out(out_), compressed_bytes(0) {}
void nextImpl()
{
size_t uncompressed_size = pos - working_buffer.begin();
@ -44,6 +41,9 @@ public:
compressed_bytes += compressed_size;
}
public:
CompressedWriteBuffer(WriteBuffer & out_) : out(out_), compressed_bytes(0) {}
/// Объём сжатых данных
size_t getCompressedBytes()
{

View File

@ -57,6 +57,9 @@ public:
{
bytes_read += pos - working_buffer.begin();
bool res = nextImpl();
if (!res)
working_buffer = Buffer(working_buffer.begin(), working_buffer.begin());
pos = working_buffer.begin();
return res;
}

View File

@ -17,25 +17,26 @@ class ReadBufferFromIStream : public ReadBuffer
private:
std::istream & istr;
public:
ReadBufferFromIStream(std::istream & istr_) : istr(istr_) {}
bool nextImpl()
{
istr.read(working_buffer.begin(), DEFAULT_READ_BUFFER_SIZE);
size_t gcount = istr.gcount();
working_buffer = Buffer(working_buffer.begin(), working_buffer.begin() + istr.gcount());
if (working_buffer.end() == working_buffer.begin())
if (!gcount)
{
if (istr.eof())
return false;
if (!istr.good())
else
throw Exception("Cannot read from istream", ErrorCodes::CANNOT_READ_FROM_ISTREAM);
}
else
working_buffer = Buffer(working_buffer.begin(), working_buffer.begin() + gcount);
return true;
}
public:
ReadBufferFromIStream(std::istream & istr_) : istr(istr_) {}
};
}

View File

@ -17,9 +17,6 @@ class WriteBufferFromOStream : public WriteBuffer
private:
std::ostream & ostr;
public:
WriteBufferFromOStream(std::ostream & ostr_) : ostr(ostr_) {}
void nextImpl()
{
ostr.write(working_buffer.begin(), pos - working_buffer.begin());
@ -29,6 +26,9 @@ public:
throw Exception("Cannot write to ostream", ErrorCodes::CANNOT_WRITE_TO_OSTREAM);
}
public:
WriteBufferFromOStream(std::ostream & ostr_) : ostr(ostr_) {}
~WriteBufferFromOStream()
{
next();