*/
private Part getPart() throws OMException {
// endOfStreamReached will be set to true if the message ended in MIME
// Style having "--" suffix with the last mime boundary
if (endOfStreamReached) {
throw new OMException(
"Referenced MIME part not found.End of Stream reached.");
}
Part part = null;
try {
if (fileCacheEnable) {
try {
MIMEBodyPartInputStream partStream;
byte[] buffer = new byte[fileStorageThreshold];
partStream = new MIMEBodyPartInputStream(pushbackInStream,
boundary, this);
int count = 0;
int value;
// Make sure not to modify this to a Short Circuit "&". If
// removed a byte will be lost
while (count != fileStorageThreshold
&& (!partStream.getBoundaryStatus())) {
value = partStream.read();
buffer[count] = (byte) value;
count++;
}
if (count == fileStorageThreshold) {
PushbackFilePartInputStream filePartStream = new PushbackFilePartInputStream(
partStream, buffer);
part = new PartOnFile(filePartStream, attachmentRepoDir);
} else {
ByteArrayInputStream byteArrayInStream = new ByteArrayInputStream(
buffer, 0, count - 1);
part = new PartOnMemory(byteArrayInStream);
}
} catch (Exception e) {
throw new OMException("Error creating temporary File.", e);
}
} else {
MIMEBodyPartInputStream partStream;
partStream = new MIMEBodyPartInputStream(pushbackInStream,
boundary, this);
part = new PartOnMemory(partStream);
}
// This will take care if stream ended without having MIME
// message terminator
if (part.getSize() <= 0) {
throw new OMException(
"Referenced MIME part not found.End of Stream reached.");
}
} catch (MessagingException e) {
throw new OMException(e);
}
partIndex++;
return part;
}