// If this is a SOAPPart, keep it in memory.
// Get the bytes of the data without a lot
// of resizing and GC. The BAAOutputStream
// keeps the data in non-contiguous byte buffers.
BAAOutputStream baaos = new BAAOutputStream();
BufferUtils.inputStream2OutputStream(dross, baaos);
BufferUtils.inputStream2OutputStream(in, baaos);
return new PartOnMemoryEnhanced(headers, baaos.buffers(), baaos.length());
} else {
// We need to read the input stream to determine whether
// the size is bigger or smaller than the threshhold.
BAAOutputStream baaos = new BAAOutputStream();
int t1 = BufferUtils.inputStream2OutputStream(dross, baaos, threshholdSize);
int t2 = BufferUtils.inputStream2OutputStream(in, baaos, threshholdSize - t1);
int total = t1 + t2;
if (total < threshholdSize) {
return new PartOnMemoryEnhanced(headers, baaos.buffers(), baaos.length());
} else {
// A BAAInputStream is an input stream over a list of non-contiguous 4K buffers.
BAAInputStream baais =
new BAAInputStream(baaos.buffers(), baaos.length());
return new PartOnFile(manager, headers,
baais,
in,
attachmentDir);