?? protocolparserimpl.java
字號:
/**
* Project:ms4j (Message Server for Java)
* Date:2007-3-13
* Authoer : jobsun@gmail.com
*
* This 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 software 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.
*
*/
package com.sunjob.ms4j.server.impl;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketAddress;
import java.util.HashMap;
import com.sunjob.ms4j.server.MsgProcesser;
import com.sunjob.ms4j.server.MsgRequest;
import com.sunjob.ms4j.server.MsgResponse;
import com.sunjob.ms4j.server.ProtocolParser;
import com.sunjob.ms4j.util.IOUtil;
/**
* @author sunjb
*
*/
public class ProtocolParserImpl implements ProtocolParser {
private HashMap context = null;
public ProtocolParserImpl() {
}
/*
* (non-Javadoc)
*
* @see com.sunjob.ms4j.server.MsgTranProtocol#getStatusText(int)
*/
public String getStatusText(int code) {
String str = null;
switch (code) {
case 20:
str = "正常";
break;
case 41:
str = "網(wǎng)絡(luò)異常";
break;
case 43:
str = "用戶名或密碼錯誤";
break;
case 44:
str = "無效的請求";
break;
case 50:
str = "后臺處理出現(xiàn)異常";
break;
case 60:
str = "消息服務(wù)器異常";
break;
}
return str;
}
/*
* (non-Javadoc)
*
* @see com.sunjob.ms4j.server.MsgTranProtocol#parse(java.io.InputStream,
* java.io.OutputStream)
*/
public void parse(SocketAddress address, InputStream is, OutputStream os)
throws Exception {
byte[] breq = IOUtil.read(is);
byte[] bName = null;
if (breq.length > 256) {
bName = new byte[256];
System.arraycopy(breq, 0, bName, 0, 256);
} else
bName = breq;
String strHeader = new String(bName);
int i = strHeader.indexOf(" ");
if (i <= 0)
throw new Exception("Error Request Header.");
String name = strHeader.substring(0, i);
MsgProcesser mp = (MsgProcesser) this.context.get(name);
ByteArrayInputStream bais = new ByteArrayInputStream(breq);
bais.skip(i + 1);
MsgRequest request = new MsgRequestImpl(bais);
MsgResponse response = new MsgResponseImpl(os);
mp.process(request, response);
}
public void setContext(HashMap context) {
this.context = context;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -