⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smpppacket.java

📁 SMPP(点到点短消息协议)的java实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    public Address getDestination() {        return destination;    }    /**     * Set the 'priority' flag.     *      * @throws ie.omk.smpp.message.InvalidParameterValueException     *             If <code>p</code> is not a valid value for the priority     *             flag.     */    public void setPriority(int p) throws InvalidParameterValueException {        if (version.validatePriorityFlag(p)) {            this.priority = p;        } else {            throw new InvalidParameterValueException("Bad priority flag value",                    p);        }    }    /**     * Set 'registered delivery' flag.     *      * @deprecated     */    public void setRegistered(boolean b) {        this.registered = b ? 1 : 0;    }    /**     * Set 'registered delivery' flag.     *      * @throws ie.omk.smpp.message.InvalidParameterValueException     *             If <code>r</code> is not a valid value for the registered     *             delivery flag.     */    public void setRegistered(int r) throws InvalidParameterValueException {        if (version.validateRegisteredDelivery(r)) {            this.registered = r;        } else {            throw new InvalidParameterValueException(                    "Bad registered delivery flag value", r);        }    }    /**     * Set 'replace if present'.     *      * @deprecated     */    public void setReplaceIfPresent(boolean b) {        this.replaceIfPresent = b ? 1 : 0;    }    /**     * Set 'replace if present' flag.     *      * @throws ie.omk.smpp.message.InvalidParameterValueException     *             If <code>rip</code> is not a valid value for the replace if     *             present flag.     */    public void setReplaceIfPresent(int rip)            throws InvalidParameterValueException {        if (version.validateReplaceIfPresent(rip)) {            this.replaceIfPresent = rip;        } else {            throw new InvalidParameterValueException(                    "Bad replace if present flag value", rip);        }    }    /**     * Set the esm class of the message.     *      * @see ie.omk.smpp.util.GSMConstants     * @throws ie.omk.smpp.message.InvalidParameterValueException     *             If the value passed is not a valid ESM class.     */    public void setEsmClass(int c) throws InvalidParameterValueException {        if (version.validateEsmClass(c)) {            this.esmClass = c;        } else {            throw new InvalidParameterValueException("Bad ESM class", c);        }    }    /**     * Set the protocol Id in the message flags.     *      * @see ie.omk.smpp.util.GSMConstants     * @deprecated ie.omk.smpp.message.SMPPPacket#setProtocolID     */    public void setProtocolId(int id) {        this.protocolID = id;    }    /**     * Set the GSM protocol ID.     *      * @see ie.omk.smpp.util.GSMConstants     * @throws ie.omk.smpp.message.InvalidParameterValueException     *             If the protocol ID supplied is invalid.     */    public void setProtocolID(int id) throws InvalidParameterValueException {        if (version.validateProtocolID(id)) {            this.protocolID = id;        } else {            throw new InvalidParameterValueException("Bad Protocol ID", id);        }    }    /**     * Set the GSM data coding of the message. This will also set the internal     * encoding type of the message to match the DCS value. It will <b>not </b>     * set the encoding type if the DCS is <code>0</code> as this code is     * reserved to represent the default SMSC encoding type, which is dependent     * on the SMSC implementation.     *      * @see ie.omk.smpp.util.GSMConstants     * @throws ie.omk.smpp.message.InvalidParameterValueException     *             If the data coding supplied is invalid.     */    public void setDataCoding(int dc) throws InvalidParameterValueException {        if (version.validateDataCoding(dc)) {            this.dataCoding = dc;            if (dc > 0) {                this.encoding = EncodingFactory.getInstance().getEncoding(dc);            }        } else {            throw new InvalidParameterValueException("Bad data coding", dc);        }    }    /**     * Set the default message id in the message flags.     */    public void setDefaultMsg(int id) throws InvalidParameterValueException {        if (version.validateDefaultMsg(id)) {            this.defaultMsg = id;        } else {            throw new InvalidParameterValueException(                    "Default message ID out of range", id);        }    }    /**     * Check is the message registered.     *      * @deprecated     */    public boolean isRegistered() {        return this.registered > 0;    }    /**     * Get the 'registered' flag for the message.     */    public int getRegistered() {        return registered;    }    /**     * Check is the message submitted as priority.     *      * @deprecated     */    public boolean isPriority() {        return (this.priority == 0) ? false : true;    }    /**     * Get the priority flag for the message.     */    public int getPriority() {        return priority;    }    /**     * Check if the message should be replaced if it is already present.     *      * @deprecated     */    public boolean isReplaceIfPresent() {        return this.replaceIfPresent > 0;    }    /**     * Get the replace if present flag for the message.     */    public int getReplaceIfPresent() {        return replaceIfPresent;    }    /**     * Get the ESM class of the message.     */    public int getEsmClass() {        return this.esmClass;    }    /**     * Get the GSM protocol Id of the message.     *      * @deprecated getProtocolID     */    public int getProtocolId() {        return this.protocolID;    }    /**     * Get the GSM protocol ID of the message.     */    public int getProtocolID() {        return this.protocolID;    }    /**     * Get the data coding.     */    public int getDataCoding() {        return this.dataCoding;    }    /**     * Get the default message to use.     *      * @deprecated     */    public int getDefaultMsgId() {        return this.defaultMsg;    }    /**     * Get the default message to use.     */    public int getDefaultMsg() {        return this.defaultMsg;    }    /**     * Set the text of the message. This method sets the message text encoded     * using the current alphabet for this message. The default alphabet to use     * is obtained using     * {@link ie.omk.smpp.util.EncodingFactory#getDefaultAlphabet}. If, at some     * point, the encoding for the message has been altered to be one other than     * a sub-class of {@link ie.omk.smpp.util.AlphabetEncoding} then calls to     * this method will reset the encoding back to the default. The maximum     * length of the message is determined by the SMPP version in use. Calling     * this method affects the data_coding value.     *      * @param text     *            The short message text.     * @throws ie.omk.smpp.message.InvalidParameterValueException     *             If the message text is too long.     * @see ie.omk.smpp.util.EncodingFactory     * @see ie.omk.smpp.util.DefaultAlphabetEncoding     */    public void setMessageText(String text)            throws InvalidParameterValueException {        if (!(encoding instanceof AlphabetEncoding)) {            encoding = EncodingFactory.getInstance().getDefaultAlphabet();        }        AlphabetEncoding a = (AlphabetEncoding) encoding;        setMessage(a.encodeString(text), a);    }    /**     * Set the text of the message. This method sets the message text encoded     * using the SMS alphabet <code>alphabet</code>. The     * AlphabetEncoding.getDataCoding value will be used to set the data_coding     * field.     *      * @param text     *            The short message text.     * @param alphabet     *            The SMS alphabet to use.     * @throws ie.omk.smpp.message.InvalidParameterValueException     *             If the message text is too long.     * @see ie.omk.smpp.util.AlphabetEncoding     * @see ie.omk.smpp.util.AlphabetEncoding#getDataCoding     * @see ie.omk.smpp.util.DefaultAlphabetEncoding     */    public void setMessageText(String text, AlphabetEncoding alphabet)            throws InvalidParameterValueException {        if (alphabet == null) {            throw new NullPointerException("Alphabet cannot be null");        }        this.setMessage(alphabet.encodeString(text), alphabet);    }    /**     * Set the message data. The data will be copied from the supplied byte     * array into an internal one.     *      * @param message     *            The byte array to take message data from.     * @throws ie.omk.smpp.message.InvalidParameterValueException     *             If the message data is too long.     */    public void setMessage(byte[] message)            throws InvalidParameterValueException {        this.setMessage(message, 0, message.length, null);    }    /**     * Set the message data. The data will be copied from the supplied byte     * array into an internal one.     *      * @param message     *            The byte array to take message data from.     * @throws ie.omk.smpp.message.InvalidParameterValueException     *             If the message data is too long.     */    public void setMessage(byte[] message, MessageEncoding encoding)            throws InvalidParameterValueException {        this.setMessage(message, 0, message.length, encoding);    }    /**     * Set the message data. The data will be copied from the supplied byte     * array into an internal one. If <i>encoding </i> is not null, the     * data_coding field will be set using the value returned by     * MessageEncoding.getDataCoding.     *      * @param message     *            The byte array to take message data from.     * @param start     *            The index the message data begins at.     * @param len     *            The length of the message data.     * @param encoding     *            The encoding object representing the type of data in the     *            message. If null, uses ie.omk.smpp.util.BinaryEncoding.     * @throws ie.omk.smpp.message.InvalidParameterValueException     *             If the message data is too long.     * @throws java.lang.ArrayIndexOutOfBoundsException     *             if start or len is less than zero or if the byte array length     *             is less than <code>start +     * len</code>.     */    public void setMessage(byte[] message, int start, int len,            MessageEncoding encoding) throws InvalidParameterValueException {        int dcs = -1;        // encoding should never be null, but for resilience, we check it here        // and default back to binary encoding if none is found.        if (encoding == null) {            encoding = new BinaryEncoding();        }        dcs = encoding.getDataCoding();        if (message != null) {            if ((start < 0) || (len < 0) || message.length < (start + len)) {                throw new ArrayIndexOutOfBoundsException(                        "Not enough bytes in array");            }            int encodedLength = len;            int encodingLength = encoding.getEncodingLength();            if (encodingLength != 8) {                encodedLength = (len * encodingLength) / 8;            }            if (encodedLength > version.getMaxLength(SMPPVersion.MESSAGE_PAYLOAD)) {                throw new InvalidParameterValueException("Message is too long",                        message);            }            this.message = new byte[len];            System.arraycopy(message, start, this.message, 0, len);            this.dataCoding = dcs;        } else {            this.message = null;        }    }    /**     * Get the message data. This method returns a <i>copy </i> of the binary     * message data.     *      * @return A byte array copy of the message data. May be null.     */    public byte[] getMessage() {        byte[] b = null;        if (this.message != null) {            b = new byte[this.message.length];            System.arraycopy(this.message, 0, b, 0, b.length);        }        return b;    }    /**     * Get the text of the message. The message will be decoded according to the     * current encoding of the message (that is, according to it's DCS value).     * If the current encoding is not some form of text encoding (that is, the     * DCS indicates a binary encoding), <code>null</code> will be returned.     *      * @return The text of the message, or <code>null</code> if the message is     *         not text.     * @see #getMessageText(ie.omk.smpp.util.AlphabetEncoding)     * @see #setMessageText(java.lang.String, ie.omk.smpp.util.AlphabetEncoding)     */    public String getMessageText() {        if (encoding instanceof AlphabetEncoding) {            return ((AlphabetEncoding) encoding).decodeString(this.message);        } else {            return null;        }    }    /**     * Get the text of the message. Never returns null.     *      * @param enc     *            The alphabet to use to decode the message bytes.     * @return The text of the message. Never returns null.     * @see ie.omk.smpp.util.AlphabetEncoding     */    public String getMessageText(AlphabetEncoding enc) {        return enc.decodeString(this.message);    }    /**     * Get the number of octets in the message payload.     *      * @return The number of octets (bytes) in the message payload.     */    public int getMessageLen() {        return (message == null) ? 0 : message.length;    }    /**     * Set the service type.     *      * @param type     *            The service type.     * @throws ie.omk.smpp.message.InvalidParameterValueException     *             if the service type is too long.     */    public void setServiceType(String type)            throws InvalidParameterValueException {        if (type != null) {            if (version.validateServiceType(type)) {                this.serviceType = type;            } else {                throw new InvalidParameterValueException("Bad service type",                        type);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -