org.apache.asn1.ber.digester.rules
Class PrimitiveIntDecodeRule

java.lang.Object
  extended byorg.apache.asn1.ber.digester.AbstractRule
      extended byorg.apache.asn1.ber.digester.rules.PrimitiveIntDecodeRule
All Implemented Interfaces:
Rule
Direct Known Subclasses:
PrimitiveEnumDecodeRule

public class PrimitiveIntDecodeRule
extends AbstractRule

A rule to Decode a BER encoded ASN.1 INTEGER into a Java primitive int.

The bytes to form the integer are extracted from the BER value which may arrive in multiple chunks. The individual bytes are temporarily stored within a 4 byte array while incrementing a counter to track the capture. Once gathered the bytes are decoded into a int in the finish

As a side effect once the decode is complete, the primitive value is pushed onto the primitive int stack to be utilized by other rules later. If there is a loss of precision where the ASN.1 INTEGER is larger or smaller than the maximum or minimum value of a Java primitive integer an exception is thrown.

Version:
$Rev: 157644 $
Author:
Apache Directory Project

Field Summary
private  int length
          the number of bytes we must read
private  int pos
          the current 8 bit position to fill in the integer
private  TagEnum tag
          the tag this rule accepts
private  byte[] value
          the bytes used to form the Java primitive integer
 
Fields inherited from class org.apache.asn1.ber.digester.AbstractRule
 
Constructor Summary
PrimitiveIntDecodeRule()
          Creates a default primitive integer decoding rule that only accepts tags of UniversalTag.INTEGER.
PrimitiveIntDecodeRule(TagEnum tag)
          Creates a default primitive integer decoding rule that only accepts tags of UniversalTag.INTEGER.
 
Method Summary
(package private)  boolean equals(byte bite, int ii)
          Used for testing to check and see if a value of the byte buffer has been set after a value event.
 void finish()
          Called when the tlv has been completely consumed.
 void length(int length)
          Called when the length of a TLV is encountered.
 void tag(int id, boolean isPrimitive, TypeClass typeClass)
          Called when the tag of the matched TLV is encountered.
 void value(java.nio.ByteBuffer buf)
          Called when a peice of the value is available.
 
Methods inherited from class org.apache.asn1.ber.digester.AbstractRule
getDigester, setDigester
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

value

private final byte[] value
the bytes used to form the Java primitive integer


pos

private int pos
the current 8 bit position to fill in the integer


length

private int length
the number of bytes we must read


tag

private final TagEnum tag
the tag this rule accepts

Constructor Detail

PrimitiveIntDecodeRule

public PrimitiveIntDecodeRule()
Creates a default primitive integer decoding rule that only accepts tags of UniversalTag.INTEGER.


PrimitiveIntDecodeRule

public PrimitiveIntDecodeRule(TagEnum tag)
Creates a default primitive integer decoding rule that only accepts tags of UniversalTag.INTEGER.

Method Detail

tag

public void tag(int id,
                boolean isPrimitive,
                TypeClass typeClass)
Description copied from interface: Rule
Called when the tag of the matched TLV is encountered.

Specified by:
tag in interface Rule
Overrides:
tag in class AbstractRule

length

public void length(int length)
Description copied from interface: Rule
Called when the length of a TLV is encountered.

Specified by:
length in interface Rule
Overrides:
length in class AbstractRule

value

public void value(java.nio.ByteBuffer buf)
Description copied from interface: Rule
Called when a peice of the value is available.

Specified by:
value in interface Rule
Overrides:
value in class AbstractRule

finish

public void finish()
Description copied from interface: Rule
Called when the tlv has been completely consumed.

Specified by:
finish in interface Rule
Overrides:
finish in class AbstractRule

equals

boolean equals(byte bite,
               int ii)
Used for testing to check and see if a value of the byte buffer has been set after a value event.

Parameters:
bite - the byte value to check
ii - the index to check the byte for in the values array
Returns:
true if the byte value matches the byte value in the array


Copyright © 2004-2006 . All Rights Reserved.