Encode the UniqueIdentity in DER form to the stream.

@param out the DerOutputStream to marshal the contents to.
@param tag enocode it under the following tag.
@exception IOException on errors.
767378
public void encode(DerOutputStream out, byte tag) throws IOException {
        byte[] bytes = id.toByteArray();
        int excessBits = bytes.length*8 - id.length();

        out.write(tag);
        out.putLength(bytes.length + 1);

        out.write(excessBits);
        out.write(bytes);
    }
11400
public void encode(DerOutputStream out) throws IOException {
        if (isEmpty()) {
            return;
        }

        DerOutputStream temp = new DerOutputStream();
        for (GeneralName gn : names) {
            gn.encode(temp);
        }
        out.write(DerValue.tag_Sequence, temp);
    }
369189
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.locationType == null) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + " the mandatory parameter locationType is not defined");
        }

        if (this.mlcNumber == null) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + " the mandatory parameter mlc-Number is not defined");
        }

        ((LocationTypeImpl) this.locationType).encodeAll(asnOs);

        ((ISDNAddressStringImpl) this.mlcNumber).encodeAll(asnOs);

        if (this.lcsClientID != null) {
            // lcs-ClientID [0] LCS-ClientID OPTIONAL
            ((LCSClientIDImpl) this.lcsClientID).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_CLIENT_ID);
        }

        if (this.privacyOverride) {
            // privacyOverride [1] NULL OPTIONAL
            try {
                asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_PRIVACY_OVERRIDE);
            } catch (IOException e) {
                throw new MAPException("IOException while encoding " + _PrimitiveName + " parameter privacyOverride", e);
            } catch (AsnException e) {
                throw new MAPException("AsnException while encoding " + _PrimitiveName + " parameter privacyOverride", e);
            }
        }

        if (this.imsi != null) {
            // imsi [2] IMSI OPTIONAL
            ((IMSIImpl) this.imsi).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_IMSI);
        }

        if (this.msisdn != null) {
            // msisdn [3] ISDN-AddressString OPTIONAL,
            ((ISDNAddressStringImpl) this.msisdn).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_MSISDN);
        }

        if (this.lmsi != null) {
            // lmsi [4] LMSI OPTIONAL,
            ((LMSIImpl) this.lmsi).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LMSI);
        }

        if (this.imei != null) {
            // imei [5] IMEI OPTIONAL,
            ((IMEIImpl) this.imei).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_IMEI);
        }

        if (this.lcsPriority != null) {
            // lcs-Priority [6] LCS-Priority OPTIONAL,
            try {
                asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_PRIORITY,
                        new byte[] { (byte) this.lcsPriority.getCode() });
            } catch (IOException e) {
                throw new MAPException("IOException while encoding " + _PrimitiveName + " parameter lcsPriority", e);
            } catch (AsnException e) {
                throw new MAPException("AsnException while encoding " + _PrimitiveName + " parameter lcsPriority", e);
            }
        }

        if (this.lcsQoS != null) {
            // lcs-QoS [7] LCS-QoS OPTIONAL
            ((LCSQoSImpl) this.lcsQoS).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_QOS);
        }

        if (this.extensionContainer != null) {
            // extensionContainer [8] ExtensionContainer OPTIONAL,
            ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_EXTENSION_CONTAINER);
        }

        if (this.supportedGADShapes != null) {
            // supportedGADShapes [9] SupportedGADShapes OPTIONAL
            ((SupportedGADShapesImpl) this.supportedGADShapes).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_SUPPORTED_GAD_SHAPES);
        }

        if (this.lcsReferenceNumber != null) {
            // lcs-ReferenceNumber [10] LCS-ReferenceNumber OPTIONAL,
            try {
                asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_REFERENCE_NUMBER,
                        new byte[] { this.lcsReferenceNumber.byteValue() });
            } catch (IOException e) {
                throw new MAPException("IOException while encoding " + _PrimitiveName + " parameter lcsReferenceNumber", e);
            } catch (AsnException e) {
                throw new MAPException("AsnException while encoding " + _PrimitiveName + " parameter lcsReferenceNumber", e);
            }
        }

        if (this.lcsServiceTypeID != null) {
            // lcsServiceTypeID [11] LCSServiceTypeID OPTIONAL,
            try {
                asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_SERVICE_TYPE_ID, this.lcsServiceTypeID);
            } catch (IOException e) {
                throw new MAPException("IOException while encoding " + _PrimitiveName + " parameter lcsReferenceNumber", e);
            } catch (AsnException e) {
                throw new MAPException("AsnException while encoding " + _PrimitiveName + " parameter lcsReferenceNumber", e);
            }
        }

        if (this.lcsCodeword != null) {
            // lcsCodeword [12] LCSCodeword OPTIONAL,
            ((LCSCodewordImpl) this.lcsCodeword).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_CODEWORD);
        }

        if (this.lcsPrivacyCheck != null) {
            // lcs-PrivacyCheck [13] LCS-PrivacyCheck OPTIONAL,
            ((LCSPrivacyCheckImpl) this.lcsPrivacyCheck).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_PRIVACY_CHECK);
        }

        if (this.areaEventInfo != null) {
            // areaEventInfo [14] AreaEventInfo OPTIONAL,
            ((AreaEventInfoImpl) this.areaEventInfo).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_AREA_EVENT_INFO);
        }

        if (this.hgmlcAddress != null) {
            ((GSNAddressImpl) this.hgmlcAddress).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_H_GMLC_ADDRESS);
        }

        if (this.moLrShortCircuitIndicator) {
            // moLrShortCircuitIndicator
            try {
                asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_mo_lrShortCircuitIndicator);
            } catch (IOException e) {
                throw new MAPException("IOException while encoding " + _PrimitiveName + " parameter moLrShortCircuitIndicator",
                        e);
            } catch (AsnException e) {
                throw new MAPException(
                        "AsnException while encoding " + _PrimitiveName + " parameter moLrShortCircuitIndicator", e);
            }
        }

        if (this.periodicLDRInfo != null) {
            ((PeriodicLDRInfoImpl) this.periodicLDRInfo).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_periodicLDRInfo);
        }

        if (this.reportingPLMNList != null) {
            ((ReportingPLMNListImpl) this.reportingPLMNList).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_reportingPLMNList);
        }
    }
