if (name == null) {
// XXX: is this an error?
continue;
}
else if (filename != null) {
Path tempDir = CauchoSystem.getWorkPath().lookup("form");
try {
tempDir.mkdirs();
} catch (IOException e) {
}
Path tempFile = tempDir.createTempFile("form", ".tmp");
request.addCloseOnExit(tempFile);
WriteStream os = tempFile.openWrite();
TempBuffer tempBuffer = TempBuffer.allocate();
byte []buf = tempBuffer.getBuffer();
int totalLength = 0;
try {
int len;
while ((len = is.read(buf, 0, buf.length)) > 0) {
os.write(buf, 0, len);
totalLength += len;
}
} finally {
os.close();
TempBuffer.free(tempBuffer);
tempBuffer = null;
}
if (uploadMax > 0 && uploadMax < tempFile.getLength()) {
String msg = L.l("multipart form data '{0}' too large",
"" + tempFile.getLength());
request.setAttribute("caucho.multipart.form.error", msg);
request.setAttribute("caucho.multipart.form.error.size",
new Long(tempFile.getLength()));
tempFile.remove();
throw new IOException(msg);
} else if (fileUploadMax > 0 && fileUploadMax < tempFile.getLength()){
String msg = L.l("multipart form data part '{0}':'{1}' is greater then the accepted value of '{2}'",
name, "" + tempFile.getLength(), fileUploadMax);
tempFile.remove();
throw new IllegalStateException(msg);
}
else if (tempFile.getLength() != totalLength) {
String msg = L.l("multipart form upload failed (possibly due to full disk).");
request.setAttribute("caucho.multipart.form.error", msg);
request.setAttribute("caucho.multipart.form.error.size",
new Long(tempFile.getLength()));
tempFile.remove();
throw new IOException(msg);
}
// server/136u, server/136v, #2578
if (table.get(name + ".filename") == null) {
table.put(name, new String[] { tempFile.getNativePath() });
table.put(name + ".file", new String[] { tempFile.getNativePath() });
table.put(name + ".filename", new String[] { filename });
table.put(name + ".content-type", new String[] { contentType });
}
else {
addTable(table, name, tempFile.getNativePath());
addTable(table, name + ".file", tempFile.getNativePath());
addTable(table, name + ".filename", filename);
addTable(table, name + ".content-type", contentType);
}
if (log.isLoggable(Level.FINE))