📄 socketconnectioninputstream.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.InputStream;/** * Implementation of InputStream on object SocketConnection. * It is usefull to provide InputStream capabilities on object * as SocketConnection where read/write timeouts are managed * and events dispatiching are provided. * * @author Aiman Sawan */public class SocketConnectionInputStream extends InputStream { protected SocketConnection f_conn; // to perform one byte write in write(byte). protected byte[] f_oneByteArray; /** * Constructor for SocketConnectionInputStream. */ public SocketConnectionInputStream(SocketConnection conn) throws IOException { super(); if (conn == null) { throw new IOException("Got NULL SocketConnection object!"); } f_conn = conn; f_oneByteArray = new byte[1]; } /** * @see InputStream#read() */ public int read() throws IOException { if (f_conn.read(f_oneByteArray) > 0) { return f_oneByteArray[0]; } else { return 0; } } /** * @see InputStream#read(byte[]) */ public int read(byte[] buffer) throws IOException { return f_conn.read(buffer); } /** * read buffer of bytes. * Make one fast read without timeout mecanics. * This is usefull to drain unwanted still bytes. * If nothing to be read by 1/1000 of second it will * be ok. * * @param buffer byte[], buffer to fill * * @return int, number of read bytes. */ public int readFast(byte[] buffer) throws IOException { return f_conn.readFast(buffer); } /** * @see InputStream#read(byte[], int offset, int count) */ public int read(byte[] buffer, int offset, int count) throws IOException { return f_conn.read(buffer, offset, count); } /** * @see InputStream#available() */ public int available() throws IOException { return 0; } /** * @see InputStream#skip(long) */ public long skip(long count) throws IOException { // not supported return 0; } /** * @see InputStream#close() */ public void close() throws IOException { f_conn.disconnect(); } /** * @see InputStream#mark() */ public synchronized void mark() { // not supported } /** * @see InputStream#markSupported() */ public boolean markSupported() { return false; } /** * @see InputStream#reset() */ public void reset() throws IOException { // not supported } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -