FileItemIterator iter = upload.getItemIterator(requestContextWrapper);
List<UploadContext> uploadContexts = new ArrayList<UploadContext>(7);
List<NamedString> formParameters = new ArrayList<NamedString>(7);
while (iter.hasNext())
{
FileItemStream item = iter.next();
InputStream stream = item.openStream();
if (!item.isFormField())
{
String contentType = item.getContentType();
if (log.isDebugEnabled())
{
log.debug("File field " + item.getFieldName() + " with file name " + item.getName()
+ " and content type " + contentType + " detected.");
}
BufferedInputStream bufIn = new BufferedInputStream(stream);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(baos);
int c = bufIn.read();
while (c != -1)
{
bos.write(c);
c = bufIn.read();
}
bos.flush();
baos.flush();
bufIn.close();
bos.close();
final byte[] uploadData = baos.toByteArray();
if (uploadData.length != 0)
{
UploadContext uploadContext = WSRPTypeFactory.createUploadContext(contentType, uploadData);
List<NamedString> mimeAttributes = new ArrayList<NamedString>(2);
String value = FileUpload.FORM_DATA + ";" + " name=\"" + item.getFieldName() + "\";" + " filename=\"" + item.getName() + "\"";
NamedString mimeAttribute = WSRPTypeFactory.createNamedString(FileUpload.CONTENT_DISPOSITION, value);
mimeAttributes.add(mimeAttribute);
mimeAttribute = WSRPTypeFactory.createNamedString(FileUpload.CONTENT_TYPE, item.getContentType());
mimeAttributes.add(mimeAttribute);
uploadContext.getMimeAttributes().addAll(mimeAttributes);
uploadContexts.add(uploadContext);
}
else
{
log.debug("Ignoring empty file " + item.getName());
}
}
else
{
NamedString formParameter = WSRPTypeFactory.createNamedString(item.getFieldName(), Streams.asString(stream));
formParameters.add(formParameter);
}
}
result.getUploadContexts().addAll(uploadContexts);