InputStream istream = in.getInputStream();
CompositeMessagePart rootPart = msg.getRoot();
CompositeMessagePart entriesPart = (CompositeMessagePart)rootPart.getPart(0);
TransferObject root = new TransferObject(msg.getName());
List entryList = new ArrayList();
ZipInputStream zipStream = new ZipInputStream(istream);
ZipEntry zipEntry;
root.setValue(entriesPart.getName(), entryList);
try
{
while ((zipEntry = zipStream.getNextEntry()) != null)
{
String sKeySize = null;
long lValueSize = 0;
String sKeyContents = null;
Primitive sizeType = null;
TransferObject entry = new TransferObject();
entryList.add(entry);
// Iterate the parts, assigning data from the Zip entry
for (int i = 0; i < entriesPart.getPartCount(); i++)
{
PrimitiveMessagePart part = (PrimitiveMessagePart)entriesPart.getPart(i);
ZipMessagePartMapping mapping = (ZipMessagePartMapping)part.getMapping();
Object datum = null;
Primitive partType = part.getType();
switch (mapping.getValue())
{
case ZipMessagePartMapping.VALUE_CONTENTS:
Binary contents = new PagedBinary(zipStream);
zipStream.closeEntry();
if (s_logger.isDebugEnabled())
{
s_logger.debug("Extracted contents of \"" + zipEntry.getName() + "\" size=" + contents.getSize());
}
if (contents.getSize() > 0)
{
datum = partType.getConverter(Primitive.BINARY).invoke(contents);
}
sKeyContents = part.getName();
break;
case ZipMessagePartMapping.VALUE_COMMENT:
datum = partType.getConverter(Primitive.STRING).invoke(zipEntry.getComment());
break;
case ZipMessagePartMapping.VALUE_DIRECTORY:
datum = partType.getConverter(Primitive.BOOLEAN).invoke(Boolean.valueOf(zipEntry.isDirectory()));
break;
case ZipMessagePartMapping.VALUE_EXTRA:
if (zipEntry.getExtra() != null)
{
datum = partType.getConverter(Primitive.BINARY).invoke(new Binary(zipEntry.getExtra()));
}
break;
case ZipMessagePartMapping.VALUE_NAME:
datum = partType.getConverter(Primitive.STRING).invoke(convertZipSeparatorToPlatformSeparator(zipEntry.getName()));
break;
case ZipMessagePartMapping.VALUE_SIZE:
datum = partType.getConverter(Primitive.LONG).invoke(Primitive.createLong(zipEntry.getSize()));
sKeySize = part.getName();
lValueSize = zipEntry.getSize();
sizeType = partType;
break;
case ZipMessagePartMapping.VALUE_TIME:
datum = partType.getConverter(Primitive.LONG).invoke(Primitive.createLong(zipEntry.getTime()));
break;
default:
throw new IllegalStateException("Unknown value: " + mapping.getValue());
}
entry.setValue(part.getName(), datum);
}
// Process the size entry
if (sKeySize != null && sKeyContents != null)
{
Binary contents = (Binary)entry.getValue(sKeyContents);
long lContentsSize = (contents != null) ? contents.getSize() : 0;
if (lValueSize == -1)
{
// Populate the size entry from the Binary's size
entry.setValue(sKeySize, sizeType.getConverter(Primitive.LONG).invoke(Primitive.createLong(lContentsSize)));
}
else
{
// Ensure size entry matches Binary's size
if (lValueSize != lContentsSize)