1049970
public void derEncode(OutputStream out) throws IOException {
        if (signedCert == null)
            throw new IOException("Null certificate to encode");
        out.write(signedCert.clone());
    }
261316
public void encode(DerOutputStream out) throws IOException {
        DerOutputStream tagged = new DerOutputStream();
        DerOutputStream tmp = new DerOutputStream();

        if (assigner != null) {
            DerOutputStream tmp2 = new DerOutputStream();
            // XXX - shd check is chars fit into PrintableString
            tmp2.putPrintableString(assigner);
            tagged.write(DerValue.createTag(DerValue.TAG_CONTEXT,
                                 false, TAG_ASSIGNER), tmp2);
        }
        if (party == null)
            throw  new IOException("Cannot have null partyName");

        // XXX - shd check is chars fit into PrintableString
        tmp.putPrintableString(party);
        tagged.write(DerValue.createTag(DerValue.TAG_CONTEXT,
                                 false, TAG_PARTYNAME), tmp);

        out.write(DerValue.tag_Sequence, tagged);
    }
168637
public void encode(DerOutputStream out) throws IOException {
        DerOutputStream seq = new DerOutputStream();

        for (int i = 0, n = size(); i < n; i++) {
            get(i).encode(seq);
        }
        out.write(DerValue.tag_Sequence, seq);
    }
814808
public static void writeTag(OutputStream out, Tag tag, boolean littleEndian) throws IOException {
        writeTag((DataOutput) (littleEndian ? new LittleEndianDataOutputStream(out) : new DataOutputStream(out)), tag);
    }
680578
public void encode(DerOutputStream out) throws IOException {
        DerOutputStream tmp = new DerOutputStream();
        name.encode(tmp);
        int nameType = name.getType();
        if (nameType == GeneralNameInterface.NAME_ANY ||
            nameType == GeneralNameInterface.NAME_X400 ||
            nameType == GeneralNameInterface.NAME_EDI) {

            // implicit, constructed form
            out.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
                              true, (byte)nameType), tmp);
        } else if (nameType == GeneralNameInterface.NAME_DIRECTORY) {
            // explicit, constructed form since underlying tag is CHOICE
            // (see X.680 section 30.6, part c)
            out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
                                         true, (byte)nameType), tmp);
        } else {
            // implicit, primitive form
            out.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
                              false, (byte)nameType), tmp);
        }
    }
96972
void encode(DEROutputStream out) throws IOException
    {
        out.writeEncoded(DERTags.APPLICATION | tag, octets);
    }
411740
public void encode(DerOutputStream out) throws IOException {

        DerOutputStream theChoice = new DerOutputStream();

        if (fullName != null) {
            fullName.encode(theChoice);
            out.writeImplicit(
                DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_FULL_NAME),
                theChoice);

        } else {
            relativeName.encode(theChoice);
            out.writeImplicit(
                DerValue.createTag(DerValue.TAG_CONTEXT, true,
                    TAG_RELATIVE_NAME),
                theChoice);
        }
    }
