}
else
{
if(previousSection != null && (previousSection.getClass() != section.getClass() || section instanceof AmqpValue))
{
throw new ConnectionScopedRuntimeException("Message is badly formed and has multiple body section which are not all Data or not all AmqpSequence");
}
else
{
previousSection = section;
}
}
}
if(sections.isEmpty())
{
// should actually be illegal
bodyObject = new byte[0];
}
else
{
Section firstBodySection = sections.get(0);
if(firstBodySection instanceof AmqpValue)
{
bodyObject = fixObject(((AmqpValue)firstBodySection).getValue());
}
else if(firstBodySection instanceof Data)
{
int totalSize = 0;
for(Section section : sections)
{
totalSize += ((Data)section).getValue().getLength();
}
byte[] bodyData = new byte[totalSize];
ByteBuffer buf = ByteBuffer.wrap(bodyData);
for(Section section : sections)
{
buf.put(((Data)section).getValue().asByteBuffer());
}
bodyObject = bodyData;
}
else
{
ArrayList totalSequence = new ArrayList();
for(Section section : sections)
{
totalSequence.addAll(((AmqpSequence)section).getValue());
}
bodyObject = fixObject(totalSequence);
}
}
}
catch (AmqpErrorException e)
{
throw new ConnectionScopedRuntimeException(e);
}
return bodyObject;
}