return splitBuffer(splitFactor, bytes, null);
}
private LargeMessageControllerImpl splitBuffer(final int splitFactor, final byte[] bytes, final File file) throws Exception
{
LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), bytes.length, 5000, file);
ByteArrayInputStream input = new ByteArrayInputStream(bytes);
while (true)
{
byte[] splitElement = new byte[splitFactor];
int size = input.read(splitElement);
if (size <= 0)
{
break;
}
SessionReceiveContinuationMessage packet = null;
if (size < splitFactor)
{
byte[] newSplit = new byte[size];
System.arraycopy(splitElement, 0, newSplit, 0, size);
packet = new FakePacket(1, newSplit, input.available() > 0, false);
}
else
{
packet = new FakePacket(1, splitElement, input.available() > 0, false);
}
outBuffer.addPacket(packet);
}
return outBuffer;
}