323720
public void write(Writer out)
         throws IOException
    {
        out.write('<'+tag+attributes()+'>');
        super.write(out);
        out.write("</"+tag+"\n>");
    }
789475
public void encode(AsnOutputStream aos) throws EncodeException {

        try {
            aos.writeTag(Tag.CLASS_APPLICATION, false, _TAG);
            int pos = aos.StartContentDefiniteLength();

            aos.writeOctetString(Tag.CLASS_APPLICATION, _TAG_DTX, this.destTxId);

            if (this.type != null)
                aos.writeInteger(Tag.CLASS_APPLICATION, _TAG_P, this.type.getType());
            else if (this.dp != null)
                this.dp.encode(aos);

            aos.FinalizeContent(pos);

        } catch (IOException e) {
            throw new EncodeException("IOException while encoding TC-Abort: " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new EncodeException("AsnException while encoding TC-Abort: " + e.getMessage(), e);
        }

    }
501596
public void encode(OutputStream out)
    throws CertificateException, IOException {
        if (rawCertInfo == null) {
            DerOutputStream tmp = new DerOutputStream();
            emit(tmp);
            rawCertInfo = tmp.toByteArray();
        }
        out.write(rawCertInfo.clone());
    }
1008872
public void encode(AsnOutputStream aos) throws EncodeException {

        if (this.nationalErrorCode == null && this.privateErrorCode == null)
            throw new EncodeException("Error code: No error code set!");

        try {
            if (this.type == ErrorCodeType.National && this.nationalErrorCode != null) {
                aos.writeInteger(Tag.CLASS_PRIVATE, ErrorCode._TAG_NATIONAL, this.nationalErrorCode);
            } else if (this.type == ErrorCodeType.Private && this.privateErrorCode != null) {
                aos.writeInteger(Tag.CLASS_PRIVATE, ErrorCode._TAG_PRIVATE, this.privateErrorCode);
            } else {
                throw new EncodeException("Error code: No error code set!");
            }

        } catch (IOException e) {
            throw new EncodeException("IOException while encoding ErrorCode: " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new EncodeException("AsnException while encoding ErrorCode: " + e.getMessage(), e);
        }
    }
475030
static void encode(DerOutputStream out, AlgorithmId algid, BitArray key)
        throws IOException {
            DerOutputStream tmp = new DerOutputStream();
            algid.encode(tmp);
            tmp.putUnalignedBitString(key);
            out.write(DerValue.tag_Sequence, tmp);
    }
1343842
public void encodeData(AsnOutputStream asnOs) throws MAPException {

        if (this.ssCode == null)
            throw new MAPException("Error while encoding " + _PrimitiveName + ": ssCode required.");

        if (this.forwardingFeatureList == null)
            throw new MAPException("Error while encoding " + _PrimitiveName + ": forwardingFeatureList required.");

        if (this.forwardingFeatureList.size() < 1 || this.forwardingFeatureList.size() > 32) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + ": Parameter forwardingFeatureList size must be from 1 to 32, found: "
                    + this.forwardingFeatureList.size());
        }

        try {

            ((SSCodeImpl) this.ssCode).encodeAll(asnOs);

            asnOs.writeTag(Tag.CLASS_UNIVERSAL, false, Tag.SEQUENCE);
            int pos = asnOs.StartContentDefiniteLength();
            for (ExtForwFeature featureItem : this.forwardingFeatureList) {
                ((ExtForwFeatureImpl) featureItem).encodeAll(asnOs);
            }
            asnOs.FinalizeContent(pos);

            if (this.extensionContainer != null)
                ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _TAG_extensionContainer);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        }
    }
313215
private static void decodeTag(String stringTag, Map<TagKey, TagValueWithMetadata> tags) {
    String keyWithValue;
    int firstPropertyIndex = stringTag.indexOf(TAG_PROPERTIES_DELIMITER);
    if (firstPropertyIndex != -1) { // Tag with properties.
      keyWithValue = stringTag.substring(0, firstPropertyIndex);
      // TODO(songya): support decoding tag properties.
    } else { // Tag without properties.
      keyWithValue = stringTag;
    }
    List<String> keyValuePair = TAG_KEY_VALUE_SPLITTER.splitToList(keyWithValue);
    checkArgument(keyValuePair.size() == 2, "Malformed tag " + stringTag);
    TagKey key = TagKey.create(keyValuePair.get(0).trim());
    TagValue value = TagValue.create(keyValuePair.get(1).trim());
    TagValueWithMetadata valueWithMetadata =
        TagValueWithMetadata.create(value, METADATA_UNLIMITED_PROPAGATION);
    tags.put(key, valueWithMetadata);
  }