Class BERElement

    • Constructor Detail

      • BERElement

        public BERElement()
    • Method Detail

      • getElement

        public static BERElement getElement​(BERTagDecoder decoder,
                                            java.io.InputStream stream,
                                            int[] bytes_read)
                                     throws java.io.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:
        java.io.IOException - failed to decode an element.
      • readLengthOctets

        public static int readLengthOctets​(java.io.InputStream stream,
                                           int[] bytes_read)
                                    throws java.io.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:
        java.io.IOException - failed to read octets
      • sendDefiniteLength

        public static void sendDefiniteLength​(java.io.OutputStream stream,
                                              int num_content_octets)
                                       throws java.io.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:
        java.io.IOException - failed to read octets
      • readUnsignedBinary

        protected int readUnsignedBinary​(java.io.InputStream stream,
                                         int[] bytes_read,
                                         int length)
                                  throws java.io.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:
        java.io.IOException - failed to read octets
      • readTwosComplement

        protected int readTwosComplement​(java.io.InputStream stream,
                                         int[] bytes_read,
                                         int length)
                                  throws java.io.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:
        java.io.IOException - failed to read octets
      • byteToHexString

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

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

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

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