TitleOptimize FileUtil.copyContents()
Date23-Feb-2006 19:49:19 EET
Bug criticalityMediumBug
Browser versionIE 6.0
Bug statusClosedBug
PageProvider used
Servlet ContainerTomcat5
Operating SystemLinux
Java version1.4.2

Uploading a 30MB attachment takes 10-20 minutes. Researching the problem I traced the slowness to BasicAttachmentProvider.putAttachementData()'s call to com.ecyrd.jspwiki.FileUtil.copyContents().

This method copies the attachments byte-by-byte, which results in 90+% of the delay. Please make this a buffered operation.

Instead of,

    public static void copyContents( InputStream in, OutputStream out )
        throws IOException
        int c;
        while( (c = in.read()) != -1  )
            out.write( c );


How about something like the following (compiled but not tested. I have used this approach before with MASSIVE speed improvement over the byte-by-byte method)

	public static void copyContents(InputStream in, OutputStream out)
			throws IOException {
		byte[] buf = new byte[4096];
		int bytesRead = 0;

		while ((bytesRead = in.read(buf)) > 0) {
			out.write(buf, 0, bytesRead);


Oops... I thought I already had. Thanks, will be fixed.

-- JanneJalkanen

Be careful with the fix! I had also changed that code because it performs horrible but there whas a problem with the javaclass TranslatorReader (I measured a 5-7x improvement). I had to revert my change! see BugClickingOnmoreInfoOnHttpwww.jspwiki.orgwikiMainTakesAVeryLongTime at 'Oef, A major setback'

-- KeesKuip

Since 2.3 no longer uses the TranslatorReader, we can safely go and take this patch in. It's in 2.3.100. Thanks!

-- JanneJalkanen, 13-Apr-2006

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-5) was last changed on 13-Apr-2006 23:32 by Janne Jalkanen