class DownloadFileService implements Constants {

    public void downloadData(final HttpServletResponse servletResponse, final JsonArray response,
            final String fileFormat, String methodType) throws Exception {
        final OutputStream output = servletResponse.getOutputStream();
        byte[] byteArray=null;
        List<String> columnList = getColumnNames(response);
        if (!StringUtils.isEmpty(fileFormat) && "excel".equalsIgnoreCase(fileFormat)) {
            byteArray = getFileBytes(response, methodType,columnList);
            servletResponse.setHeader("Content-Disposition", "attachment; filename=" + methodType + "_"
                    + new DateTime() + ".xls");
            servletResponse.setContentType("application/vnd.ms-excel");
        } else {
            byteArray = generateCsvFile(response,columnList);
            servletResponse.setHeader("Content-Disposition", "attachment; filename=" + methodType + "_"
                    + new DateTime() + ".csv");
            servletResponse.setContentType("text/csv");
        }
        servletResponse.setContentLength(byteArray.length);
        output.write(byteArray);
        output.flush();
        output.close();
        columnList = new ArrayList<>();
    }

}