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

📄 incomingmessage.java

📁 J2me实现的MSN Messeger客户端程序。聊天、添加好友、删除好友、阻止好友
💻 JAVA
字号:
/*
 * @(#)IncomingMessage.java
 *
 * Copyright (c) 2001-2002, JangHo Hwang
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 	1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * 	2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * 	3. Neither the name of the JangHo Hwang nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *    $Id: IncomingMessage.java,v 2.0 2004/12/21 16:15:08 chenzs Exp $
 */
package vitular.msnp.msg;

/**
 * 将HashMap改成Hashtable
 */
import java.util.Hashtable;


/**
 *
 * @author Jang-Ho Hwang, rath@linuxkorea.co.kr
 * @version $Id: IncomingMessage.java,v 2.0 2004/12/21 16:15:08 chenzs Exp $
 */
public class IncomingMessage
    extends Message {
  /*
   * NON-TR Headers from server
   *
   * NLN Substate UserHandle FriendlyName (Online)
   * FLN UserHandle (Offline)
   * RNG SessionID SSAddr SP AuthChallengeInfo CalUserHandle CalFriendName
   * OUT {StatusCode} (Get out)
   */
  private static Hashtable PUSH_HEADERS = new Hashtable();
  static {
    PUSH_HEADERS.put("MSG", "MSG");//Message消息传递
    PUSH_HEADERS.put("NLN", "NLN");//online通知客户端联系人上线或改变状态。
    PUSH_HEADERS.put("FLN", "FLN");//offline通知有联系人列表中的用户下线
    PUSH_HEADERS.put("RNG", "RNG");//ring通知客户端有人要建立聊天连接
    PUSH_HEADERS.put("JOI", "JOI");//join通知客户端已经同另外的用户建立了聊天连接
    PUSH_HEADERS.put("BYE", "BYE");//bye通知客户端结束会话
    PUSH_HEADERS.put("OUT", "OUT");//out结束客户端-服务器的连接
    PUSH_HEADERS.put("BPR", "BPR");//
    PUSH_HEADERS.put("LSG", "LSG");//list group联系人组列表的请求/应答
    PUSH_HEADERS.put("LST", "LST");//list联系人列表的请求/应答
  }

  private boolean isBodyless = false;

  private IncomingMessage(String header) {
    super(header);
  }

  private void fill(String str) {
    int len = str.length();
    int preoff = 0;
    int offset = 0;
    while ( (offset = str.indexOf(' ', preoff)) != -1) {
      list.add(str.substring(preoff, offset));

      preoff = offset + 1;
      if (preoff >= len)
        break;
    }
    if (preoff < len)
      list.add(str.substring(preoff));
  }

  public static IncomingMessage getInstance(String line) {
    if (line.length() <= 3) {
      IncomingMessage msg = new IncomingMessage(line);
      msg.isBodyless = true;
      return msg;
    }

    String header = line.substring(0, 3);
    IncomingMessage msg = new IncomingMessage(header);

    if (PUSH_HEADERS.containsKey(header)) {
      // No transaction id
      msg.isBodyless = true;
      msg.fill(line.substring(4));
    }
    else {
      // Have transaction id
      int i0 = line.indexOf(' ', 4);
      if (i0 == -1) {
        msg.setTransactionId(Integer.parseInt(line.substring(4)));
      }
      else {
        msg.setTransactionId(Integer.parseInt(line.substring(4, i0)));
        msg.fill(line.substring(i0 + 1));
      }
    }

    return msg;
  }

  /**
   * \uFFFD\u05BE\uFFFD\uFFFD\uFFFD index\uFFFD\uFFFD hostname:port \uFFFD\uFFFD\uFFFD\uFFFD\uFFFD \uFFFD\u0136\uFFFD\uFFFD\uFFFD\u0378\uFFFD \uFFFDо\uFFFD\u9FE9\uFFFD\uFFFD
   * parsing\uFFFD\u03FF\uFFFD ServerInfo \uFFFD\uFFFDü\uFFFD\uFFFD \uFFFD\uFFFD\uFFFD\u03FF\uFFFD \uFFFD\uFFFD\u022F\uFFFD\uFFFD\uFFFD\u0634\uFFFD.
   */
  public String getServerIP(int index) {
    String str = list.get(index);
    if (str == null)
      return null;

    int i0 = str.indexOf(':');
    String ip = str.substring(0, i0);

    return ip;
  }

  /**
   * \uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD \uFFFD\u07BD\uFFFD\uFFFD\uFFFD trId\uFFFD\uFFFD \uFFFD\uFFFD\uFFFD notify\uFFFD\uFFFD \uFFFD\u07BD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD
   * \u022E\uFFFD\uFFFD\uFFFD\u0474\uFFFD.
   */
  public boolean isNotify() {
    return this.isBodyless;
  }
}

⌨️ 快捷键说明

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