Code example for ShortBufferException

0
            BadPaddingException { 
        byte[] b = engineDoFinal(input, inputOffset, inputLen);
 
        final int lastOffset = outputOffset + b.length;
        if (lastOffset > output.length) {
            throw new ShortBufferException("output buffer is too small " + output.length + " < "
                    + lastOffset);
        } 
 
        System.arraycopy(b, 0, output, outputOffset, b.length);
        return b.length;
    } 
 
    @Override 
    protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException {
        try { 
            byte[] encoded = key.getEncoded();
            return engineDoFinal(encoded, 0, encoded.length);
        } catch (BadPaddingException e) {
            IllegalBlockSizeException newE = new IllegalBlockSizeException();
            newE.initCause(e);