📄 cmpputility.java
字号:
import java.util.*;
import java.lang.*;
import java.net.*;
import java.io.*;
import CMPPException;
public class CMPPUtility
{
public static void read(InputStream is,byte[] bBytes)
throws IOException, CMPPException
{
if(is == null)
{
throw new CMPPException("CMPPUtility.read : null input stream !");
}
if(bBytes == null || bBytes.length <= 0)
{
throw new CMPPException("CMPPUtility.read : null buffer !");
}
int nLength = bBytes.length;
int nOffset = 0;
do
{
int nByteRead = is.read(bBytes,nOffset,nLength - nOffset);
if(nByteRead == -1)
{
throw new CMPPException("CMPPUtility.read : unexpected end !");
}
nOffset += nByteRead;
}while(nOffset < nLength);
}
public static void write(OutputStream os,byte[] bBytes)
throws IOException, CMPPException
{
if(os == null)
{
throw new CMPPException("CMPPUtility.write : null output stream !");
}
if(bBytes == null || bBytes.length <= 0)
{
throw new CMPPException("CMPPUtility.write : null buffer !");
}
os.write(bBytes);
}
public static String toHexString(byte bValue)
{
String strHex = "";
strHex += Character.forDigit((bValue >> 4) & 0x0f,16);
strHex += Character.forDigit(bValue & 0x0f,16);
return new String(strHex);
}
public static String toHexString(short sValue)
{
String strTemp = "";
for(int i = 0;i < 4;i ++)
{
strTemp += Character.forDigit(sValue & 0x0f,16);
sValue = (short)(sValue >> 4);
}
String strHex = "";
for(int j = 8;j > 0;j --)
{
strHex += strTemp.charAt(j - 1);
}
return new String(strHex);
}
public static String toHexString(int nValue)
{
String strTemp = "";
for(int i = 0;i < 8;i ++)
{
strTemp += Character.forDigit(nValue & 0x0f,16);
nValue = nValue >> 4;
}
String strHex = "";
for(int j = 8;j > 0;j --)
{
strHex += strTemp.charAt(j - 1);
}
return new String(strHex);
}
public static String toHexString(byte[] bBytes)
{
String strBytes = "";
if(bBytes == null)
{
return null;
}
for(int i = 0;i < bBytes.length;i ++)
{
strBytes += toHexString(bBytes[i]);
}
return new String(strBytes);
}
public static String getMsgFmtDescription(byte msg_fmt)
{
switch(msg_fmt)
{
case 0:
return "ASCII串";
case 3:
return "短信息写卡操作";
case 4:
return "二进制信息";
case 8:
return "UCS2编码";
case 15:
return "含GB汉字";
default:;
}
return "(保留)";
}
public static String getRegisteredDeliveryDescription(byte registered_delivery)
{
switch(registered_delivery)
{
case 0:
return "不需要";
case 1:
return "需要";
case 2:
return "产生SMC话单";
default:;
}
return "(保留)";
}
public static String getResultDescription(byte result)
{
switch(result)
{
case 0:
return "正确";
case 1:
return "消息结果错";
case 2:
return "命令字错";
case 3:
return "消息序号重复";
case 4:
return "消息长度错";
case 5:
return "资费代码错";
case 6:
return "超过最带信息长";
case 7:
return "业务代码错";
case 8:
return "流量控制错";
default:;
}
return "(其他错误)";
}
static public String getStatusDescription(int status)
{
switch(status)
{
case 0:
return "正确";
case 1:
return "消息结构错";
case 2:
return "非法SP_ID";
case 3:
return "SP认证错";
case 4:
return "版本太高";
default:;
}
return "其他错误";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -