Class BERElement

java.lang.Object
netscape.ldap.ber.stream.BERElement
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BERAny, BERBitString, BERBoolean, BERCharacterString, BERChoice, BERConstruct, BERIntegral, BERNull, BERObjectId, BEROctetString, BERReal, BERTag, BERUTCTime

public abstract class BERElement extends Object implements Serializable
This class is for the tagged object type. A nested tag is allowed. A tagged element contains another BER element.
Version:
1.0 seeAlso CCITT X.209
See Also:
  • Field Details

  • Constructor Details

    • BERElement

      public BERElement()
  • Method Details

    • getElement

      public static BERElement getElement(BERTagDecoder decoder, InputStream stream, int[] bytes_read) throws IOException
      Gets a ber element from the input stream.
      Parameters:
      decoder - decoder for application specific BER
      stream - source of ber encoding
      bytes_read - array of 1 int; value incremented by number of bytes read from stream
      Throws:
      IOException - failed to decode an element.
    • readLengthOctets

      public static int readLengthOctets(InputStream stream, int[] bytes_read) throws IOException
      Reads and decodes a length byte and then that many octets from the input stream.
      Parameters:
      stream - input stream from which to read
      bytes_read - array of 1 int; value incremented by number of bytes read from stream
      Returns:
      length of contents or -1 if indefinite length.
      Throws:
      IOException - failed to read octets
    • sendDefiniteLength

      public static void sendDefiniteLength(OutputStream stream, int num_content_octets) throws IOException
      Writes length octets (definite length only) to stream. Uses shortform whenever possible.
      Parameters:
      stream - output stream to write to
      num_content_octets - value to be encode into length octets
      Throws:
      IOException - failed to read octets
    • readUnsignedBinary

      protected int readUnsignedBinary(InputStream stream, int[] bytes_read, int length) throws IOException
      Reads a number of bytes from an input stream and form an integer..
      Parameters:
      stream - source of data
      bytes_read - number of bytes read
      length - number of bytes to be read (1 to 4)
      Returns:
      the value of the data as two's complement.
      Throws:
      IOException - failed to read octets
    • readTwosComplement

      protected int readTwosComplement(InputStream stream, int[] bytes_read, int length) throws IOException
      Reads the two's complement representation of an integer from an input stream.
      Parameters:
      stream - source of data
      bytes_read - number of bytes read
      length - number of bytes to be read
      Returns:
      the integer value as two's complement.
      Throws:
      IOException - failed to read octets
    • byteToHexString

      public String byteToHexString(byte value)
      Converts byte to hex string.
      Parameters:
      value - byte value
      Returns:
      string representation of Hex String
    • write

      public abstract void write(OutputStream stream) throws IOException
      Sends the BER encoding directly to a stream.
      Parameters:
      stream - output stream
      Throws:
      IOException
    • getType

      public abstract int getType()
      Gets the element type.
      Returns:
      element type.
    • toString

      public abstract String toString()
      Gets the string representation.
      Overrides:
      toString in class Object
      Returns:
      string representation of an element.