⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paddingscheme.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        int result = enginePad(in, offset, length);        if (tracing) traceResult(result);        return result;    }    /**     * Returns the increase in size that a padding operation would cause on     * input data of a given length. This is always     * <code>blockSize - (length % blockSize)</code>.     *     * @param  length   the length of the data to be padded.     * @return the increase in size that a padding operation would cause on     *                  input of the specified length.     */    public final int padLength(int length) {        return blockSize - (length % blockSize);    }    /**     * Given the specified subarray of bytes that includes padding bytes,     * returns the index indicating where padding starts.     * <p>     * <i>length</i> must be at least <code>blockSize</code>.     *     * @param  in       the buffer containing the bytes.     * @param  offset   the offset into the <i>in</i> buffer of the     *                  first byte in the block.     * @param  length   the total length in bytes of the blocks to be     *                  unpadded.     * @return the index into the <i>in</i> buffer indicating where the     *                  padding starts.     * @exception ArrayIndexOutOfBoundsException if offset < 0 || length < 0 ||     *                  (long)offset + length > in.length     * @exception IllegalBlockSizeException if length < blockSize     */    public final int unpad(byte[] in, int offset, int length) {        if (length == 0) return 0;        if (offset < 0 || length < 0 || (long)offset + length > in.length)            throw new ArrayIndexOutOfBoundsException(                "offset < 0 || length < 0 || (long)offset + length > in.length");// this is taken care of in Cipher.updateInternal --RSN//        int size = blockSize;//        if (length < size)//            throw new IllegalBlockSizeException("length < blockSize");//        offset += length - size;//        if (tracing) traceMethod("engineUnpad(<" + in + ">, " + offset + ", " + size + ")");        if (tracing) traceMethod("engineUnpad(<" + in + ">, " + offset + ", " + length + ")");//        int result = engineUnpad(in, offset, size);        int result = engineUnpad(in, offset, length);        if (tracing) traceResult(result);        return result;    }    /**     * Returns the standard name of the padding scheme implemented.     * <p>     * See <a href="../guide/ijce/Algorithms.html#PaddingScheme">     * <cite>International JCE Standard Algorithm Names</cite></a> for a list     * of PaddingScheme algorithm names.     *     * @return the standard name of the padding scheme.     * @deprecated Use getAlgorithm() instead.     */    public final String paddingScheme() { return algorithm; }    /**     * Sets the specified algorithm parameter to the specified value.     * <p>     * This method supplies a general-purpose mechanism through which it is     * possible to set the various parameters of this object. A uniform     * algorithm-specific naming scheme for each parameter is desirable but     * left unspecified at this time.     * <p>     * <strong><a href="../guide/ijce/JCEDifferences.html">This method     * is not supported in JavaSoft's version of JCE.</a></strong>     *     * @param  param    the string identifier of the parameter.     * @param  value    the parameter value.     * @exception NullPointerException if param == null     * @exception NoSuchParameterException if there is no parameter with name     *                  param for this padding scheme implementation.     * @exception InvalidParameterException if the parameter exists but cannot     *                  be set.     * @exception InvalidParameterTypeException if value is the wrong type     *                  for this parameter.     */    public void setParameter(String param, Object value)    throws NoSuchParameterException, InvalidParameterException,           InvalidParameterTypeException {        if (param == null) throw new NullPointerException("param == null");        engineSetParameter(param, value);    }    /**     * Gets the value of the specified algorithm parameter.     * <p>     * This method supplies a general-purpose mechanism through which it is     * possible to get the various parameters of this object. A uniform     * algorithm-specific naming scheme for each parameter is desirable but     * left unspecified at this time.     * <p>     * <strong><a href="../guide/ijce/JCEDifferences.html">This method     * is not supported in JavaSoft's version of JCE.</a></strong>     *     * @param  param    the string name of the parameter.     * @return the object that represents the parameter value.     * @exception NullPointerException if param == null     * @exception NoSuchParameterException if there is no parameter with name     *                  param for this padding scheme implementation.     * @exception InvalidParameterException if the parameter exists but cannot     *                  be read.     */    public Object getParameter(String param)    throws NoSuchParameterException, InvalidParameterException {        if (param == null) throw new NullPointerException("param == null");        return engineGetParameter(param);    }    /**     * Returns a clone of this cipher.     *     * @exception CloneNotSupportedException if the cipher is not cloneable.     */    public Object clone() throws CloneNotSupportedException {        if (this instanceof Cloneable) {            return super.clone();        } else {            throw new CloneNotSupportedException();        }    }    public String toString() {        return "PaddingScheme [" + getAlgorithm() + "]";    }// SPI methods//...........................................................................    /**     * Sets the <code>blockSize</code> variable for this instance.     * <p>     * Subclasses that override this method (to do initialization that     * depends on <code>blockSize</code> being set) should call     * <code>super.engineSetBlockSize(size)</code> first.     *     * @exception IllegalBlockSizeException if size < 1 || !engineIsValidBlockSize(size)     */    protected void engineSetBlockSize(int size) {        if (size < 1 || !engineIsValidBlockSize(size))            throw new IllegalBlockSizeException(getAlgorithm() + ": " +                size + " is not a valid block size");        blockSize = size;    }    /**     * <b>SPI</b>: Pads a single incomplete block.     * <p>     * The padding is written to the same buffer that is used for input     * (<i>in</i>). When this method returns, the padded block should be stored at     * <code>in[offset .. offset+blockSize-1]</code>.     * <p>     * <i>in</i> will be long enough to accomodate the padding. <i>length</i> is     * guaranteed to be in the range 0 .. <code>blockSize</code>-1.     *     * @param  in       the buffer containing the incomplete block.     * @param  offset   the offset into the <i>in</i> buffer of the block.     * @param  length   the number of bytes from the <i>in</i> buffer,     *                  starting at <i>offset</i>, that need to be unpadded.     * @return the number of padding bytes written.     */    protected abstract int enginePad(byte[] in, int offset, int length);    /**     * <b>SPI</b>: Given the specified subarray of bytes that includes     * padding bytes, returns the index indicating where padding starts.     * <p>     * <i>length</i> is guaranteed to be a non-negative multiple of     * <code>blockSize</code>.     *     * @param  in       the buffer containing the bytes.     * @param  offset   the offset into the <i>in</i> buffer of the     *                  first byte to be unpadded.     * @param  length   the total length in bytes of the blocks to be     *                  unpadded.     * @return the index into the <i>in</i> buffer indicating     *                  where the padding starts.     */    protected abstract int engineUnpad(byte[] in, int offset, int length);    /**     * <b>SPI</b>: Returns true if <i>size</i> is a valid block size (in     * bytes) for this scheme.     * <p>     * The default implementation always returns true.     */    protected boolean engineIsValidBlockSize(int size) { return true; }    /**     * <b>SPI</b>: Sets the specified algorithm parameter to the specified     * value.     * <p>     * This method supplies a general-purpose mechanism through which it is     * possible to set the various parameters of this object. A uniform     * algorithm-specific naming scheme for each parameter is desirable but     * left unspecified at this time.     * <p>     * The default implementation always throws a NoSuchParameterException.     * <p>     * <strong><a href="../guide/ijce/JCEDifferences.html">This method     * is not supported in JavaSoft's version of JCE.</a></strong>     *     * @param  param    the string name of the parameter.      * @param  value    the parameter value.     * @exception NoSuchParameterException if there is no parameter with name     *                  param for this padding scheme implementation.     * @exception InvalidParameterException if the parameter exists but cannot     *                  be set.     * @exception InvalidParameterTypeException if value is the wrong type     *                  for this parameter.     */    protected void engineSetParameter(String param, Object value)    throws NoSuchParameterException, InvalidParameterException,           InvalidParameterTypeException {        throw new NoSuchParameterException(getAlgorithm() + ": " + param);    }    /**     * <b>SPI</b>: Gets the value of the specified algorithm parameter.     * <p>     * This method supplies a general-purpose mechanism through which it is     * possible to get the various parameters of this object. A uniform     * algorithm-specific naming scheme for each parameter is desirable but     * left unspecified at this time.     * <p>     * The default implementation always throws a NoSuchParameterException.     * <p>     * <strong><a href="../guide/ijce/JCEDifferences.html">This method     * is not supported in JavaSoft's version of JCE.</a></strong>     *     * @param  param    the string name of the parameter.      * @return the object that represents the parameter value.     * @exception NoSuchParameterException if there is no parameter with name     *                  param for this padding scheme implementation.     * @exception InvalidParameterException if the parameter exists but cannot     *                  be read.     */    protected Object engineGetParameter(String param)    throws NoSuchParameterException, InvalidParameterException {        throw new NoSuchParameterException(getAlgorithm() + ": " + param);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -