Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-2913

o.a.w.markup.html.form.upload.FileUpload.writeTo(File) is not optimal

    XMLWordPrintableJSON

    Details

      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

      { Files.writeTo(file, is, bufSize); }

      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.

        Attachments

          Activity

            People

            • Assignee:
              pete Peter Ertl
              Reporter:
              akiraly Attila Király
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: