Methods Summary |
---|
public void | closeSequence()Close a sequence.
The decode pull the stack to know the end of the current sequence.
closeSequence(SequenceTag) ;
|
public void | closeSequence(int tag)Close a sequence with the specified tag.
final int end = stackBuf[--stackTop] ;
putLength(end - start) ;
putTag(tag) ;
|
public void | openSequence()Open a sequence.
The encoder push the current position on its stack.
stackBuf[stackTop++] = start ;
|
public void | putAny(byte[] s)Put an ANY value. In fact, this method does not encode anything.
It simply copies the specified bytes into the encoding.
putAny(s, s.length) ;
|
public void | putAny(byte[] s, int byteCount)Put an ANY value. Only the first byteCount are considered.
java.lang.System.arraycopy(s,0,bytes,start-byteCount,byteCount);
start -= byteCount;
// for (int i = byteCount - 1 ; i >= 0 ; i--) {
// bytes[--start] = s[i] ;
// }
|
public void | putInteger(int v)Put an integer.
putInteger(v, IntegerTag) ;
|
public void | putInteger(int v, int tag)Put an integer with the specified tag.
putIntegerValue(v) ;
putTag(tag) ;
|
public void | putInteger(long v)Put an integer expressed as a long.
putInteger(v, IntegerTag) ;
|
public void | putInteger(long v, int tag)Put an integer expressed as a long with the specified tag.
putIntegerValue(v) ;
putTag(tag) ;
|
protected final void | putIntegerValue(int v)Put an integer value and move the current position backward.
final int end = start ;
int mask = 0x7f800000 ;
int byteNeeded = 4 ;
if (v < 0) {
while (((mask & v) == mask) && (byteNeeded > 1)) {
mask = mask >> 8 ;
byteNeeded-- ;
}
}
else {
while (((mask & v) == 0) && (byteNeeded > 1)) {
mask = mask >> 8 ;
byteNeeded-- ;
}
}
for (int i = 0 ; i < byteNeeded ; i++) {
bytes[--start] = (byte)v ;
v = v >> 8 ;
}
putLength(end - start) ;
|
protected final void | putIntegerValue(long v)Put an integer value expressed as a long.
final int end = start ;
long mask = 0x7f80000000000000L ;
int byteNeeded = 8 ;
if (v < 0) {
while (((mask & v) == mask) && (byteNeeded > 1)) {
mask = mask >> 8 ;
byteNeeded-- ;
}
}
else {
while (((mask & v) == 0) && (byteNeeded > 1)) {
mask = mask >> 8 ;
byteNeeded-- ;
}
}
for (int i = 0 ; i < byteNeeded ; i++) {
bytes[--start] = (byte)v ;
v = v >> 8 ;
}
putLength(end - start) ;
|
protected final void | putLength(int length)Put a length and move the current position backward.
if (length < 0) {
throw new IllegalArgumentException() ;
}
else if (length < 128) {
bytes[--start] = (byte)length ;
}
else if (length < 256) {
bytes[--start] = (byte)length ;
bytes[--start] = (byte)0x81 ;
}
else if (length < 65536) {
bytes[--start] = (byte)(length) ;
bytes[--start] = (byte)(length >> 8) ;
bytes[--start] = (byte)0x82 ;
}
else if (length < 16777126) {
bytes[--start] = (byte)(length) ;
bytes[--start] = (byte)(length >> 8) ;
bytes[--start] = (byte)(length >> 16) ;
bytes[--start] = (byte)0x83 ;
}
else {
bytes[--start] = (byte)(length) ;
bytes[--start] = (byte)(length >> 8) ;
bytes[--start] = (byte)(length >> 16) ;
bytes[--start] = (byte)(length >> 24) ;
bytes[--start] = (byte)0x84 ;
}
|
public void | putNull()Put a NULL value.
putNull(NullTag) ;
|
public void | putNull(int tag)Put a NULL value with a specified tag.
putLength(0) ;
putTag(tag) ;
|
public void | putOctetString(byte[] s)Put an octet string.
putOctetString(s, OctetStringTag) ;
|
public void | putOctetString(byte[] s, int tag)Put an octet string with a specified tag.
putStringValue(s) ;
putTag(tag) ;
|
public void | putOid(long[] s, int tag)Put an object identifier with a specified tag.
putOidValue(s) ;
putTag(tag) ;
|
public void | putOid(long[] s)Put an object identifier.
putOid(s, OidTag) ;
|
protected final void | putOidValue(long[] s)Put an oid and move the current position backward.
final int end = start ;
final int slength = s.length;
// bugId 4641746: 0, 1, and 2 are legal values.
if ((slength < 2) || (s[0] > 2) || (s[1] >= 40)) {
throw new IllegalArgumentException() ;
}
for (int i = slength - 1 ; i >= 2 ; i--) {
long c = s[i] ;
if (c < 0) {
throw new IllegalArgumentException() ;
}
else if (c < 128) {
bytes[--start] = (byte)c ;
}
else {
bytes[--start] = (byte)(c & 127) ;
c = c >> 7 ;
while (c != 0) {
bytes[--start] = (byte)(c | 128) ;
c = c >> 7 ;
}
}
}
bytes[--start] = (byte)(s[0] * 40 + s[1]) ;
putLength(end - start) ;
|
protected final void | putStringValue(byte[] s)Put a byte string and move the current position backward.
final int datalen = s.length;
java.lang.System.arraycopy(s,0,bytes,start-datalen,datalen);
start -= datalen;
// for (int i = s.length - 1 ; i >= 0 ; i--) {
// bytes[--start] = s[i] ;
// }
putLength(datalen) ;
|
protected final void | putTag(int tag)Put a tag and move the current position backward.
////////////////////////// PROTECTED ///////////////////////////////
if (tag < 256) {
bytes[--start] = (byte)tag ;
}
else {
while (tag != 0) {
bytes[--start] = (byte)(tag & 127) ;
tag = tag << 7 ;
}
}
|
public int | trim()Trim the encoding data and returns the length of the encoding.
The encoder does backward encoding : so the bytes buffer is
filled from end to start. The encoded data must be shift before
the buffer can be used. This is the purpose of the trim method.
After a call to the trim method, the encoder is reinitialized and putXXX
overwrite any existing encoded data.
final int result = bytes.length - start ;
// for (int i = start ; i < bytes.length ; i++) {
// bytes[i-start] = bytes[i] ;
// }
if (result > 0)
java.lang.System.arraycopy(bytes,start,bytes,0,result);
start = bytes.length ;
stackTop = 0 ;
return result ;
|