protected function download($data, $fileName = null)
    {
        if ($fileName === null) {
            $fileName = time();
        }

        while (ob_get_level() > 0) {
            ob_end_flush();
        }

        header('Content-Type: ' . $this->contentType);
        header('Content-Disposition: attachment; fileName="' . $fileName .'"');
        header("Content-Length: " . strlen($data));

        echo $data;
    }