private void doWriteSignature() throws IOException {
        // calculate the ByteRange values
        long inLength = incrementalInput.length();
        long beforeLength = signatureOffset;
        long afterOffset = signatureOffset + signatureLength;
        long afterLength = getStandardOutput().getPos() - (inLength + signatureLength) -
                (signatureOffset - inLength);

        String byteRange = "0 " + beforeLength + " " + afterOffset + " " + afterLength + "]";

        // Assign the values to the actual COSArray, so that the user can access it before closing
        byteRangeArray.set(0, COSInteger.ZERO);
        byteRangeArray.set(1, COSInteger.get(beforeLength));
        byteRangeArray.set(2, COSInteger.get(afterOffset));
        byteRangeArray.set(3, COSInteger.get(afterLength));

        if (byteRange.length() > byteRangeLength) {
            throw new IOException("Can't write new byteRange '" + byteRange +
                    "' not enough space: byteRange.length(): " + byteRange.length() +
                    ", byteRangeLength: " + byteRangeLength);
        }

        // copy the new incremental data into a buffer (e.g. signature dict, trailer)
        output.flush();
        incrementPart = getBytes(output);

        // overwrite the ByteRange in the buffer
        byte[] byteRangeBytes = byteRange.getBytes(StandardCharsets.ISO_8859_1);
        for (int i = 0; i < byteRangeLength; i++) {
            if (i >= byteRangeBytes.length) {
                incrementPart[(int) (byteRangeOffset + i - inLength)] = 0x20; // SPACE
            } else {
                incrementPart[(int) (byteRangeOffset + i - inLength)] = byteRangeBytes[i];
            }
        }

        if (signatureInterface != null) {
            // data to be signed
            try (InputStream dataToSign = getDataToSign()) {
                // sign the bytes
                byte[] signatureBytes = signatureInterface.sign(dataToSign);
                writeExternalSignature(signatureBytes);
            }
        }
        // else signature should created externally and set via writeSignature()
    }
Write an incremental update for a non signature case. This can be used for e.g. augmenting
signatures.

@throws IOException
tika-fuzzing/src/main/java/org/apache/tika/fuzzing/pdf/EvilCOSWriter.java