Update to LCEMP's ByteArrayIO version
Fixes compilation since ours was missing some revisions from LCEMP
This commit is contained in:
@@ -23,6 +23,7 @@ ByteArrayInputStream::ByteArrayInputStream(byteArray buf, unsigned int offset, u
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
count = offset + length;
|
count = offset + length;
|
||||||
|
}
|
||||||
this->buf = buf;
|
this->buf = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,10 +45,14 @@ ByteArrayInputStream::ByteArrayInputStream(byteArray buf)
|
|||||||
int ByteArrayInputStream::read()
|
int ByteArrayInputStream::read()
|
||||||
{
|
{
|
||||||
if (pos >= count)
|
if (pos >= count)
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return buf[pos++];
|
return buf[pos++];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reads some number of bytes from the input stream and stores them into the buffer array b.
|
// Reads some number of bytes from the input stream and stores them into the buffer array b.
|
||||||
// The number of bytes actually read is returned as an integer. This method blocks until input data is available,
|
// The number of bytes actually read is returned as an integer. This method blocks until input data is available,
|
||||||
@@ -86,7 +91,9 @@ int ByteArrayInputStream::read(byteArray b)
|
|||||||
int ByteArrayInputStream::read(byteArray b, unsigned int offset, unsigned int length)
|
int ByteArrayInputStream::read(byteArray b, unsigned int offset, unsigned int length)
|
||||||
{
|
{
|
||||||
if (pos == count)
|
if (pos == count)
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int k = min(length, count - pos);
|
int k = min(length, count - pos);
|
||||||
XMemCpy(&b[offset], &buf[pos], k);
|
XMemCpy(&b[offset], &buf[pos], k);
|
||||||
@@ -111,11 +118,14 @@ void ByteArrayInputStream::close()
|
|||||||
// n - the number of bytes to be skipped.
|
// n - the number of bytes to be skipped.
|
||||||
// Returns:
|
// Returns:
|
||||||
// the actual number of bytes skipped.
|
// the actual number of bytes skipped.
|
||||||
int64_t ByteArrayInputStream::skip(int64_t n)
|
__int64 ByteArrayInputStream::skip(__int64 n)
|
||||||
{
|
{
|
||||||
int newPos = pos + n;
|
int newPos = pos + n;
|
||||||
|
|
||||||
if(newPos > count) newPos = count;
|
if (newPos > count)
|
||||||
|
{
|
||||||
|
newPos = count;
|
||||||
|
}
|
||||||
|
|
||||||
int k = newPos - pos;
|
int k = newPos - pos;
|
||||||
pos = newPos;
|
pos = newPos;
|
||||||
@@ -125,5 +135,8 @@ int64_t ByteArrayInputStream::skip(int64_t n)
|
|||||||
|
|
||||||
ByteArrayInputStream::~ByteArrayInputStream()
|
ByteArrayInputStream::~ByteArrayInputStream()
|
||||||
{
|
{
|
||||||
if(buf.data != nullptr) delete [] buf.data;
|
if (buf.data != NULL)
|
||||||
|
{
|
||||||
|
delete[] buf.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -20,9 +20,11 @@ ByteArrayOutputStream::ByteArrayOutputStream(unsigned int size)
|
|||||||
|
|
||||||
ByteArrayOutputStream::~ByteArrayOutputStream()
|
ByteArrayOutputStream::~ByteArrayOutputStream()
|
||||||
{
|
{
|
||||||
if (buf.data != nullptr)
|
if (buf.data != NULL)
|
||||||
|
{
|
||||||
delete[] buf.data;
|
delete[] buf.data;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Writes the specified byte to this byte array output stream.
|
// Writes the specified byte to this byte array output stream.
|
||||||
// Parameters:
|
// Parameters:
|
||||||
@@ -31,9 +33,11 @@ void ByteArrayOutputStream::write(unsigned int b)
|
|||||||
{
|
{
|
||||||
// If we will fill the buffer we need to make it bigger
|
// If we will fill the buffer we need to make it bigger
|
||||||
if (count + 1 >= buf.length)
|
if (count + 1 >= buf.length)
|
||||||
|
{
|
||||||
buf.resize(buf.length * 2);
|
buf.resize(buf.length * 2);
|
||||||
|
}
|
||||||
|
|
||||||
buf[count] = static_cast<byte>(b);
|
buf[count] = (byte)b;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +55,6 @@ void ByteArrayOutputStream::write(byteArray b)
|
|||||||
// len - the number of bytes to write.
|
// len - the number of bytes to write.
|
||||||
void ByteArrayOutputStream::write(byteArray b, unsigned int offset, unsigned int length)
|
void ByteArrayOutputStream::write(byteArray b, unsigned int offset, unsigned int length)
|
||||||
{
|
{
|
||||||
assert( b.length >= offset + length );
|
|
||||||
|
|
||||||
if (offset > b.length || length > b.length - offset)
|
if (offset > b.length || length > b.length - offset)
|
||||||
{
|
{
|
||||||
@@ -61,6 +64,7 @@ void ByteArrayOutputStream::write(byteArray b, unsigned int offset, unsigned int
|
|||||||
if (length > 0xFFFFFFFF - count)
|
if (length > 0xFFFFFFFF - count)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If we will fill the buffer we need to make it bigger
|
// If we will fill the buffer we need to make it bigger
|
||||||
if (count + length >= buf.length)
|
if (count + length >= buf.length)
|
||||||
@@ -74,7 +78,6 @@ void ByteArrayOutputStream::write(byteArray b, unsigned int offset, unsigned int
|
|||||||
}
|
}
|
||||||
|
|
||||||
XMemCpy(&buf[count], &b[offset], length);
|
XMemCpy(&buf[count], &b[offset], length);
|
||||||
//std::copy( b->data+offset, b->data+offset+length, buf->data + count ); // Or this instead?
|
|
||||||
|
|
||||||
count += length;
|
count += length;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user