org.asnlab.asndt.runtime.conv
Class BitStringConverter
java.lang.Object
org.asnlab.asndt.runtime.conv.AsnConverter
org.asnlab.asndt.runtime.conv.BitStringConverter
- Direct Known Subclasses:
- BitString.BitStringValueConverter
public abstract class BitStringConverter
- extends AsnConverter
The BitStringConverter
can convert
BitString to ASN.1 recognized values and vice versa.
The following is an example customize the BitStringConverter
to convert an array of boolean to and from ASN.1 recognized values.
public class MyBitStringConverter extends BitStringConverter {
public Object createObject(byte[] bytes, byte unusedBits) {
BitString bitString = new BitString(bytes, unusedBits);
int size = bytes.length*8-unusedBits;
boolean[] array = new boolean[size];
for(int i=0; i<size; i++) {
array[i] = bitString.getBit(i);
}
return array;
}
public byte[] getBytes(Object object) {
boolean[] array = (boolean[]) object;
BitString bitString = new BitString(array.length);
for(int i=0; i<size; i++) {
bitString.setBit(i, array[i]);
}
return bitString.bytes;
}
public byte getUnusedBits(Object object) {
boolean[] array = (boolean[]) object;
if(array.length%8==0) {
return 0;
}
else {
return (8-array.length%8);
}
}
}
Method Summary |
abstract java.lang.Object |
createObject(byte[] bytes,
byte unusedBits)
|
byte[] |
getBytes(java.lang.Object object)
Return the bytes of the BIT STRING value |
byte |
getUnusedBits(java.lang.Object object)
Return the unused bits of the BIT STRING value |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
INSTANCE
public static final BitStringConverter INSTANCE
BitStringConverter
public BitStringConverter()
createObject
public abstract java.lang.Object createObject(byte[] bytes,
byte unusedBits)
getBytes
public byte[] getBytes(java.lang.Object object)
- Return the bytes of the BIT STRING value
- Parameters:
object
- The BIT STRING value
- Returns:
- The bytes of the BIT STRING value
getUnusedBits
public byte getUnusedBits(java.lang.Object object)
- Return the unused bits of the BIT STRING value
- Parameters:
object
- The BIT STRING value
- Returns:
- The unused bits of the BIT STRING value
Copyright �2009-2012 ASN Lab