* @param http The <code>HttpExchange</code> object containing POST request data.
* @return The temporary file containing the extracted POST data.
* @throws IOException if an error occurs while attempting to extract the POST request data.
*/
private File extractPostContent(final HttpExchange http) throws IOException {
final BoundaryDelimitedInputStream iStream = new BoundaryDelimitedInputStream(http.getRequestBody(), POST_BOUNDARY);
final File tempUploadFile = File.createTempFile("upload", ".tmp", serverTempDir);
final BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tempUploadFile));
final byte[] buffer = new byte[UPLOAD_BUFFER_SIZE];
boolean isDeploymentPart = false;
try {
// Read from the stream until the deployment is found in the POST data.
while (!isDeploymentPart && !iStream.isOuterStreamClosed()) {
int numRead = 0;
// Read the POST section header from the inner stream.
final MultipartHeader header = readHeader(iStream);
if(header != null) {
// Determine if the current section is a deployment file upload.
isDeploymentPart = MULTIPART_FORM_DATA_CONTENT_TYPE.equals(header.getContentType());
/*
* Read the body following the header. If it is the deployment,
* write it to the temporary file. Otherwise, discard the data.
*/
while (numRead != -1) {
numRead = iStream.read(buffer);
if (numRead > 0 && isDeploymentPart) {
bos.write(buffer, 0, numRead);
}
}
}