}
Object entity = bodyPart.getEntity();
if (entity == null) {
parts.add(PayloadImpl.Part.newInstance(mimeType, name, props, (InputStream) null));
} else if (entity instanceof BodyPartEntity) {
BodyPartEntity bpe = (BodyPartEntity) entity;
parts.add(PayloadImpl.Part.newInstance(mimeType, name, props, bpe.getInputStream()));
} else if (entity instanceof String) {
parts.add(PayloadImpl.Part.newInstance(mimeType, name, props, (String) entity));
} else {
throw new WebApplicationException(new Exception("Unsupported entity " + entity.getClass().getName()), Response.Status.BAD_REQUEST);
}