derbitstring.java

来自「《移动Agent技术》一书的所有章节源代码。」· Java 代码 · 共 86 行

JAVA
86
字号
package org.bouncycastle.asn1;import java.io.*;public class DERBitString    extends DERObject{    protected byte[]      data;    protected int         padBits;    protected DERBitString(        byte    data,        int     padBits)    {        this.data = new byte[1];        this.data[0] = data;        this.padBits = padBits;    }    /**     * @param data the octets making up the bit string.     * @param padBits the number of extra bits at the end of the string.     */    public DERBitString(        byte[]  data,        int     padBits)    {        this.data = data;        this.padBits = padBits;    }    public DERBitString(        byte[]  data)    {        this(data, 0);    }    public DERBitString(        DERObject  obj)    {        try        {            ByteArrayOutputStream   bOut = new ByteArrayOutputStream();            DEROutputStream         dOut = new DEROutputStream(bOut);            dOut.writeObject(obj);            dOut.close();            this.data = bOut.toByteArray();            this.padBits = 0;        }        catch (IOException e)        {            throw new IllegalArgumentException("Error processing object : " + e.toString());        }    }    public DERBitString(        DEREncodable  obj)    {        this(obj.getDERObject());    }    public byte[] getBytes()    {        return data;    }    public int getPadBits()    {        return padBits;    }    void encode(        DEROutputStream  out)        throws IOException    {        byte[]  bytes = new byte[getBytes().length + 1];        bytes[0] = (byte)getPadBits();        System.arraycopy(getBytes(), 0, bytes, 1, bytes.length - 1);        out.writeEncoded(BIT_STRING, bytes);    }}

⌨️ 快捷键说明

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