// read size (#bytes)
int size = _read4int( littleEndian, buffer, pos);
if (size < 1)
{
throw new MARSHAL("invalid string size: " + size);
}
int start = pos + 4;
index += (size + 4);
pos += (size + 4);
final int stringTerminatorPosition = start + size -1;
if (buffer.length < stringTerminatorPosition + 1)
{
throw new MARSHAL("buffer too small");
}
if ((buffer[stringTerminatorPosition] == 0))
{
size --;
}
else
{
throw new MARSHAL("unexpected string terminator value " + Integer.toHexString(buffer[stringTerminatorPosition]) + " at buffer index " + stringTerminatorPosition);
}
// Optimize for empty strings.
if (size == 0)
{
return "";
}
if(start + size > buffer.length)
{
final String message = "Size (" + size + ") invalid for string extraction from buffer length of " + buffer.length + " from position " + start;
if (logger.isDebugEnabled())
{
logger.debug(message);
}
throw new MARSHAL(message);
}
if (codesetEnabled)
{