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

📄 address.java

📁 短信短消息SMPP开发的JAVA API最新版本。
💻 JAVA
字号:
/* * Java SMPP API * Copyright (C) 1998 - 2002 by Oran Kelly *  * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *  * A copy of the LGPL can be viewed at http://www.gnu.org/copyleft/lesser.html * Java SMPP API author: orank@users.sf.net * Java SMPP API Homepage: http://smppapi.sourceforge.net/ * $Id: Address.java,v 1.4 2004/07/11 20:28:08 orank Exp $ */package ie.omk.smpp;import ie.omk.smpp.util.GSMConstants;import ie.omk.smpp.util.SMPPIO;import java.io.OutputStream;/** Object representing a Short Message Entity's address. An address consists of * a Type Of Number, a Numbering Plan Indicator and an address. * @see ie.omk.smpp.util.GSMConstants */public class Address implements java.io.Serializable{    /** Type of number. */    private int ton = GSMConstants.GSM_TON_UNKNOWN;    /** Numbering plan indicator. */    private int npi = GSMConstants.GSM_NPI_UNKNOWN;    /** The address. */    private String address = "";    /** Create a new Address with all nul values. TON will be 0, NPI will be 0     * and the address field will be blank.     */    public Address()    {    }    /** Create a new Address.     * @param ton The Type Of Number.     * @param npi The Numbering Plan Indicator.     * @param address The address.     */    public Address(int ton, int npi, String address)    {	this.ton = ton;	this.npi = npi;	this.address = address;    }        /** Get the Type Of Number.     */    public int getTON()    {	return (ton);    }    /** Set the Type of Number.     */    public void setTON(int ton)    {	this.ton = ton;    }    /** Get the Numbering Plan Indicator.     */    public int getNPI()    {	return (npi);    }    /** Set the Numbering Plan Indicator.     */    public void setNPI(int npi)    {	this.npi = npi;    }    /** Get the address.     */    public String getAddress()    {	return (address);    }    /** Set the address.     */    public void setAddress(String address)    {	this.address = (address != null) ? address : "";    }    /** Get a unique hash code for this address.     */    public int hashCode()    {	StringBuffer buf = new StringBuffer();	buf.append(Integer.toString(ton)).append(':');	buf.append(Integer.toString(npi)).append(':');	if (address != null)	    buf.append(address);	return (buf.hashCode());    }    /** Test for equality. Two address objects are equal if their TON, NPI and     * address fields are equal.     */    public boolean equals(Object obj)    {	if (obj instanceof Address) {	    Address a = (Address)obj;	    return ((a.ton == ton)		    && (a.npi == npi)		    && (a.address.equals(address)));	} else {	    return (false);	}    }    /** Get the number of bytes this object would encode to.     */    public int getLength()    {	return (3 + address.length());    }    /** Encode this object as bytes to the output stream. An address encodes as     * a single byte for the TON, a single byte for the NPI and a nul-terminated     * ASCII character string.     * @param out The output stream to encode the address to.     * @throws java.io.IOException If an I/O error occurs while writing to the     * output stream.     */    public void writeTo(OutputStream out)	throws java.io.IOException    {	SMPPIO.writeInt(ton, 1, out);	SMPPIO.writeInt(npi, 1, out);	SMPPIO.writeCString(address, out);    }    /** Decode this address from a byte array.     * @param addr The byte array to read the address from.     * @param offset The offset within the byte array to begin decoding from.     * @throws java.lang.ArrayIndexOutOfBoundsException If the byte array does     * not contain enough bytes to decode an address.     */    public void readFrom(byte[] addr, int offset)    {	ton = SMPPIO.bytesToInt(addr, offset++, 1);	npi = SMPPIO.bytesToInt(addr, offset++, 1);	address = SMPPIO.readCString(addr, offset);    }    public String toString()    {	return (Integer.toString(ton) + ":" + Integer.toString(npi) + ":"		+ address);    }    /** Test driver function. This method checks that serialization and     * deserialization of instances of this class result in byte arrays and new     * packets of consistently the same size. It does the same as the NullTest     * and FullTest packet test classes.     */    /*public static final void main(String[] args)    {	try {	    System.out.println("Null test:");	    Address a = new Address();	    java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();	    a.writeTo(os);	    byte[] b = os.toByteArray();	    if (b.length == a.getLength())		System.out.println("\tpass 1.");	    else		System.out.println("\tfail 1.");	    Address a1 = new Address();	    a1.readFrom(b, 0);	    if (b.length == a1.getLength())		System.out.println("\tpass 2.");	    else		System.out.println("\tfail 2.");	} catch (Exception x) {	    System.out.println("\texception:");	    x.printStackTrace(System.out);	}	try {	    System.out.println("\nFilled test:");	    Address a = new Address(2, 2, "4745879345");	    java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();	    a.writeTo(os);	    byte[] b = os.toByteArray();	    if (b.length == a.getLength())		System.out.println("\tpass 1.");	    else		System.out.println("\tfail 1.");	    Address a1 = new Address();	    a1.readFrom(b, 0);	    if (b.length == a1.getLength())		System.out.println("\tpass 2.");	    else		System.out.println("\tfail 2.");	} catch (Exception x) {	    System.out.println("\texception:");	    x.printStackTrace(System.out);	}    }*/}

⌨️ 快捷键说明

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