Class SMSTPDUWithData

  • All Implemented Interfaces:
    DataObject, Serializable
    Direct Known Subclasses:
    SMSDeliver, SMSDeliverReport, SMSStatusReport, SMSSubmit, SMSSubmitReport

    public abstract class SMSTPDUWithData
    extends SMSTPDU
    Superclass handling common methods for dealing with user data: ProtocolId (TP-PID), UserData (TP-UD), UserDataLength (TP-UDL), UserDataHeaderIndicator (TP-UDHI), and DataCodingScheme (TP-DCS).

    Field onlyHeader, when present, causes the userDataLength and userData fields to be omitted on encoding and to be required to be absent on decoding; it doesn't prevent values from being set for those fields, those fields still participate in the Map returned by getFieldsMap(), and hence equals(), hashCode() and toString() are still affected.

    See Also:
    Serialized Form
    • Field Detail

      • OnlyHeader_value

        protected ASN1Null OnlyHeader_value
        Value of field OnlyHeader.
      • OnlyHeader_present

        protected boolean OnlyHeader_present
        Whether field OnlyHeader is present.
      • ProtocolId_value

        protected SMSProtocolId ProtocolId_value
        Value of field ProtocolId.
      • DataCodingScheme_value

        protected SMSDataCodingScheme DataCodingScheme_value
        Value of field DataCodingScheme.
      • UserDataLength_value

        protected int UserDataLength_value
        Value of field UserDataLength.
      • UserDataLength_present

        protected boolean UserDataLength_present
        Whether field UserDataLength is present.
      • UserData_value

        protected byte[] UserData_value
        Value of field UserData.
    • Constructor Detail

      • SMSTPDUWithData

        public SMSTPDUWithData()
        Constructs a new SMSTPDUWithData object with no fields set.
      • SMSTPDUWithData

        public SMSTPDUWithData​(byte[] data)
        Constructs a new SMSTPDUWithData object from network-encoded data. The data is not decoded and might not be decodable.
        Parameters:
        data - network-encoded data
        Throws:
        NullPointerException - if data is null
      • SMSTPDUWithData

        public SMSTPDUWithData​(byte[] data,
                               int start,
                               int len)
        Constructs a new SMSTPDUWithData object from part of network-encoded data. The part starts at index start and is len bytes long. The data is not decoded and might not be decodable.
        Parameters:
        data - network-encoded data
        start - starting offset of network-encoded data in byte array
        len - default length if not predictable
        Throws:
        NullPointerException - if data is null
        IllegalArgumentException - if len is negative
    • Method Detail

      • hasOnlyHeader

        public boolean hasOnlyHeader()
                              throws DecodeException
        Tests whether the field OnlyHeader has a value.
        Returns:
        whether the field has a value
        Throws:
        DecodeException - if encoded state cannot be decoded
      • setOnlyHeaderPresent

        public SMSTPDUWithData setOnlyHeaderPresent​(boolean flag)
                                             throws IllegalStateException
        Sets the presence or absence of the field OnlyHeader.
        Parameters:
        flag - whether the field should be marked as present
        Returns:
        this
        Throws:
        IllegalStateException - if this instance has been marked as read-only
      • hasUserDataHeaderIndicator

        public boolean hasUserDataHeaderIndicator()
                                           throws DecodeException
        Tests whether the field UserDataHeaderIndicator has a value.
        Returns:
        whether the field has a value
        Throws:
        DecodeException - if encoded state cannot be decoded
      • hasProtocolId

        public boolean hasProtocolId()
                              throws DecodeException
        Tests whether the field ProtocolId has a value.
        Returns:
        whether the field has a value
        Throws:
        DecodeException - if encoded state cannot be decoded
      • hasDataCodingScheme

        public boolean hasDataCodingScheme()
                                    throws DecodeException
        Tests whether the field DataCodingScheme has a value.
        Returns:
        whether the field has a value
        Throws:
        DecodeException - if encoded state cannot be decoded
      • hasUserDataLength

        public boolean hasUserDataLength()
                                  throws DecodeException
        Tests whether the field UserDataLength has a value.
        Returns:
        whether the field has a value
        Throws:
        DecodeException - if encoded state cannot be decoded
      • setUserDataLengthPresent

        public SMSTPDUWithData setUserDataLengthPresent​(boolean flag)
                                                 throws IllegalStateException
        Sets the presence or absence of the field UserDataLength.
        Parameters:
        flag - whether the field should be marked as present
        Returns:
        this
        Throws:
        IllegalStateException - if this instance has been marked as read-only
      • hasUserData

        public boolean hasUserData()
                            throws DecodeException
        Tests whether the field UserData has a value.
        Returns:
        whether the field has a value
        Throws:
        DecodeException - if encoded state cannot be decoded
      • checkFieldsSet

        public void checkFieldsSet()
                            throws EncodeException
        Checks that all mandatory fields are present. Should be called immediately before all calls to encode().
        Overrides:
        checkFieldsSet in class SMSTPDU
        Throws:
        EncodeException - if any mandatory field is not present
      • getProtocolId

        public SMSProtocolId getProtocolId()
                                    throws DecodeException
        Gets the value of identifies the above layer protocol.
        Returns:
        SMSProtocolId representation of identifies the above layer protocol
        Throws:
        DecodeException - if encoded state cannot be decoded
      • getDataCodingScheme

        public SMSDataCodingScheme getDataCodingScheme()
                                                throws DecodeException
        Gets the value of the coding scheme within the user data.
        Returns:
        SMSDataCodingScheme representation of the coding scheme within the user data
        Throws:
        DecodeException - if encoded state cannot be decoded
      • getUserDataLength

        public int getUserDataLength()
                              throws DecodeException
        Gets the value of the length of the user data.
        Returns:
        int representation of the length of the user data
        Throws:
        DecodeException - if encoded state cannot be decoded
      • getUserData

        public byte[] getUserData()
                           throws DecodeException
        Gets the value of the user data.
        Returns:
        byte[] representation of the user data
        Throws:
        DecodeException - if encoded state cannot be decoded
      • getUserDataHeader

        public final byte[] getUserDataHeader()
        Gets the UserDataHeader portion of the UserData (TP-UD), if present.
        Returns:
        the header as a bytearray, or null if UserData (TP-UD) is not present or it does not contain a UserDataHeader (UDH)
      • getUserDataString

        public final String getUserDataString()
        Gets the text portion of UserData (TP-UD) in String form. This method only decodes data encoded using the 7-bit GSM and UCS-2 Data Coding Schemes. For other data coding schemes, the user must decode the data themselves.
        Returns:
        a String representing the text portion of UserData (TP-UD), or null if UserData (TP-UD) is not present
        Throws:
        IllegalArgumentException - if the PDU cannot be decoded or the Data Coding Scheme is not supported
        ArrayIndexOutOfBoundsException - if the PDU is truncated
      • setUserDataString

        public final void setUserDataString​(String value)
        Sets UserData (TP-UD) to the given text value, with no UserDataHeader (UDH). DataCodingScheme (TP-DCS) is set to the 7-bit GSM coding scheme if the string can be represented in the 7-bit alphabet; otherwise, the UCS-2 coding scheme is used. UserDataLength (TP-UDL) is set appropriately. UserDataHeaderIndicator (TP-UDHI) is cleared.
        Parameters:
        value - the text value to use, or null to clear UserData (TP-UD)
        Throws:
        IllegalArgumentException - if the PDU cannot be decoded, or the resulting UserData (TP-UD) exceeds 140 octets.
        ArrayIndexOutOfBoundsException - if the PDU is truncated
      • setUserDataString

        public final void setUserDataString​(String value,
                                            byte[] header)
        Sets UserData (TP-UD) to the given text value, with an optional UserDataHeader (UDH). DataCodingScheme (TP-DCS) is set to the 7-bit GSM coding scheme if the string can be represented in the 7-bit alphabet; otherwise, the UCS-2 coding scheme is used. UserDataLength (TP-UDL) is set appropriately. If a header is supplied, UserDataHeaderIndicator (TP-UDHI) is set and the provided header is added to UserData (TP-UD). If no header is supplied, UserDataHeaderIndicator (TP-UDHI) is cleared.
        Parameters:
        value - the text value to use, or null to provide no text.
        header - the UserDataHeader (UDH) contents to use, or null to provide no header.
        Throws:
        IllegalArgumentException - if the PDU cannot be decoded, or the resulting UserData (TP-UD) exceeds 140 octets.
        ArrayIndexOutOfBoundsException - if the PDU is truncated
      • setUserDataString

        public final void setUserDataString​(SMSDataCodingScheme dcs,
                                            String value)
        Sets UserData (TP-UD) to the given text value, using a provided DataCodingScheme (DCS) and no UserDataHeader (UDH). Only 7-bit GSM and UCS-2 based coding schemes are supported. DataCodingScheme (TP-DCS) is set to the provided value. UserDataLength (TP-UDL) is set appropriately. If a header is supplied, UserDataHeaderIndicator (TP-UDHI) is set and the provided header is added to UserData (TP-UD). If no header is supplied, UserDataHeaderIndicator (TP-UDHI) is cleared.
        Parameters:
        dcs - the DataCodingScheme (TP-DCS) value to use
        value - the text value to use
        Throws:
        IllegalArgumentException - if the PDU cannot be decoded, or DataCodingScheme (TP-DCS) is out of range, or the given DataCodingScheme (DCS) cannot encode the given value, or the resulting UserData (TP-UD) exceeds 140 octets
        ArrayIndexOutOfBoundsException - if the PDU is truncated
      • setUserDataString

        public final void setUserDataString​(SMSDataCodingScheme dcs,
                                            String value,
                                            byte[] header)
        Sets UserData (TP-UD) to the given text value, using a provided DataCodingScheme (DCS) and an optional UserDataHeader (UDH). Only 7-bit GSM and UCS-2 based coding schemes are supported. DataCodingScheme (TP-DCS) is set to the provided value. UserDataLength (TP-UDL) is set appropriately. UserDataHeaderIndicator (TP-UDHI) is cleared.
        Parameters:
        dcs - the DataCodingScheme (TP-DCS) value to use
        value - the text value to use
        header - the UserDataHeader (UDH) contents to use, or null to provide no header
        Throws:
        IllegalArgumentException - if the PDU cannot be decoded, or DataCodingScheme (TP-DCS) is out of range, or the given DataCodingScheme (DCS) cannot encode the given value, or the resulting UserData (TP-UD) exceeds 140 octets
        ArrayIndexOutOfBoundsException - if the PDU is truncated
      • checkUserDataConstraints

        protected final void checkUserDataConstraints()
        Checks that UserData (TP-UD), UserDataLength (TP-UDL), and DataCodingScheme (TP-DCS) are consistent with each other. Called by subclasses before encoding.
        Throws:
        IllegalStateException - if something is inconsistent