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

📄 msg.java

📁 同步接收web services请求
💻 JAVA
字号:
/**
 * 
 */
package com.aceway.vas.sjcraw.cbgp201;

import java.io.Serializable;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;

import com.aceway.vas.sjcraw.cbgp201.common.ConfigFileOper;
import com.aceway.vas.sjcraw.cbgp201.common.MsgInfo;

/**
 * 标题: 华为彩铃平台接口规范
 * 说明: 消息体, 为抽象类, 每个具体的消息体都要继承此类
 * 版权: Copyright(c) 2007 
 * 公司: 北京汉铭信通科技有限公司 
 * 部门: 增值业务部 
 * 作者: 武达
 * May 28, 2007
 */
public class Msg implements Serializable{
	protected MsgHead msgHead;
	protected ByteBuffer bodyBuffer ;
	private int commandLength;
	protected SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd");			//日期格式
	protected SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");				//时间格式
	
	
	private String souAddr = ConfigFileOper.getProperty("souAddr");
	private String desAddr = ConfigFileOper.getProperty("desAddr");
	
	protected Msg(){}
	
	/**
	 * @param bytes		接收到的消息体
	 */
	protected Msg(byte[] bytes){
		byte[] temp = new byte[MsgInfo.LEN_HEAD];
		System.arraycopy(bytes, 0, temp, 0, temp.length);
		msgHead = new MsgHead(temp);
		int len = bytes.length-MsgInfo.LEN_HEAD;
		if (len >0){
			bodyBuffer = ByteBuffer.allocate(len);
			temp = new byte[len];
			System.arraycopy(bytes, MsgInfo.LEN_HEAD, temp, 0, temp.length);
			bodyBuffer.put(temp);
			bodyBuffer.flip();
		}
	}
	
	/**
	 * 设置消息头
	 * @param operCode
	 * @param commandStatus
	 * @param seqNo
	 * @param linkId
	 */
	protected void setMsgHead(int operCode, String commandStatus, String seqNo, String linkId){
		msgHead = new MsgHead( String.valueOf(commandLength),  operCode,  commandStatus,  souAddr,
				 desAddr,  seqNo,  linkId);
	}
	
	/**
	 * 设置消息头
	 * @param bytes
	 */
	protected void setMsgHead(byte[] bytes){
		msgHead = new MsgHead(bytes);
	}
	
	/**
	 * 设置消息体
	 * @param bytes
	 */
	protected void setMsgBody(byte[] bytes){
		bodyBuffer = ByteBuffer.allocate(Integer.valueOf(msgHead.getCommandLength()) - MsgInfo.LEN_HEAD);
		bodyBuffer.put(bytes);
		bodyBuffer.flip();
	}
	
	/**
	 * 获得消息
	 * @return
	 */
	public byte[] getMsg(){
		int len = getCommandLength();
		byte[] bytes = new byte[len];
		System.arraycopy(getMsgHead().getHeadBuffer().array(), 0, bytes, 0, MsgInfo.LEN_HEAD);
		System.arraycopy(bodyBuffer.array(), 0, bytes, MsgInfo.LEN_HEAD, bodyBuffer.array().length);
		return bytes;
	}
	

	/**
	 * 设置消息包的长度(包括消息头和消息体的总长)
	 * @param lenBody			只是消息体的参数并不包括消息头的长度
	 */
	protected void setCommandLength(int lenBody){
		this.commandLength = MsgInfo.LEN_HEAD+lenBody;
	}
	
	/**
	 * 获得消息包的长度
	 * @return
	 */
	protected int getCommandLength(){
		return this.commandLength;
	}

	/**
	 * 获得消息体Buffer
	 * @return
	 */
	public ByteBuffer getBodyBuffer() {
		return bodyBuffer;
	}

	/**
	 * 得到消息头
	 * @return
	 */
	public MsgHead getMsgHead() {
		return msgHead;
	}
	
}

⌨️ 快捷键说明

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