TrustedByteArrayOutputStream output = new TrustedByteArrayOutputStream(estimatedByteSize);
try {
boolean previousCarryOver = false;
for (int i = 0; i< expressionCount; i++) {
Expression child = getChildren().get(i);
PDataType childType = child.getDataType();
ImmutableBytesWritable tempPtr = ptrs[i];
if (tempPtr == null) {
// Since we have a null and have no representation for null,
// we must decrement the value of the current. Otherwise,
// we'd have an ambiguity if this value happened to be the
// min possible value.
previousCarryOver = childType == null || childType.isFixedWidth();
int bytesToWrite = getExpressionByteCount(child);
for (int m = 0; m < bytesToWrite; m++) {
output.write(QueryConstants.SEPARATOR_BYTE);
}
} else {
output.write(tempPtr.get(), tempPtr.getOffset(), tempPtr.getLength());
if (!childType.isFixedWidth()) {
output.write(QueryConstants.SEPARATOR_BYTE);
}
if (previousCarryOver) {
previousCarryOver = !ByteUtil.previousKey(output.getBuffer(), output.size());
}