private static int doReadLength(ByteBuffer buffer) throws IOException {
		int lengthbyte = buffer.get() & 0xFF;

		if ((lengthbyte & BerConstants.ASN_BIT8) == BerConstants.ASN_BIT8) {
			lengthbyte &= ~BerConstants.ASN_BIT8;
			if (lengthbyte == 0) {
				throw new IOException("Indefinite lengths are not supported");
			}
			if (lengthbyte > 4) {
				throw new IOException("Data length > 4 bytes are not supported");
			}
			int length = 0;
			for (int i = 0; i < lengthbyte; i++) {
				length <<= 8;
				length |= buffer.get() & 0xFF;
			}
			if (length < 0) {
				throw new IOException("SNMP does not support data lengths > 2^31");
			}
			return length;
		} else { // Short asnlength
			return lengthbyte;
		}
	}
private static int doReadLength(ByteBuffer buffer) throws IOException {
		int lengthbyte = buffer.get() & 0xFF;

		if ((lengthbyte & BerConstants.ASN_BIT8) == BerConstants.ASN_BIT8) {
			lengthbyte &= ~BerConstants.ASN_BIT8;
			if (lengthbyte == 0) {
				throw new IOException("Indefinite lengths are not supported");
			}
			if (lengthbyte > 4) {
				throw new IOException("Data length > 4 bytes are not supported");
			}
			int length = 0;
			for (int i = 0; i < lengthbyte; i++) {
				length <<= 8;
				length |= buffer.get() & 0xFF;
			}
			if (length < 0) {
				throw new IOException("SNMP does not support data lengths > 2^31");
			}
			return length;
		} else { 
			return lengthbyte;
		}
	}
private static int doReadLength ( ByteBuffer buffer ) throws IOException { int lengthbyte = buffer . get ( ) & 0xFF ; if ( ( lengthbyte & BerConstants . ASN_BIT8 ) == BerConstants . ASN_BIT8 ) { lengthbyte &= ~ BerConstants . ASN_BIT8 ; if ( lengthbyte == 0 ) { throw new IOException ( "Indefinite lengths are not supported" ) ; } if ( lengthbyte > 4 ) { throw new IOException ( "Data length > 4 bytes are not supported" ) ; } int length = 0 ; for ( int i = 0 ; i < lengthbyte ; i ++ ) { length <<= 8 ; length |= buffer . get ( ) & 0xFF ; } if ( length < 0 ) { throw new IOException ( "SNMP does not support data lengths > 2^31" ) ; } return length ; } else { // Short asnlength return lengthbyte ; } }
checked
checked