@Override
    protected int engineDoFinal(ByteBuffer input, ByteBuffer output) throws ShortBufferException,
            IllegalBlockSizeException, BadPaddingException {
        if (!ENABLE_BYTEBUFFER_OPTIMIZATIONS) {
            return super.engineDoFinal(input, output);
        }
        if (input == null || output == null) {
            throw new NullPointerException("Null ByteBuffer Error");
        }
        if (getOutputSizeForFinal(input.remaining()) > output.remaining()) {
            throw new ShortBufferWithoutStackTraceException("Insufficient Bytes for Output Buffer");
        }
        if (output.isReadOnly()) {
            throw new IllegalArgumentException("Cannot write to Read Only ByteBuffer");
        }
        if (bufCount != 0) {
            return super.engineDoFinal(input, output); // traditional case
        }
        int bytesWritten;
        if (!input.isDirect()) {
            int incap = input.remaining();
            ByteBuffer inputClone = ByteBuffer.allocateDirect(incap);
            inputClone.mark();
            inputClone.put(input);
            inputClone.reset();
            input = inputClone;
        }
        if (!output.isDirect()) {
            ByteBuffer outputClone = ByteBuffer.allocateDirect(
                    getOutputSizeForFinal(input.remaining()));
            bytesWritten = doFinalInternal(input, outputClone);
            output.put(outputClone);
            input.position(input.limit()); // API reasons
        }
        else {
            bytesWritten =  doFinalInternal(input, output);
            output.position(output.position() + bytesWritten);
            input.position(input.limit()); // API reasons
        }

        return bytesWritten;
    }
Returns whether reusing nonces is allowed (aka, whether this is nonce misuse-resistant).
Most AEAD ciphers are not, but some are specially constructed so that reusing a key/nonce
pair is safe.
common/src/main/java/org/conscrypt/OpenSSLAeadCipher.java