| Method from com.sun.jmx.snmp.BerDecoder Detail: |
public boolean cannotCloseSequence() {
return (next < stackBuf[stackTop - 1]) ;
}
Return true if the end of the current sequence is not reached.
When this method returns false, closeSequence can (and must) be
invoked. |
public void closeSequence() throws BerException {
if (stackBuf[stackTop - 1] == next) {
stackTop-- ;
}
else {
throw new BerException() ;
}
}
Close a sequence.
The decode pull the stack and verifies that the current position
matches with the calculated end of the sequence. If not it throws
an exception. |
public byte[] fetchAny() throws BerException {
byte[] result = null ;
final int backup = next ;
try {
final int tag = fetchTag() ;
final int contentLength = fetchLength() ;
if (contentLength < 0) throw new BerException() ;
final int tlvLength = next + contentLength - backup ;
if (contentLength > (bytes.length - next))
throw new IndexOutOfBoundsException("Decoded length exceeds buffer");
final byte[] data = new byte[tlvLength] ;
java.lang.System.arraycopy(bytes,backup,data,0,tlvLength);
// for (int i = 0 ; i < tlvLength ; i++) {
// data[i] = bytes[backup + i] ;
// }
next = next + contentLength ;
result = data;
}
catch(IndexOutOfBoundsException e) {
next = backup ;
throw new BerException() ;
}
// catch(Error e) {
// debug("fetchAny: Error decoding BER: " + e);
// throw e;
// }
return result ;
}
Fetch an ANY value. In fact, this method does not decode anything
it simply returns the next TLV as an array of bytes. |
public byte[] fetchAny(int tag) throws BerException {
if (getTag() != tag) {
throw new BerException() ;
}
return fetchAny() ;
}
Fetch an ANY value with a specific tag. |
public int fetchInteger() throws BerException {
return fetchInteger(IntegerTag) ;
}
|
public int fetchInteger(int tag) throws BerException {
int result = 0 ;
final int backup = next ;
try {
if (fetchTag() != tag) {
throw new BerException() ;
}
result = fetchIntegerValue() ;
}
catch(BerException e) {
next = backup ;
throw e ;
}
return result ;
}
Fetch an integer with the specified tag. |
public long fetchIntegerAsLong() throws BerException {
return fetchIntegerAsLong(IntegerTag) ;
}
Fetch an integer and return a long value. |
public long fetchIntegerAsLong(int tag) throws BerException {
long result = 0 ;
final int backup = next ;
try {
if (fetchTag() != tag) {
throw new BerException() ;
}
result = fetchIntegerValueAsLong() ;
}
catch(BerException e) {
next = backup ;
throw e ;
}
return result ;
}
Fetch an integer with the specified tag and return a long value. |
public void fetchNull() throws BerException {
fetchNull(NullTag) ;
}
|
public void fetchNull(int tag) throws BerException {
final int backup = next ;
try {
if (fetchTag() != tag) {
throw new BerException() ;
}
final int length = fetchLength();
if (length != 0) throw new BerException();
}
catch(BerException e) {
next = backup ;
throw e ;
}
}
Fetch a NULL value with a specified tag. |
public byte[] fetchOctetString() throws BerException {
return fetchOctetString(OctetStringTag) ;
}
|
public byte[] fetchOctetString(int tag) throws BerException {
byte[] result = null ;
final int backup = next ;
try {
if (fetchTag() != tag) {
throw new BerException() ;
}
result = fetchStringValue() ;
}
catch(BerException e) {
next = backup ;
throw e ;
}
return result ;
}
Fetch an octet string with a specified tag. |
public long[] fetchOid() throws BerException {
return fetchOid(OidTag) ;
}
Fetch an object identifier. |
public long[] fetchOid(int tag) throws BerException {
long[] result = null ;
final int backup = next ;
try {
if (fetchTag() != tag) {
throw new BerException() ;
}
result = fetchOidValue() ;
}
catch(BerException e) {
next = backup ;
throw e ;
}
return result ;
}
Fetch an object identifier with a specified tag. |
public int getTag() throws BerException {
int result = 0 ;
final int backup = next ;
try {
result = fetchTag() ;
}
finally {
next = backup ;
}
return result ;
}
Get the tag of the data at the current position.
Current position is unchanged. |
public void openSequence() throws BerException {
openSequence(SequenceTag) ;
}
Fetch a sequence header.
The decoder computes the end position of the sequence and push it
on its stack. |
public void openSequence(int tag) throws BerException {
final int backup = next ;
try {
if (fetchTag() != tag) {
throw new BerException() ;
}
final int l = fetchLength() ;
if (l < 0) throw new BerException();
if (l > (bytes.length - next)) throw new BerException();
stackBuf[stackTop++] = next + l ;
}
catch(BerException e) {
next = backup ;
throw e ;
}
}
Fetch a sequence header with a specific tag. |
public void reset() {
next = 0 ;
stackTop = 0 ;
}
|
public String toString() {
final StringBuffer result = new StringBuffer(bytes.length * 2) ;
for (int i = 0 ; i < bytes.length ; i++) {
final int b = (bytes[i] > 0) ? bytes[i] : bytes[i] + 256 ;
if (i == next) {
result.append("(") ;
}
result.append(Character.forDigit(b / 16, 16)) ;
result.append(Character.forDigit(b % 16, 16)) ;
if (i == next) {
result.append(")") ;
}
}
if (bytes.length == next) {
result.append("()") ;
}
return new String(result) ;
}
|