Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Duplicate
-
1.4.9
Description
The current code of org.apache.wicket.markup.html.form.upload.FileUpload.writeTo(File):
public void writeTo(final File file) throws IOException
{
writeTo(file, 4096);
}
simply delegates to org.apache.wicket.markup.html.form.upload.FileUpload.writeTo(File, int):
public void writeTo(final File file, final int bufSize) throws IOException
{
InputStream is = getInputStream();
try
finally
{ is.close(); }}
which opens an inputstream and pumbs the content to the parameter file. This means that there is always a copy.
But if writeTo(File) would look something like this:
public void writeTo(final File file) throws IOException
{
item.write(file);
// item.write can throw Exception so some exception handling is also needed (rethrow as IOException maybe)
}
This could be more efficient because item is a FileItem which is probably a DiskFileItem (the only implementation in wicket), and DiskFileItem.write() tries to simply rename the file first. If that fails it tries to copy. So if rename works there is no need to copy and the code runs faster.