/*
(non-Javadoc)

@see org.restcomm.protocols.ss7.map.primitives.MAPAsnPrimitive#encodeData (org.mobicents.protocols.asn.AsnOutputStream)
189889
public void encodeData(AsnOutputStream asnOs) throws MAPException {

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

        try {

            if (this.basicService != null)
                ((ExtBasicServiceCodeImpl) this.basicService).encodeAll(asnOs);

            if (this.preferentialCugIndicator != null)
                asnOs.writeInteger(this.preferentialCugIndicator);

            ((InterCUGRestrictionsImpl) this.interCugRestrictions).encodeAll(asnOs);

            if (this.extensionContainer != null)
                ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs);
        } catch (IOException e) {
            throw new MAPException("IOException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        }
    }
67540
@SuppressWarnings("AssignmentToForLoopParameter")
    public static String encode(final byte[] data) {
        final int len = data.length;
        final StringBuilder result = new StringBuilder((len / 3 + 1) * 4);
        int bte;
        int index;

        for (int i = 0; i < len; i++) {

            bte = data[i];

            // First 6 bits
            index = bte >> 2 & MASK_6;
            result.append(CHAR_TABLE.charAt(index));

            // Last 2 bits plus 4 from next byte
            index = bte << 4 & MASK_6;

            if (++i < len) {
                bte = data[i];
                index |= bte >> 4 & MASK_4;
            }
            result.append(CHAR_TABLE.charAt(index));

            // 4 + 2 from next
            if (i < len) {
                index = bte << 2 & MASK_6;
                if (++i < len) {
                    bte = data[i];
                    index |= bte >> 6 & MASK_2;
                }
                result.append(CHAR_TABLE.charAt(index));
            } else {
                i++;
                result.append(CHAR_TABLE.charAt(64));
            }
            if (i < len) {
                index = bte & MASK_6;
                result.append(CHAR_TABLE.charAt(index));
            } else {
                result.append(CHAR_TABLE.charAt(64));
            }
        }

        return result.toString();
    }
1260801
public static byte[] encodeBZ(String data) {
    try {
      byte[] bytes = encodeBZ(data.getBytes("UTF-8"));
      //assert(data.equals(decodeBZ(bytes)));
      return bytes;
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }
  }
587962
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.callSessionUnrelated == null) {
            throw new MAPException(
                    "Error while encoding LCSPrivacyCheck the mandatory parameter callSessionUnrelated is not defined");
        }

        try {
            asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_CALL_SESSION_UNRELATED, this.callSessionUnrelated.getAction());
        } catch (IOException e) {
            throw new MAPException("IOException when encoding parameter LCSPrivacyCheck.callSessionUnrelated", e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding parameter LCSPrivacyCheck.callSessionUnrelated", e);
        }

        if (this.callSessionRelated != null) {
            try {
                asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_CALL_SESSION_RELATED, this.callSessionRelated.getAction());
            } catch (IOException e) {
                throw new MAPException("IOException when encoding parameter LCSPrivacyCheck.callSessionRelated", e);
            } catch (AsnException e) {
                throw new MAPException("AsnException when encoding parameter LCSPrivacyCheck.callSessionRelated", e);
            }
        }
    }
269653
public void encodeAll(AsnOutputStream asnOs) throws MAPException {
        this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.STRING_BIT);
    }
953874
public void encodeData(AsnOutputStream asnOs) throws MAPException {

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

        try {

            if (this.basicService != null)
                ((ExtBasicServiceCodeImpl) this.basicService).encodeAll(asnOs);

            ((ExtSSStatusImpl) this.ssStatus).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_ss_Status);

            if (this.forwardedToNumber != null)
                ((ISDNAddressStringImpl) this.forwardedToNumber).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _TAG_forwardedToNumber);

            if (this.forwardedToSubaddress != null)
                ((ISDNSubaddressStringImpl) this.forwardedToSubaddress).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _TAG_forwardedToSubaddress);

            if (this.forwardingOptions != null)
                ((ExtForwOptionsImpl) this.forwardingOptions).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _TAG_forwardingOptions);

            if (this.noReplyConditionTime != null)
                asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_noReplyConditionTime, this.noReplyConditionTime);

            if (this.extensionContainer != null)
                ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _TAG_extensionContainer);

            if (this.longForwardedToNumber != null)
                ((FTNAddressStringImpl) this.longForwardedToNumber).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _TAG_longForwardedToNumber);
        } catch (IOException e) {
            throw new MAPException("IOException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        }
    }
1048581
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.extensionContainer != null) {
            // extensionContainer ExtensionContainer OPTIONAL
            ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs);
        }

        if (this.naEsrk != null) {
            // na-ESRK [0] ISDN-AddressString OPTIONAL
            ((ISDNAddressStringImpl) this.naEsrk).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_NA_ESRK);
        }

        if (this.naEsrd != null) {
            // na-ESRD [1] ISDN-AddressString OPTIONAL ,
            ((ISDNAddressStringImpl) this.naEsrd).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_NA_ESRD);
        }
    }
791616
String encodeBinary(byte[] data){
        if (data == null) return null;
        return Base64.encodeToString(data,Base64.URL_SAFE|Base64.NO_WRAP);
    }
526841
func (e *Erasure) EncodeData(ctx context.Context, data []byte) ([][]byte, error) {
	if len(data) == 0 {
		return make([][]byte, e.dataBlocks+e.parityBlocks), nil
	}
	encoded, err := e.encoder.Split(data)
	if err != nil {
		logger.LogIf(ctx, err)
		return nil, err
	}
	if err = e.encoder.Encode(encoded); err != nil {
		logger.LogIf(ctx, err)
		return nil, err
	}
	return encoded, nil
}
1052068
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.locationEstimateType == null) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + " the mandatory parameter LocationEstimateType is not defined");
        }

        try {
            asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LOCATION_ESTIMATE_TYPE, this.locationEstimateType.getType());
        } catch (IOException e) {
            throw new MAPException("IOException when encoding parameter " + _PrimitiveName + ": ", e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding parameter " + _PrimitiveName + ": ", e);
        }

        if (this.deferredLocationEventType != null) {
            ((DeferredLocationEventTypeImpl) this.deferredLocationEventType).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_DEFERRED_LOCATION_EVET_TYPE);
        }
    }
953268
@Override
    public String encode(final String data, final Optional<RegisteredService> service) {
        try {
            if (service.isPresent()) {
                val registeredService = service.get();
                val publicKey = createRegisteredServicePublicKey(registeredService);
                val result = encodeInternal(data, publicKey, registeredService);
                if (result != null) {
                    return EncodingUtils.encodeBase64(result);
                }
            }
        } catch (final Exception e) {
            LOGGER.warn(e.getMessage(), e);
        }
        return null;
    }
23826
public void encodeData(AsnOutputStream asnOs) throws MAPException {

        try {
            if (this.choice == null)
                throw new MAPException("Error while encoding the " + _PrimitiveName + ": choice is not defined");

            if ((this.choice == PSSubscriberStateChoice.psPDPActiveNotReachableForPaging || this.choice == PSSubscriberStateChoice.psPDPActiveReachableForPaging)
                    && this.pdpContextInfoList == null)
                throw new MAPException(
                        "Error while encoding the "
                                + _PrimitiveName
                                + ": for choice psPDPActiveNotReachableForPaging or psPDPActiveReachableForPaging - pdpContextInfoList must not be null");

            if ((this.choice == PSSubscriberStateChoice.netDetNotReachable) && this.netDetNotReachable == null)
                throw new MAPException("Error while encoding the " + _PrimitiveName
                        + ": for choice netDetNotReachable - netDetNotReachable must not be null");

            switch (this.choice) {
                case notProvidedFromSGSNorMME:
                case psDetached:
                case psAttachedNotReachableForPaging:
                case psAttachedReachableForPaging:
                    asnOs.writeNullData();
                    break;
                case psPDPActiveNotReachableForPaging:
                case psPDPActiveReachableForPaging:

                    if (this.pdpContextInfoList.size() < 1 || this.pdpContextInfoList.size() > 50)
                        throw new MAPException("Error while encoding " + _PrimitiveName
                                + ": pdpContextInfoList size must be from 1 to 50");

                    for (PDPContextInfo cii : this.pdpContextInfoList) {
                        PDPContextInfoImpl ci = (PDPContextInfoImpl) cii;
                        ci.encodeAll(asnOs);
                    }
                    break;
                case netDetNotReachable:
                    asnOs.writeIntegerData(this.netDetNotReachable.getCode());
                    break;
            }

        } catch (IOException e) {
            throw new MAPException("IOException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        }
    }
783173
public static byte[] encodeSourceData(DbFileSources.Data data) {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    LZ4BlockOutputStream compressedOutput = new LZ4BlockOutputStream(byteOutput);
    try {
      data.writeTo(compressedOutput);
      compressedOutput.close();
      return byteOutput.toByteArray();
    } catch (IOException e) {
      throw new IllegalStateException("Fail to serialize and compress source data", e);
    } finally {
      IOUtils.closeQuietly(compressedOutput);
    }
  }
1337638
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.areaDefinition == null) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + " the mandatory parameter[areaDefinition [0] AreaDefinition] is not defined");
        }

        ((AreaDefinitionImpl) this.areaDefinition).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_areaDefinition);

        try {
            if (this.occurrenceInfo != null) {
                asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_OCCURRENCE_INFO, this.occurrenceInfo.getInfo());
            }

            if (this.intervalTime != null) {
                asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_INTERVAL_TIME, this.intervalTime);
            }

        } catch (IOException e) {
            throw new MAPException("IOException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        }
    }
715169
public static String getUrlParamsByMap(Map<String, String> data) throws UnsupportedEncodingException {
        if (data == null || data.isEmpty()) return null;

        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> i : data.entrySet()) {

            sb.append(i.getKey())
                    .append("=")
                    .append(URLEncoder.encode(i.getValue(), Charset.UTF_8))
                    .append("&");

        }
        String str = sb.toString();

        return str.substring(0, str.length() - 1);
    }
591493
public void encode(AsnOutputStream aos) throws EncodeException {

        if (this.getProblem() == null)
            throw new EncodeException("Error encoding Reject: RejectProblem must not be null");

        try {
            // tag
            aos.writeTag(Tag.CLASS_PRIVATE, false, Reject._TAG_REJECT);
            int pos = aos.StartContentDefiniteLength();

            // correlationId
            byte[] buf;
            if (this.correlationId != null) {
                buf = new byte[1];
                buf[0] = (byte) (long) this.correlationId;
            } else {
                buf = new byte[0];
            }
            aos.writeOctetString(Tag.CLASS_PRIVATE, Component._TAG_INVOKE_ID, buf);

            // rejectProblem
            aos.writeInteger(Tag.CLASS_PRIVATE, Reject._TAG_REJECT_PROBLEM, this.rejectProblem.getType());

            // Empty parameter
            aos.writeTag(Tag.CLASS_PRIVATE, false, Parameter._TAG_SEQUENCE);
            aos.writeLength(0);

            aos.FinalizeContent(pos);

        } catch (IOException e) {
            throw new EncodeException("IOException while encoding Reject: " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new EncodeException("AsnException while encoding Reject: " + e.getMessage(), e);
        }
    }
479335
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.externalAddress != null) {
            ((ISDNAddressStringImpl) this.externalAddress).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_EXTERNAL_ADDRESS);
        }

        if (this.extensionContainer != null) {
            ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_EXTENSION_CONTAINER);
        }
    }