package com.njcn.rdms.module.project.controller.admin.workreport.common;

import com.njcn.rdms.framework.common.util.http.HttpUtils;
import com.njcn.rdms.module.project.service.workreport.export.WorkReportExportFile;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public final class WorkReportExportResponseUtils {

    private WorkReportExportResponseUtils() {
    }

    public static void write(HttpServletResponse response, WorkReportExportFile file) throws IOException {
        response.addHeader("Content-Disposition", "attachment;filename=" + HttpUtils.encodeUtf8(file.filename()));
        response.setContentType(file.contentType());
        response.setContentLength(file.content().length);
        response.getOutputStream().write(file.content());
    }
}
