📄 cngpreader.java
字号:
package com.grail.comm.cngp;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import com.grail.comm.cngp.message.CNGPActiveTestMessage;
import com.grail.comm.cngp.message.CNGPDeliverMessage;
import com.grail.comm.cngp.message.CNGPLoginRespMessage;
import com.grail.comm.cngp.message.CNGPSubmitRespMessage;
import com.grail.comm.core.PMessage;
import com.grail.comm.core.PReader;
import com.grail.util.TypeConvert;
/**
* <p>
* Title: 短信 项目
* </p>
* <p>
* Description:网通CNGP协议读取
* </p>
* <p>
* Copyright: Copyright (c) 2004 合力阳光
* </p>
* <p>
* Company: 合力阳光
* </p>
*
* @author ray/刘有为
* @version 1.0
*/
public class CNGPReader extends PReader {
protected DataInputStream in;
public CNGPReader(InputStream is) {
in = new DataInputStream(new BufferedInputStream(is));
}
/* (non-Javadoc)
* @see com.ray.insa2.comm.core.PReader#read()
*/
public PMessage read() throws IOException {
int totalLength = in.readInt();
int commandId = in.readInt();
byte[] tmp = new byte[totalLength - 8];
in.readFully(tmp);
byte[] buf = new byte[totalLength];
TypeConvert.int2byte(totalLength, buf, 0);
TypeConvert.int2byte(commandId, buf, 4);
System.arraycopy(tmp, 0, buf, 8, totalLength - 8);
if (commandId == 0x80000001) {
return new CNGPLoginRespMessage(buf);
}
if (commandId == 0x00000003)
return new CNGPDeliverMessage(buf);
if (commandId == 0x80000002)
return new CNGPSubmitRespMessage(buf);
if (commandId == 0x00000004) {
return new CNGPActiveTestMessage();
} else
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -