buffer fix

This commit is contained in:
JuiceyDev 2026-03-06 11:27:47 +01:00
parent 43a28fc490
commit aadb7172a9
2 changed files with 35 additions and 2 deletions

View file

@ -21,9 +21,17 @@ BufferedOutputStream::~BufferedOutputStream()
//Flushes this buffered output stream. This forces any buffered output bytes to be written out to the underlying output stream. //Flushes this buffered output stream. This forces any buffered output bytes to be written out to the underlying output stream.
void BufferedOutputStream::flush() void BufferedOutputStream::flush()
{ {
stream->write( buf, 0, count ); if (stream == NULL)
{
app.DebugPrintf("BufferedOutputStream::flush() called but underlying stream is NULL\n");
return;
}
count = 0; if (count > 0)
{
stream->write( buf, 0, count );
count = 0;
}
} }
//Closes this output stream and releases any system resources associated with the stream. //Closes this output stream and releases any system resources associated with the stream.
@ -31,6 +39,11 @@ void BufferedOutputStream::flush()
void BufferedOutputStream::close() void BufferedOutputStream::close()
{ {
flush(); flush();
if (stream == NULL)
{
app.DebugPrintf("BufferedOutputStream::close() called but underlying stream is NULL\n");
return;
}
stream->close(); stream->close();
} }

View file

@ -24,6 +24,11 @@ void DataOutputStream::deleteChildStream()
//b - the byte to be written. //b - the byte to be written.
void DataOutputStream::write(unsigned int b) void DataOutputStream::write(unsigned int b)
{ {
if (stream == NULL)
{
app.DebugPrintf("DataOutputStream::write(unsigned int) called but underlying stream is NULL\n");
return;
}
stream->write( b ); stream->write( b );
// TODO 4J Stu - Exception handling? // TODO 4J Stu - Exception handling?
written++; written++;
@ -31,6 +36,11 @@ void DataOutputStream::write(unsigned int b)
void DataOutputStream::flush() void DataOutputStream::flush()
{ {
if (stream == NULL)
{
app.DebugPrintf("DataOutputStream::flush() called but underlying stream is NULL\n");
return;
}
stream->flush(); stream->flush();
} }
@ -51,6 +61,11 @@ void DataOutputStream::write(byteArray b)
//len - the number of bytes to write. //len - the number of bytes to write.
void DataOutputStream::write(byteArray b, unsigned int offset, unsigned int length) void DataOutputStream::write(byteArray b, unsigned int offset, unsigned int length)
{ {
if (stream == NULL)
{
app.DebugPrintf("DataOutputStream::write(byteArray,...) called but underlying stream is NULL\n");
return;
}
stream->write(b, offset, length); stream->write(b, offset, length);
// TODO 4J Stu - Some form of error checking? // TODO 4J Stu - Some form of error checking?
written += length; written += length;
@ -60,6 +75,11 @@ void DataOutputStream::write(byteArray b, unsigned int offset, unsigned int leng
//The close method of FilterOutputStream calls its flush method, and then calls the close method of its underlying output stream. //The close method of FilterOutputStream calls its flush method, and then calls the close method of its underlying output stream.
void DataOutputStream::close() void DataOutputStream::close()
{ {
if (stream == NULL)
{
app.DebugPrintf("DataOutputStream::close() called but underlying stream is NULL\n");
return;
}
stream->close(); stream->close();
} }