@Override
    public void run() {
        URLConnection conn = null;
        try {
            conn = prepareConnection();
            prepareStream(conn);

            response.setStatus(DownloadResponseImpl.Status.IN_PROGRESS);

            try (InputStream inputStream = conn.getInputStream()) {
                byte[] tmpBuf = new byte[TMP_BUF_SIZE];

                while (!Thread.currentThread().isInterrupted()) {
                    int len = inputStream.read(tmpBuf);
                    if (len == -1) {
                        response.setStatus(DownloadResponseImpl.Status.FINISHED);
                        break;
                    }
                    response.getStream().write(tmpBuf, 0, len);

                    if (response.checkPaused(supportsRangedDownload(conn))) {
                        // Should release the current thread and connection on pause
                        return;
                    }

                    if (response.getStatus() == DownloadResponseImpl.Status.CANCELLED) {
                        //Clean up already downloaded memory
                        response.setStream(null);
                        return;
                    }
                }
            }
        } catch (IOException | InterruptedException e) {
            response.setStatus(DownloadResponseImpl.Status.FAILED);
        } finally {
            finalizeConnection(conn);
        }
    }