String fileName = "configKV.json";
String downConfFile = configManagerService.downConfFile();
System.out.println(downConfFile.substring(downConfFile.length()-50,downConfFile.length()));
response.addHeader("Content-Type", "application/octet-stream");
response.addHeader("Content-Length", "" + downConfFile.getBytes().length);
response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
int BUFFER_SIZE = 4096;
byte[] buffer = new byte[BUFFER_SIZE];
try (OutputStream outputStream = response.getOutputStream();
ByteArrayInputStream inputStream = new ByteArrayInputStream(downConfFile.getBytes())) {
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.flush();
} catch (IOException e) {
throw new MeshException("文件下载失败");
} finally {
try {
response.getOutputStream().close();
}catch (IOException ioException){
throw new MeshException("文件下载失败");
}
}