public void doDownload(HttpRequest request, long contentLength, OutputStream clientOut)
    {
        cout = clientOut;
        SpeedThread speedThread = new SpeedThread(this);
        buffer = new CircularDownloadBuffer(bufferSize);

        // Also write the request out to a file
        BufferedOutputStream fileOut = null; 
        
        try
        {
            String outFile = request.getFileName();
            if(outputDir != null) {
                outFile = outputDir + File.separator + request.getFileName();
                fileOut = new BufferedOutputStream(new FileOutputStream(outFile));
            }
            
            downloadThreads = new DownloadThread[downloadThreadCount];
            for (int i = 0; i < downloadThreadCount; i++)
            {
                downloadThreads[i] = new DownloadThread(request, buffer, this);
                downloadThreads[i].start();
            }
            
            speedThread.start();
            
            // Whoa there boyo, give the server time to give us some data before we start sending it to the client
            Thread.sleep(2000);
            
            byte readBuffer[] = new byte[4096];
            int readLength = 4096;
            while (bytesSent < contentLength - 1 && !downloadFinished)
            {
                // For the last set of bytes that we download we need to make sure we don't try and read too much
                // from the circular buffer, otherwise it will block waiting for more data
                if(readLength + bytesSent >= contentLength)
                    readLength = (int) (contentLength - bytesSent - 1);
                
                int newBytes = buffer.read(readBuffer, readLength);
                clientOut.write(readBuffer, 0, newBytes);
                if(fileOut != null) {
                   fileOut.write(readBuffer, 0, newBytes);
                }
                bytesSent += newBytes;
            }
            clientOut.flush();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            downloadFinished = true;
            buffer.quit();
            if(fileOut != null)
              try { fileOut.close(); } catch(IOException e) {}
        }
        log.debug("Manager - finished sent: " + bytesSent);
    }