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

📄 socketconnectionoutputstream.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.io.IOException;import java.io.OutputStream;import org.butor.log.Log;/** * Implementation of OutputStream on object SocketConnection. * It is usefull to provide OnputStream capabilities on object * such as SocketConnection where read/write timeouts, retries, * auto-(re)connect are managed and events dispatiching are provided. *  * @author Aiman Sawan */public class SocketConnectionOutputStream extends OutputStream {	private static final String CLASS_NAME = SocketConnectionOutputStream.class.getName();	protected SocketConnection f_conn;		// to perform one byte write in write(byte).	protected byte[] f_oneByteArray;		/**	 * Constructor for SocketConnectionOutputStream.	 */	public SocketConnectionOutputStream(SocketConnection conn) throws IOException {		super();				if (conn == null) {			throw new IOException("Got NULL SocketConnection object!");		}				f_conn = conn;		f_oneByteArray = new byte[1];	}	/**	 * @see OutputStream#write(int)	 */	public void write(int b) throws IOException {		f_oneByteArray[0] = (byte)b;		f_conn.write(f_oneByteArray);	}	/**	 * @see OutputStream#write(byte[])	 */	public void write(byte[] buffer) throws IOException {		f_conn.write(buffer);	}	/**	 * @see OutputStream#write(byte[], int, int)	 */	public void write(byte[] buffer, int offset, int count) throws IOException {		f_conn.write(buffer, offset, count);	}	/**	 * @see OutputStream#flush()	 */	public void flush() throws IOException {		f_conn.flush();	}	/**	 * @see OutputStream#close()	 */	public void close() throws IOException {		f_conn.disconnect();	}		/**	 * When called, this method will prevent any further	 * logging of the data sent on the socket	 */	public void disableLogging() {		if (Log.shouldLog(CLASS_NAME, Log.LOG_LEVEL_MEDIUM)) {			Log.logStr(this, Log.LOG_TYPE_INFO, "disableLogging", toString());		}				f_conn.disableLogging();	}		/**	 * When called, this method will enable logging	 * of the data sent on the socket, the logging	 * will correspond to the trace level of the class	 */	public void enableLogging() {		if (Log.shouldLog(CLASS_NAME, Log.LOG_LEVEL_MEDIUM)) {			Log.logStr(this, Log.LOG_TYPE_INFO, "enableLogging", toString());		}				f_conn.enableLogging();	}}

⌨️ 快捷键说明

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