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

📄 socketevent.java

📁 一个实用工具类
💻 JAVA
字号:
/* * Copyright (C) butor.com. All rights reserved. * * This software is published under the terms of the GNU Library General * Public License (GNU LGPL), a copy of which has been included with this * distribution in the LICENSE.txt file.  */package org.butor.socket.tcp;import java.util.EventObject;/** * Socket events * * @author Aiman Sawan */public class SocketEvent extends EventObject {		// theses constants are used to make and check a bitset.	// so values are important if new events are added.	/**	 * The socket connection to a host is failed even	 * after many attempts.	 */	public final static int EVENT_CONNECTION_FAILED = 1;	/**	 * The socket connection to a host is failed but 	 * will make another attempt.	 */	public final static int EVENT_CONNECTION_FAILED_RETRY = 2;	/**	 * The socket connection to a host is done successfully.	 */	public final static int EVENT_CONNECTED = 4;	/**	 * The socket connection to a host are closed.	 */	public final static int EVENT_DISCONNECTED = 8;	/**	 * Data are written on the socket.	 */	public final static int EVENT_WRITE_DATA = 16;	/**	 * Data can't be written on the socket even	 * after many attempts.	 */	public final static int EVENT_WRITE_FAILED = 32;	/**	 * Data can't be written on the socket but	 * will make another attempt.	 */	public final static int EVENT_WRITE_FAILED_RETRY = 64;	/**	 * Data can't be written on the socket due to	 * a timeout period.	 */	public final static int EVENT_WRITE_TIMEOUT = 2048;	/**	 * Data are read from the socket.	 */	public final static int EVENT_READ_DATA = 128;	/**	 * Data can't be read from the socket even	 * after many attempts.	 */	public final static int EVENT_READ_FAILED = 256;	/**	 * Data can't be read from the socket but	 * will make another attempt.	 */	public final static int EVENT_READ_FAILED_RETRY = 512;	/**	 * Data can't be read from the socket due to	 * a timeout period.	 */	public final static int EVENT_READ_TIMEOUT = 1024;	protected byte[] f_bytes;	protected int f_id;		/**	 * Constructor.	 * 	 * @param source Object, events generator object.	 */	public SocketEvent(Object source) {		super(source);		f_bytes = null;		f_id = 0;	}	/**	 * Set event related data bytes.	 * example: bytes on read events, are read bytes	 * This is protected to avoid modification	 * by handlers.	 * 	 * @param bytes bytes[], array of bytes	 */	protected void setBytes(byte[] bytes) {		f_bytes = bytes;	}	/**	 * Set event id.	 * This is protected to avoid modification	 * by handlers.	 * 	 * @param id int, event identifier	 */	protected void setId(int id) {		f_id = id;	}	/**	 * get event related bytes.	 * 	 * @return byte[], event related bytes.	 */	public byte[] getBytes() {		return f_bytes;	}	/**	 * Get event identifier	 * 	 * @return int, event id.	 */	public int getId() {		return f_id;	}	/**	 * Get an event name.	 * 	 * @param id int, event id.	 */	public String getEventName(int id) {		switch (id) {			case EVENT_CONNECTED: return "connected";			case  EVENT_CONNECTION_FAILED: return "connection_failed";			case EVENT_CONNECTION_FAILED_RETRY: return "connection_failed_retry";			case EVENT_DISCONNECTED: return "disconnected";			case EVENT_WRITE_DATA: return "write_data";			case EVENT_WRITE_FAILED: return "write_failed";			case EVENT_WRITE_FAILED_RETRY: return "write_failed_retry";			case EVENT_WRITE_TIMEOUT: return "write_timeout";			case EVENT_READ_DATA: return "read_data";			case EVENT_READ_FAILED: return "read_failed";			case EVENT_READ_FAILED_RETRY: return "read_failed_retry";			case EVENT_READ_TIMEOUT: return "read_timeout";			default: return "unknown";		}	}	/**	 * toString()	 */	public String toString() {		return "id: " +f_id + " (" +getEventName(f_id) +")" +			" data: " +(f_bytes == null ? "null" : new String(f_bytes));	}}

⌨️ 快捷键说明

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