void doReceive(final File file, final boolean resume) {
        new Thread() {
            public void run() {

                BufferedOutputStream foutput = null;
                Exception exception = null;

                try {

                    // Convert the integer address to a proper IP address.
                    int[] ip = _bot.longToIp(_address);
                    String ipStr = ip[0] + "." + ip[1] + "." + ip[2] + "." + ip[3];

                    // Connect the socket and set a timeout.
                    _socket = new Socket(ipStr, _port);
                    _socket.setSoTimeout(30*1000);
                    _startTime = System.currentTimeMillis();

                    // No longer possible to resume this transfer once it's underway.
                    _manager.removeAwaitingResume(DccFileTransfer.this);

                    BufferedInputStream input = new BufferedInputStream(_socket.getInputStream());
                    BufferedOutputStream output = new BufferedOutputStream(_socket.getOutputStream());

                    // Following line fixed for jdk 1.1 compatibility.
                    foutput = new BufferedOutputStream(new FileOutputStream(file.getCanonicalPath(), resume));

                    byte[] inBuffer = new byte[BUFFER_SIZE];
                    byte[] outBuffer = new byte[4];
                    int bytesRead = 0;
                    while ((bytesRead = input.read(inBuffer, 0, inBuffer.length)) != -1) {
                        foutput.write(inBuffer, 0, bytesRead);
                        _progress += bytesRead;
                        // Send back an acknowledgement of how many bytes we have got so far.
                        outBuffer[0] = (byte) ((_progress >> 24) & 0xff);
                        outBuffer[1] = (byte) ((_progress >> 16) & 0xff);
                        outBuffer[2] = (byte) ((_progress >> 8) & 0xff);
                        outBuffer[3] = (byte) ((_progress >> 0) & 0xff);
                        output.write(outBuffer);
                        output.flush();
                        delay();
                    }
                    foutput.flush();
                }
                catch (Exception e) {
                    exception = e;
                }
                finally {
                    try {
                        foutput.close();
                        _socket.close();
                    }
                    catch (Exception anye) {
                        // Do nothing.
                    }
                }

                _bot.onFileTransferFinished(DccFileTransfer.this, exception);
            }
        }.start();
    }