?? smpppacket.java
字號:
flags.priority = (this.priority == 0) ? false : true; flags.registered = this.registered; flags.replace_if_present = this.replaceIfPresent; flags.esm_class = this.esmClass; flags.protocol = this.protocolID; flags.data_coding = this.dataCoding; flags.default_msg = this.defaultMsg; return (flags); } /** Check is the message registered. * @see ie.omk.smpp.message.MsgFlags */ public boolean isRegistered() { return (this.registered); } /** Check is the message submitted as priority. * @see ie.omk.smpp.message.MsgFlags */ public boolean isPriority() { return ((this.priority == 0) ? false : true); } /** Check if the message should be replaced if it is already present. * @see ie.omk.smpp.message.MsgFlags */ public boolean isReplaceIfPresent() { return (this.replaceIfPresent); } /** Get the ESM class of the message. * @see ie.omk.smpp.message.MsgFlags */ public int getEsmClass() { return (this.esmClass); } /** Get the GSM protocol Id of the message. * @see ie.omk.smpp.message.MsgFlags * @deprecated getProtocolID */ public int getProtocolId() { return (this.protocolID); } /** Get the GSM protocol ID of the message. * @see ie.omk.smpp.message.MsgFlags */ public int getProtocolID() { return (this.protocolID); } /** Get the data coding. * @see ie.omk.smpp.message.MsgFlags */ public int getDataCoding() { return (this.dataCoding); } /** Get the default message to use. * @see ie.omk.smpp.message.MsgFlags */ public int getDefaultMsgId() { return (this.defaultMsg); } /** Set the text of the message (max 160 characters). * This method sets the message text encoded using the default alphabet (as * returned by AlphabetFactory.getDefaultAlphabet). The maximum length of * the string is 160 octets. Calling this method sets the data_coding value * using AlphabetEncoding.getDataCoding. * @param text The short message text. * @exception ie.omk.smpp.StringTooLongException if the message is too * long. * @see ie.omk.smpp.util.AlphabetEncoding * @see ie.omk.smpp.util.AlphabetEncoding#getDataCoding * @see ie.omk.smpp.util.AlphabetFactory * @see ie.omk.smpp.util.DefaultAlphabetEncoding */ public void setMessageText(String text) throws ie.omk.smpp.SMPPException { this.setMessageText(text, this.alphabet); } /** Set the text of the message (max 160 characters). * This method sets the message text encoded using the SMS alphabet * <i>alphabet</i>. 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. * @exception ie.omk.smpp.StringTooLongException if the message 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 ie.omk.smpp.SMPPException { if(text == null) { this.message = null; return; } byte[] bytes = alphabet.encodeString(text); this.setMessage(bytes, alphabet); } /** Set the message data (max 140 octets). * Maximum data length is 140 octets. The data will be copied from the * supplied byte array into a newly created internal one. * @param message The byte array to take message data from. * @exception ie.omk.smpp.StringTooLongException if the message is too long * (XXX this will probably change to a better exception). */ public void setMessage(byte[] message) throws ie.omk.smpp.SMPPException { this.setMessage(message, 0, message.length, null); } /** Set the message data (max 140 octets). * Maximum data length is 140 octets. The data will be copied from the * supplied byte array into a newly created internal one. * @param message The byte array to take message data from. * @exception ie.omk.smpp.StringTooLongException if the message is too long * (XXX this will probably change to a better exception). */ public void setMessage(byte[] message, MessageEncoding encoding) throws ie.omk.smpp.SMPPException { this.setMessage(message, 0, message.length, encoding); } /** Set the message data (max 140 octets). * Maximum data length is 140 octets. The data will be copied from the * supplied byte array into a newly created 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. * @exception ie.omk.smpp.StringTooLongException if the message is too long * (XXX this will probably change to a better exception). */ public void setMessage(byte[] message, int start, int len, MessageEncoding encoding) throws ie.omk.smpp.SMPPException { int maxLen = 0; int dcs = -1; if (encoding == null) { // use unspecified (ie binary) encoding type.. maxLen = new BinaryEncoding().getMaxLength(); } else { maxLen = encoding.getMaxLength(); dcs = encoding.getDataCoding(); } if (message != null) { if ((start < 0) || (len < 0) || message.length < (start + len)) throw new ArrayIndexOutOfBoundsException(); if (len > maxLen) { Debug.warn(this, "setMessage", "Message data too long"); throw new StringTooLongException(maxLen); } this.message = new byte[len]; System.arraycopy(message, start, this.message, 0, len); if (dcs != -1) this.setDataCoding(encoding.getDataCoding()); } 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 data_coding field. If the * API has no registered encoding for a data_coding value, the default * alphabet (as returned by AlphabetFactory.getDefaultAlphabet) will be * used. * @see ie.omk.smpp.util.AlphabetFactory#getDefaultAlphabet */ public String getMessageText() { AlphabetEncoding enc = AlphabetEncoding.getEncoding(this.dataCoding); if (enc == null) enc = this.alphabet; return (enc.decodeString(this.message)); } /** Get the text of the message. * @param enc The text encoding of the message bytes. * @see ie.omk.smpp.util.AlphabetEncoding */ public String getMessageText(AlphabetEncoding enc) throws java.io.UnsupportedEncodingException { 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. * @exception ie.omk.smpp.StringTooLongException if the service type is too * long. */ public void setServiceType(String type) throws ie.omk.smpp.SMPPException { if(type == null) { serviceType = null; return; } if(type.length() < 6) { this.serviceType = type; Debug.d(this, "setServiceType", type, 4); } else { Debug.warn(this, "setServiceType", "Service type too long"); throw new StringTooLongException(5); } } /** Get the service type. */ public String getServiceType() { return (serviceType); } /** Set the scheduled delivery time for the short message. * @param d The date and time the message should be delivered. * @throws ie.omk.smpp.SMPPException (XXX can the date be invalid?) */ public void setDeliveryTime(SMPPDate d) throws ie.omk.smpp.SMPPException { this.deliveryTime = d; Debug.d(this, "setDeliveryTime", d, 4); } /** Get the current value of the scheduled delivery time for the short * message. */ public SMPPDate getDeliveryTime() { return (deliveryTime); } /** Set the expiry time of the message. * If the message is not delivered by time 'd', it will be cancelled and * never delivered to it's destination. * @param d the date and time the message should expire. * @exception ie.omk.smpp.SMPPException (XXX can the time be invalid?) */ public void setExpiryTime(SMPPDate d) throws ie.omk.smpp.SMPPException { expiryTime = d; Debug.d(this, "setExpiryTime", d, 4); } /** Get the current expiry time of the message. */ public SMPPDate getExpiryTime() { return (expiryTime); } /** Set the final date of the message. * The final date is the date and time that the message reached it's final * destination. * @param d the date the message was delivered. * @exception ie.omk.smpp.SMPPException (XXX can the time be invalid?) */ public void setFinalDate(SMPPDate d) throws ie.omk.smpp.SMPPException { finalDate = d; Debug.d(this, "setFinalDate", d, 4); } /** Get the final date of the message. */ public SMPPDate getFinalDate() { return (finalDate); } /** Set the message Id. * Each submitted short message is assigned an Id by the SMSC which is used * to uniquely identify it. SMPP v3.3 message Ids are hexadecimal numbers * up to 9 characters long. This gives them a range of 0x0 - 0xffffffff. * @param id The message's id. * @exception ie.omk.smpp.InvalidMessageIDException if the message id is * invalid. */ public void setMessageId(String id) throws ie.omk.smpp.SMPPException { if (id == null) { this.messageId = null; } else { try { // Using longs is probably only valid for SMPP v3.3! long l = Long.parseLong(id, 16); if (l < 0L || l > 0x0ffffffffL) throw new InvalidMessageIDException(id); this.messageId = id; Debug.d(this, "setMessageId", id, 4); } catch (NumberFormatException x) { throw new InvalidMessageIDException(id); } } } /** Get the message id. */ public String getMessageId() { return (this.messageId); } /** Set the message status. This is different to the command status field. * XXX describe the message status. * @param st The message status. * @exception ie.omk.smpp.SMPPException if the status is invalid. */ public void setMessageStatus(int st) throws ie.omk.smpp.SMPPException { this.messageStatus = st; Debug.d(this, "setMessageStatus", st, 4); } /** Get the message status. */ public int getMessageStatus() { return (this.messageStatus); } /** Set the error code. * @param code The error code. */ public void setErrorCode(int code) throws ie.omk.smpp.SMPPException { errorCode = code; Debug.d(this, "setErrorCode", code, 4); } /** Get the error code. */ public int getErrorCode() { return (errorCode); } /** Set the alphabet encoding for this message. * @param enc The alphabet to use. If null, use DefaultAlphabetEncoding. * @see ie.omk.smpp.util.AlphabetEncoding * @see ie.omk.smpp.util.DefaultAlphabetEncoding */ public void setAlphabet(AlphabetEncoding enc) { if (enc == null) this.alphabet = new ie.omk.smpp.util.DefaultAlphabetEncoding(); else this.alphabet = enc; } /** Convert this packet to a String. Not to be interpreted programmatically, * it's just dead handy for debugging! */ public String toString() { return new String("header: " + getHeaderLen() + ", " + Integer.toHexString(commandId) + ", " + commandStatus + ", " + Integer.toHexString(sequenceNum)); } /** Encode the body of the SMPP Packet to the output stream. Sub classes * should override this method to output their packet-specific fields. This * method is called from SMPPPacket.writeTo(java.io.OutputStream) to * encode the message. * @param out The output stream to write to. * @exception java.io.IOException if there's an error writing to the output * stream. */ protected void encodeBody(OutputStream out) throws java.io.IOException, ie.omk.smpp.SMPPException { // This method is not abstract so that packets that are really just an // SMPP header need not override it to just return the value from // getHeaderLen. } /** Write the byte representation of this SMPP packet to an OutputStream * @param out The OutputStream to use * @exception java.io.IOException if there's an error writing to the * output stream. */ public final void writeTo(OutputStream out) throws java.io.IOException, ie.omk.smpp.SMPPException { // Make sure the size is set properly int commandLen = getCommandLen(); SMPPIO.writeInt(commandLen, 4, out); SMPPIO.writeInt(commandId, 4, out); SMPPIO.writeInt(commandStatus, 4, out); SMPPIO.writeInt(sequenceNum, 4, out); encodeBody(out); Debug.d(this, "writeTo", "written!", 5); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -