|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jasn.BaseBerEncoder
org.jasn.BerIndefiniteEncoder
An ASN.1 encoder that uses the Basic Encoding Rules (BER) to encode ASN.1 values.
| Field Summary |
| Fields inherited from class org.jasn.BaseBerEncoder |
implicitTag |
| Constructor Summary | |
BerIndefiniteEncoder(OutputStream out)
Creates a new encoder that will write to the given output stream using the BER encoding. |
|
| Method Summary | |
int |
encodeExplicit(int tag)
Starts the encoding of an explicitly tagged value. |
int |
encodeSequence()
Starts the encoding of an ASN.1 SEQUENCE. |
int |
encodeSet()
Starts the encoding of an ASN.1 SET. |
void |
endOf(int id)
Terminates the encoding of the constructed value identified by id. |
void |
reset()
Resets the state of this encoder. |
protected void |
writeByte(int b)
Writes the specified byte to this output stream. |
protected void |
writeBytes(byte[] b,
int offs,
int len)
Writes len bytes from the specified byte array starting at
offset off to this output stream. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public BerIndefiniteEncoder(OutputStream out)
out - the underlying output stream the encoded data are encoded to.| Method Detail |
public int encodeSequence()
throws IOException
Asn1Encoderdecode methods. Finally, the endOf method must be invoked to terminate the decoding of the SEQUENCE.
The returned int value must be passed to the endOf method
that then checks if the current nesting and the passed int do match.
The code samples below show the decoding of two nested sequences. The
corresponding ASN.1 definition is:
SEQUENCE {
s IA5String,
a SEQUENCE {
i INTEGER
}
}
int id1 = enc.encodeSequence();
enc.decodeIA5String("Organization");
int id2 = enc.encodeSequence();
enc.encodeInteger(124);
enc.endOf(id2);
enc.endOf(id1);
encodeSequence in interface Asn1EncoderencodeSequence in class BaseBerEncoderIOException
public void endOf(int id)
throws IOException
Asn1Encoderid.
endOf in interface Asn1EncoderendOf in class BaseBerEncoderIOException
public int encodeSet()
throws IOException
Asn1Encoderencode methods. Finally, the endOf method
must be invoked to terminate the encoding of the SET.
The returned int value must be passed to the endOf method
that then checks if the current nesting and the passed int do match.
The code samples below show the decoding of two nested sequences. The
corresponding ASN.1 definition is:
SET {
s IA5String,
a SET {
i INTEGER
}
}
int id1 = enc.encodeSet();
enc.decodeIA5String("Organization");
int id2 = enc.encodeSet();
enc.encodeInteger(124);
enc.endOf(id2);
enc.endOf(id1);
encodeSet in interface Asn1EncoderencodeSet in class BaseBerEncoderIOException
public int encodeExplicit(int tag)
throws IOException
encodeExplicit in interface Asn1EncoderencodeExplicit in class BaseBerEncodertag - the tag used to explicitly tagged the next encoded value.
IOException
protected void writeByte(int b)
throws IOException
write is that one byte is written to the output stream. The
byte to be written is the eight low-order bits of the argument
b. The 24 high-order bits of b are ignored.
writeByte in class BaseBerEncoderb - the byte.
IOException - if an I/O error occurs. In particular, an
IOException may be thrown if the output stream has been
closed.
protected void writeBytes(byte[] b,
int offs,
int len)
throws IOException
len bytes from the specified byte array starting at
offset off to this output stream. The general contract for
write(b, off, len) is that some of the bytes in the array
b are written to the output stream in order; element
b[off] is the first byte written and
b[off+len-1] is the last byte written by this operation.
The write method of OutputStream calls the
write method of one argument on each of the bytes to be written out.
Subclasses are encouraged to override this method and provide a more
efficient implementation.
If b is null, a NullPointerException
is thrown.
If off is negative, or len is negative, or
off+len is greater than the length of the array
b, then an IndexOutOfBoundsException is thrown.
writeBytes in class BaseBerEncoderb - the data.offs - the start offset in the data.len - the number of bytes to write.
IOException - if an I/O error occurs. In particular, an
IOException is thrown if the output stream is closed.public void reset()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||