You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.1 KiB
86 lines
3.1 KiB
2 years ago
|
package com.hzdatalink.gsdes.export;
|
||
|
|
||
|
import com.fr.general.CommonIOUtils;
|
||
|
import com.fr.io.exporter.AppExporter;
|
||
|
import com.fr.log.FineLoggerFactory;
|
||
|
import com.fr.main.workbook.ResultWorkBook;
|
||
|
import com.fr.page.PageSetCreator;
|
||
|
import com.fr.page.PageSetProvider;
|
||
|
import com.fr.web.core.ReportRepositoryDeal;
|
||
|
import com.hzdatalink.gsdes.FileOperation;
|
||
|
import com.hzdatalink.gsdes.util.FileUtil;
|
||
|
|
||
|
import java.io.*;
|
||
|
|
||
|
/**
|
||
|
* @Author xx
|
||
|
* @Date 2021/11/23
|
||
|
* @Description
|
||
|
**/
|
||
|
public class EncryptExporter implements AppExporter {
|
||
|
|
||
|
private AppExporter original;
|
||
|
|
||
|
public EncryptExporter(AppExporter original) {
|
||
|
this.original = original;
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public void export(OutputStream out, ResultWorkBook book) throws Exception {
|
||
|
ByteArrayOutputStream encryptOutputStream = new ByteArrayOutputStream();
|
||
|
original.export(encryptOutputStream, book);
|
||
|
this.encrypt(encryptOutputStream.toByteArray(),out);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void export(OutputStream out, PageSetProvider pageSet) throws Exception {
|
||
|
ByteArrayOutputStream encryptOutputStream = new ByteArrayOutputStream();
|
||
|
original.export(encryptOutputStream, pageSet);
|
||
|
this.encrypt(encryptOutputStream.toByteArray(),out);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void export(OutputStream out, ResultWorkBook book, PageSetCreator creator, ReportRepositoryDeal repo, int[] sheets) throws Exception {
|
||
|
ByteArrayOutputStream encryptOutputStream = new ByteArrayOutputStream();
|
||
|
original.export(encryptOutputStream, book, creator, repo, sheets);
|
||
|
this.encrypt(encryptOutputStream.toByteArray(),out);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void export(OutputStream out, ResultWorkBook book, PageSetProvider pageSet, ReportRepositoryDeal repo, int[] sheets) throws Exception {
|
||
|
ByteArrayOutputStream encryptOutputStream = new ByteArrayOutputStream();
|
||
|
original.export(encryptOutputStream, book, pageSet, repo, sheets);
|
||
|
this.encrypt(encryptOutputStream.toByteArray(),out);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void setVersion(Object o) {
|
||
|
original.setVersion(o);
|
||
|
}
|
||
|
|
||
|
private void encrypt(byte[] bytes,OutputStream outputStream) throws IOException {
|
||
|
FileOutputStream fileOutputStream = null;
|
||
|
try {
|
||
|
File tempFile = FileUtil.createTempFile();
|
||
|
File encodeFile = FileUtil.createTempFile();
|
||
|
fileOutputStream = new FileOutputStream(tempFile);
|
||
|
fileOutputStream.write(bytes);
|
||
|
fileOutputStream.flush();
|
||
|
FileOperation.encodeFile(tempFile.getAbsolutePath(), encodeFile.getAbsolutePath());
|
||
|
byte[] encodeByte = CommonIOUtils.inputStream2Bytes(new FileInputStream(encodeFile));
|
||
|
tempFile.deleteOnExit();
|
||
|
encodeFile.deleteOnExit();
|
||
|
outputStream.write(encodeByte);
|
||
|
outputStream.flush();
|
||
|
outputStream.close();
|
||
|
} catch (Exception e) {
|
||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e);
|
||
|
} finally {
|
||
|
if (fileOutputStream != null) {
|
||
|
fileOutputStream.close();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|