codec.asn1
Class AbstractEncoder
java.lang.Object
|
+--java.io.OutputStream
|
+--java.io.FilterOutputStream
|
+--codec.asn1.AbstractEncoder
- All Implemented Interfaces:
- Encoder
- Direct Known Subclasses:
- DEREncoder
- public abstract class AbstractEncoder
- extends FilterOutputStream
- implements Encoder
- Version:
- "$Id: AbstractEncoder.java,v 1.3 2005/03/22 15:55:36 flautens Exp $"
- Author:
- Volker Roth
|
Method Summary |
protected int |
getHeaderLength(int tag,
int len)
This method computes the number of octets needed to encode the identifier
and length octets of the ASN.1 type with the given tag
and contents length. |
protected int |
significantBits(int n)
Counts the number of significant bits in the given integer. |
protected void |
writeBase128(int n)
Writes the given integer to the output in base 128 representation with
bit 7 of all octets except the last one being set to "1". |
protected void |
writeBase256(int n)
Writes the given integer to the output in base 256 with the minimal
number of octets. |
protected void |
writeHeader(int tag,
int cls,
boolean prim,
int len)
This method encodes identifier and length octets. |
void |
writeType(ASN1Type t)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface codec.asn1.Encoder |
writeBitString, writeBoolean, writeCollection, writeInteger, writeNull, writeObjectIdentifier, writeOctetString, writeReal, writeString, writeTaggedType, writeTime, writeTypeIdentifier |
AbstractEncoder
public AbstractEncoder(OutputStream out)
- Creates an encoder that writes its output to the given output stream.
- Parameters:
out - The output stream to which the encoded ASN.1 objects are
written.
writeType
public void writeType(ASN1Type t)
throws ASN1Exception,
IOException
- Specified by:
writeType in interface Encoder
writeHeader
protected void writeHeader(int tag,
int cls,
boolean prim,
int len)
throws IOException
- This method encodes identifier and length octets. The given length can be
negative in which case 0x80 is written to indicate INDEFINITE LENGTH
encoding. Please note that this is appropriate only for a BER encoding or
CER encoding (ITU-T Recommenation X.690). Encoders are responsible for
writing the end of code octets
0x00 0x00 after encoding
the content octets.
- Parameters:
tag - The ASN.1 tagcls - The ASN.1 tag class.prim - true if the encoding is PRIMITIVE and
false if it is CONSTRUCTED.len - The number of content octets or -1 to indicate INDEFINITE
LENGTH encoding.
getHeaderLength
protected int getHeaderLength(int tag,
int len)
- This method computes the number of octets needed to encode the identifier
and length octets of the
ASN.1 type with the given tag
and contents length. The given length can be negative in which case
INDEFINITE LENGTH encoding is assumed.
- Parameters:
tag - The ASN.1 tag.len - The number of contents octets of the ASN.1 type with the
given tag and length.- Returns:
- The number of octets required for encoding the identifier and
length octets.
writeBase128
protected void writeBase128(int n)
throws IOException
- Writes the given integer to the output in base 128 representation with
bit 7 of all octets except the last one being set to "1". The
minimum number of octets necessary is used.
- Parameters:
n - The integer to be written to the output.- Throws:
IOException - Thrown by the underlying output stream.
writeBase256
protected void writeBase256(int n)
throws IOException
- Writes the given integer to the output in base 256 with the minimal
number of octets.
- Parameters:
n - The integer to be written to the output.- Throws:
IOException - Thrown by the underlying output stream.
significantBits
protected int significantBits(int n)
- Counts the number of significant bits in the given integer. There is
always at least one significant bit.
- Parameters:
n - The integer.- Returns:
- The number of significant bits in the given integer.
Copyright © Fraunhofer Gesellschaft. All Rights Reserved.