public int readLength ( ) throws IOException { int length = 0 ; byte b = ( byte ) this . read ( ) ; // This is short form. The short form can be used if the number of // octets in the Value part is less than or // equal to 127, and can be used whether the Value part is primitive or // constructed. This form is identified by // encoding bit 8 as zero, with the length count in bits 7 to 1 (as // usual, with bit 7 the most significant bit // of the length). if ( ( b & 0x80 ) == 0 ) { return b ; } // This is indefinite form. The indefinite form of length can only be // used (but does not have to be) if the V // part is constructed, that // is to say, consists of a series of TLVs. In the indefinite form of // length the first bit of the first octet is // set to 1, as for the long form, but the value N is set to zero. b = ( byte ) ( b & 0x7F ) ; if ( b == 0 ) { return Tag . Indefinite_Length ; } // If bit 8 of the first length octet is set to 1, then we have the long // form of length. In long form, the first // octet encodes in its remaining seven bits a value N which is the // length of a series of octets that themselves // encode the length of the Value part. byte temp ; for ( int i = 0 ; i < b ; i ++ ) { temp = ( byte ) this . read ( ) ; length = ( length << 8 ) | ( 0x00FF & temp ) ; } return length ; }
Reads and returns the length field . In case of indefinite length returns Tag . Indefinite_Length value