use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.
the class TestSignatureInfo method bug58630.
@Test
public void bug58630() throws Exception {
// test deletion of sheet 0 and signing
File tpl = copy(testdata.getFile("bug58630.xlsx"));
SXSSFWorkbook wb1 = new SXSSFWorkbook((XSSFWorkbook) WorkbookFactory.create(tpl), 10);
wb1.setCompressTempFiles(true);
wb1.removeSheetAt(0);
ByteArrayOutputStream os = new ByteArrayOutputStream();
wb1.write(os);
wb1.close();
OPCPackage pkg = OPCPackage.open(new ByteArrayInputStream(os.toByteArray()));
initKeyPair("Test", "CN=Test");
SignatureConfig signatureConfig = new SignatureConfig();
signatureConfig.setKey(keyPair.getPrivate());
signatureConfig.setSigningCertificateChain(Collections.singletonList(x509));
signatureConfig.setOpcPackage(pkg);
SignatureInfo si = new SignatureInfo();
si.setSignatureConfig(signatureConfig);
si.confirmSignature();
assertTrue("invalid signature", si.verifySignature());
pkg.close();
}
use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.
the class SXSSFITestDataProvider method createWorkbook.
//************ SXSSF-specific methods ***************//
@Override
public SXSSFWorkbook createWorkbook(int rowAccessWindowSize) {
SXSSFWorkbook wb = new SXSSFWorkbook(rowAccessWindowSize);
instances.add(wb);
return wb;
}
use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.
the class SXSSFITestDataProvider method writeOutAndReadBack.
/**
* Returns an XSSFWorkbook since SXSSFWorkbook is write-only
*/
@Override
public XSSFWorkbook writeOutAndReadBack(Workbook wb) {
// several times in succession
if (!(wb instanceof SXSSFWorkbook || wb instanceof XSSFWorkbook)) {
throw new IllegalArgumentException("Expected an instance of SXSSFWorkbook");
}
XSSFWorkbook result;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
wb.write(baos);
InputStream is = new ByteArrayInputStream(baos.toByteArray());
result = new XSSFWorkbook(is);
} catch (IOException e) {
throw new RuntimeException(e);
}
return result;
}
use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project tika by apache.
the class Report method dumpXLSX.
private void dumpXLSX(Connection c, Path reportsRoot) throws IOException, SQLException {
Statement st = c.createStatement();
Path out = reportsRoot.resolve(reportFilename);
Files.createDirectories(out.getParent());
SXSSFWorkbook wb = new SXSSFWorkbook(new XSSFWorkbook(), 100, true, true);
wb.setCompressTempFiles(true);
defaultIntegerFormatter.reset(wb.getXSSFWorkbook());
defaultDoubleFormatter.reset(wb.getXSSFWorkbook());
sqlCellStyle = wb.createCellStyle();
sqlCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
sqlCellStyle.setWrapText(true);
try {
dumpReportToWorkbook(st, wb);
} finally {
try (OutputStream os = Files.newOutputStream(out)) {
wb.write(os);
} finally {
wb.dispose();
}
}
}
Aggregations