private static Section convertMessageBody(String mimeType, byte[] data)
{
if("text/plain".equals(mimeType) || "text/xml".equals(mimeType))
{
String text = new String(data);
return new AmqpValue(text);
}
else if("jms/map-message".equals(mimeType))
{
TypedBytesContentReader reader = new TypedBytesContentReader(ByteBuffer.wrap(data));
LinkedHashMap map = new LinkedHashMap();
final int entries = reader.readIntImpl();
for (int i = 0; i < entries; i++)
{
try
{
String propName = reader.readStringImpl();
Object value = reader.readObject();
map.put(propName, value);
}
catch (EOFException e)
{
throw new IllegalArgumentException(e);
}
catch (TypedBytesFormatException e)
{
throw new IllegalArgumentException(e);
}
}
return new AmqpValue(fixMapValues(map));
}
else if("amqp/map".equals(mimeType))
{
BBDecoder decoder = new BBDecoder();
decoder.init(ByteBuffer.wrap(data));
final Map<String,Object> map = decoder.readMap();
return new AmqpValue(fixMapValues(map));
}
else if("amqp/list".equals(mimeType))
{
BBDecoder decoder = new BBDecoder();
decoder.init(ByteBuffer.wrap(data));
return new AmqpValue(fixListValues(decoder.readList()));
}
else if("jms/stream-message".equals(mimeType))
{
TypedBytesContentReader reader = new TypedBytesContentReader(ByteBuffer.wrap(data));
List list = new ArrayList();
while (reader.remaining() != 0)
{
try
{
list.add(fixValue(reader.readObject()));
}
catch (TypedBytesFormatException e)
{
throw new RuntimeException(e); // TODO - Implement
}
catch (EOFException e)
{
throw new RuntimeException(e); // TODO - Implement
}
}
return new AmqpValue(list);
}
else
{
return new Data(new Binary(data));