private int getLength() throws IOException {

        int i = in.read();
        if (i == -1)
            throw new IOException("Invalid DER: length missing"); //$NON-NLS-1$

        // A single byte short length
        if ((i & ~0x7F) == 0)
            return i;

        int num = i & 0x7F;

        // We can't handle length longer than 4 bytes
        if ( i >= 0xFF || num > 4) 
            throw new IOException("Invalid DER: length field too big (" //$NON-NLS-1$
                    + i + ")"); //$NON-NLS-1$

        byte[] bytes = new byte[num];                   
        int n = in.read(bytes);
        if (n < num)
            throw new IOException("Invalid DER: length too short"); //$NON-NLS-1$

        return new BigInteger(1, bytes).intValue();
    }
private int getLength ( ) throws IOException { int i = in . read ( ) ; if ( i == - 1 ) throw new IOException ( "Invalid DER: length missing" ) ; if ( ( i & ~ 0x7F ) == 0 ) return i ; int num = i & 0x7F ; if ( i >= 0xFF || num > 4 ) throw new IOException ( "Invalid DER: length field too big (" + i + ")" ) ; byte [ ] bytes = new byte [ num ] ; int n = in . read ( bytes ) ; if ( n < num ) throw new IOException ( "Invalid DER: length too short" ) ; return new BigInteger ( 1 , bytes ) . intValue ( ) ; }
Decode the length of the field. Can only support length
encoding up to 4 octets.

<p/>In BER/DER encoding, length can be encoded in 2 forms,
<ul>
<li>Short form. One octet. Bit 8 has value "0" and bits 7-1
give the length.
<li>Long form. Two to 127 octets (only 4 is supported here).
Bit 8 of first octet has value "1" and bits 7-1 give the
number of additional length octets. Second and following
octets give the length, base 256, most significant digit first.
</ul>
@return The length as integer
@throws IOException