PDFBOX:COSStream已关闭,无法读取。也许它的封闭 PDDocument 已经关闭?

问题描述 投票:0回答:0

我正在尝试使用 pdfbox 执行签名。在调用 saveIncrementalForExternalSigning 方法之前,我添加了验证信息。

    public ByteArrayOutputStream addSignature(PDDocument document, PDSignature signature, InputStream inputStream,
                                              SealCSCCredentialOptions cscCredentialOptions, Certificate[] certificateChain, String signatureFormat)
            throws Exception {


        

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ExternalSigningSupport externalSigningSupport = null;
        try {
            externalSigningSupport = document.saveIncrementalForExternalSigning(outputStream);
        } catch (IOException e)
        {
            e.printStackTrace();
            LOG.error("Request ID: {} Error occurred: " + e.getMessage(), LoggerUtils.getFromThreadContext("requestId"));
            throw e;
        }

        CMSSignedData signedData = generateCMSSignedData(certificateChain, externalSigningSupport, inputStream,
                cscCredentialOptions, signatureFormat);

        byte[] cmsSignature = signedData.getEncoded();
        externalSigningSupport.setSignature(cmsSignature);
        
        return outputStream;
    }

但是我在打电话时出现间歇性错误

externalSigningSupport = document.saveIncrementalForExternalSigning(outputStream);
COSStream 已经关闭,无法读取。也许它的封闭 PDDocument 已经关闭?

我间歇性地收到这个错误。有时它会给出那个错误。我在某些情况下得到了成功的回应。

有人可以帮忙弄清楚我做错了什么以及为什么我会间歇性地收到该错误吗?

java certificate pdfbox digital-signature
© www.soinside.com 2019 - 2024. All rights reserved.