mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-29 23:42:39 +02:00
fixed exception messages if writing to output stream fails
This commit is contained in:
parent
0784665ce8
commit
b4fd25c620
@ -151,7 +151,7 @@ int DeflatingStreamBuf::close()
|
|||||||
int rc = deflate(&_zstr, Z_FINISH);
|
int rc = deflate(&_zstr, Z_FINISH);
|
||||||
if (rc != Z_OK && rc != Z_STREAM_END) throw IOException(zError(rc));
|
if (rc != Z_OK && rc != Z_STREAM_END) throw IOException(zError(rc));
|
||||||
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
if (!_pOstr->good()) throw IOException("Failed writing deflated data to output stream");
|
||||||
_zstr.next_out = (unsigned char*) _buffer;
|
_zstr.next_out = (unsigned char*) _buffer;
|
||||||
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
||||||
while (rc != Z_STREAM_END)
|
while (rc != Z_STREAM_END)
|
||||||
@ -159,7 +159,7 @@ int DeflatingStreamBuf::close()
|
|||||||
rc = deflate(&_zstr, Z_FINISH);
|
rc = deflate(&_zstr, Z_FINISH);
|
||||||
if (rc != Z_OK && rc != Z_STREAM_END) throw IOException(zError(rc));
|
if (rc != Z_OK && rc != Z_STREAM_END) throw IOException(zError(rc));
|
||||||
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
if (!_pOstr->good()) throw IOException("Failed writing deflated data to output stream");
|
||||||
_zstr.next_out = (unsigned char*) _buffer;
|
_zstr.next_out = (unsigned char*) _buffer;
|
||||||
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ int DeflatingStreamBuf::sync()
|
|||||||
int rc = deflate(&_zstr, Z_SYNC_FLUSH);
|
int rc = deflate(&_zstr, Z_SYNC_FLUSH);
|
||||||
if (rc != Z_OK) throw IOException(zError(rc));
|
if (rc != Z_OK) throw IOException(zError(rc));
|
||||||
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
if (!_pOstr->good()) throw IOException("Failed writing deflated data to output stream");
|
||||||
while (_zstr.avail_out == 0)
|
while (_zstr.avail_out == 0)
|
||||||
{
|
{
|
||||||
_zstr.next_out = (unsigned char*) _buffer;
|
_zstr.next_out = (unsigned char*) _buffer;
|
||||||
@ -191,7 +191,7 @@ int DeflatingStreamBuf::sync()
|
|||||||
rc = deflate(&_zstr, Z_SYNC_FLUSH);
|
rc = deflate(&_zstr, Z_SYNC_FLUSH);
|
||||||
if (rc != Z_OK) throw IOException(zError(rc));
|
if (rc != Z_OK) throw IOException(zError(rc));
|
||||||
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
if (!_pOstr->good()) throw IOException("Failed writing deflated data to output stream");
|
||||||
};
|
};
|
||||||
_zstr.next_out = (unsigned char*) _buffer;
|
_zstr.next_out = (unsigned char*) _buffer;
|
||||||
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
||||||
@ -281,14 +281,14 @@ int DeflatingStreamBuf::writeToDevice(const char* buffer, std::streamsize length
|
|||||||
if (_zstr.avail_out == 0)
|
if (_zstr.avail_out == 0)
|
||||||
{
|
{
|
||||||
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE);
|
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE);
|
||||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
if (!_pOstr->good()) throw IOException("Failed writing deflated data to output stream");
|
||||||
_zstr.next_out = (unsigned char*) _buffer;
|
_zstr.next_out = (unsigned char*) _buffer;
|
||||||
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
if (_zstr.avail_in == 0)
|
if (_zstr.avail_in == 0)
|
||||||
{
|
{
|
||||||
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
if (!_pOstr->good()) throw IOException("Failed writing deflated data to output stream");
|
||||||
_zstr.next_out = (unsigned char*) _buffer;
|
_zstr.next_out = (unsigned char*) _buffer;
|
||||||
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
||||||
break;
|
break;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
InflatingStreamBuf::InflatingStreamBuf(std::istream& istr, StreamType type):
|
InflatingStreamBuf::InflatingStreamBuf(std::istream& istr, StreamType type):
|
||||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
|
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
|
||||||
_pIstr(&istr),
|
_pIstr(&istr),
|
||||||
_pOstr(0),
|
_pOstr(0),
|
||||||
@ -45,15 +45,15 @@ InflatingStreamBuf::InflatingStreamBuf(std::istream& istr, StreamType type):
|
|||||||
_buffer = new char[INFLATE_BUFFER_SIZE];
|
_buffer = new char[INFLATE_BUFFER_SIZE];
|
||||||
|
|
||||||
int rc = inflateInit2(&_zstr, 15 + (type == STREAM_GZIP ? 16 : 0));
|
int rc = inflateInit2(&_zstr, 15 + (type == STREAM_GZIP ? 16 : 0));
|
||||||
if (rc != Z_OK)
|
if (rc != Z_OK)
|
||||||
{
|
{
|
||||||
delete [] _buffer;
|
delete [] _buffer;
|
||||||
throw IOException(zError(rc));
|
throw IOException(zError(rc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
InflatingStreamBuf::InflatingStreamBuf(std::istream& istr, int windowBits):
|
InflatingStreamBuf::InflatingStreamBuf(std::istream& istr, int windowBits):
|
||||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
|
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
|
||||||
_pIstr(&istr),
|
_pIstr(&istr),
|
||||||
_pOstr(0),
|
_pOstr(0),
|
||||||
@ -71,15 +71,15 @@ InflatingStreamBuf::InflatingStreamBuf(std::istream& istr, int windowBits):
|
|||||||
_buffer = new char[INFLATE_BUFFER_SIZE];
|
_buffer = new char[INFLATE_BUFFER_SIZE];
|
||||||
|
|
||||||
int rc = inflateInit2(&_zstr, windowBits);
|
int rc = inflateInit2(&_zstr, windowBits);
|
||||||
if (rc != Z_OK)
|
if (rc != Z_OK)
|
||||||
{
|
{
|
||||||
delete [] _buffer;
|
delete [] _buffer;
|
||||||
throw IOException(zError(rc));
|
throw IOException(zError(rc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
InflatingStreamBuf::InflatingStreamBuf(std::ostream& ostr, StreamType type):
|
InflatingStreamBuf::InflatingStreamBuf(std::ostream& ostr, StreamType type):
|
||||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
|
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
|
||||||
_pIstr(0),
|
_pIstr(0),
|
||||||
_pOstr(&ostr),
|
_pOstr(&ostr),
|
||||||
@ -97,7 +97,7 @@ InflatingStreamBuf::InflatingStreamBuf(std::ostream& ostr, StreamType type):
|
|||||||
_buffer = new char[INFLATE_BUFFER_SIZE];
|
_buffer = new char[INFLATE_BUFFER_SIZE];
|
||||||
|
|
||||||
int rc = inflateInit2(&_zstr, 15 + (type == STREAM_GZIP ? 16 : 0));
|
int rc = inflateInit2(&_zstr, 15 + (type == STREAM_GZIP ? 16 : 0));
|
||||||
if (rc != Z_OK)
|
if (rc != Z_OK)
|
||||||
{
|
{
|
||||||
delete [] _buffer;
|
delete [] _buffer;
|
||||||
throw IOException(zError(rc));
|
throw IOException(zError(rc));
|
||||||
@ -105,7 +105,7 @@ InflatingStreamBuf::InflatingStreamBuf(std::ostream& ostr, StreamType type):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
InflatingStreamBuf::InflatingStreamBuf(std::ostream& ostr, int windowBits):
|
InflatingStreamBuf::InflatingStreamBuf(std::ostream& ostr, int windowBits):
|
||||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
|
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
|
||||||
_pIstr(0),
|
_pIstr(0),
|
||||||
_pOstr(&ostr),
|
_pOstr(&ostr),
|
||||||
@ -123,7 +123,7 @@ InflatingStreamBuf::InflatingStreamBuf(std::ostream& ostr, int windowBits):
|
|||||||
_buffer = new char[INFLATE_BUFFER_SIZE];
|
_buffer = new char[INFLATE_BUFFER_SIZE];
|
||||||
|
|
||||||
int rc = inflateInit2(&_zstr, windowBits);
|
int rc = inflateInit2(&_zstr, windowBits);
|
||||||
if (rc != Z_OK)
|
if (rc != Z_OK)
|
||||||
{
|
{
|
||||||
delete [] _buffer;
|
delete [] _buffer;
|
||||||
throw IOException(zError(rc));
|
throw IOException(zError(rc));
|
||||||
@ -214,7 +214,7 @@ int InflatingStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
|||||||
{
|
{
|
||||||
_zstr.next_in = (unsigned char*) _buffer;
|
_zstr.next_in = (unsigned char*) _buffer;
|
||||||
_zstr.avail_in = n;
|
_zstr.avail_in = n;
|
||||||
}
|
}
|
||||||
else return static_cast<int>(length) - _zstr.avail_out;
|
else return static_cast<int>(length) - _zstr.avail_out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -224,7 +224,7 @@ int InflatingStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
|||||||
int InflatingStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
int InflatingStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||||
{
|
{
|
||||||
if (length == 0 || !_pOstr) return 0;
|
if (length == 0 || !_pOstr) return 0;
|
||||||
|
|
||||||
_zstr.next_in = (unsigned char*) buffer;
|
_zstr.next_in = (unsigned char*) buffer;
|
||||||
_zstr.avail_in = static_cast<unsigned>(length);
|
_zstr.avail_in = static_cast<unsigned>(length);
|
||||||
_zstr.next_out = (unsigned char*) _buffer;
|
_zstr.next_out = (unsigned char*) _buffer;
|
||||||
@ -235,21 +235,21 @@ int InflatingStreamBuf::writeToDevice(const char* buffer, std::streamsize length
|
|||||||
if (rc == Z_STREAM_END)
|
if (rc == Z_STREAM_END)
|
||||||
{
|
{
|
||||||
_pOstr->write(_buffer, INFLATE_BUFFER_SIZE - _zstr.avail_out);
|
_pOstr->write(_buffer, INFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
if (!_pOstr->good()) throw IOException("Failed writing inflated data to output stream");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (rc != Z_OK) throw IOException(zError(rc));
|
if (rc != Z_OK) throw IOException(zError(rc));
|
||||||
if (_zstr.avail_out == 0)
|
if (_zstr.avail_out == 0)
|
||||||
{
|
{
|
||||||
_pOstr->write(_buffer, INFLATE_BUFFER_SIZE);
|
_pOstr->write(_buffer, INFLATE_BUFFER_SIZE);
|
||||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
if (!_pOstr->good()) throw IOException("Failed writing inflated data to output stream");
|
||||||
_zstr.next_out = (unsigned char*) _buffer;
|
_zstr.next_out = (unsigned char*) _buffer;
|
||||||
_zstr.avail_out = INFLATE_BUFFER_SIZE;
|
_zstr.avail_out = INFLATE_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
if (_zstr.avail_in == 0)
|
if (_zstr.avail_in == 0)
|
||||||
{
|
{
|
||||||
_pOstr->write(_buffer, INFLATE_BUFFER_SIZE - _zstr.avail_out);
|
_pOstr->write(_buffer, INFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
if (!_pOstr->good()) throw IOException("Failed writing inflated data to output stream");
|
||||||
_zstr.next_out = (unsigned char*) _buffer;
|
_zstr.next_out = (unsigned char*) _buffer;
|
||||||
_zstr.avail_out = INFLATE_BUFFER_SIZE;
|
_zstr.avail_out = INFLATE_BUFFER_SIZE;
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user