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

📄 mstreamconnector.java

📁 httptunnel.jar httptunnel java 源码
💻 JAVA
字号:
package net.jumperz.util;

import java.io.*;

public final class MStreamConnector
implements MCommand, MSubject1
{
private int state;
private InputStream inputStream;
private OutputStream outputStream;
private MSubject1 subject = new MSubject1Impl();

private static final int BUFSIZE	= 4096;

public static final int RECEIVED	= 0;
public static final int SEND		= 1;
public static final int CLOSED		= 2;
//-------------------------------------------------------------------------------------------
public MStreamConnector( InputStream in_inputStream, OutputStream in_outputStream )
{
inputStream	= in_inputStream;
outputStream	= in_outputStream;
}
//-------------------------------------------------------------------------------------------
public void execute()
{
try
	{
	int received = 0;
	byte[] buffer = new byte[ BUFSIZE ];
	while( true )
		{
		received = inputStream.read( buffer );
		if( received <= 0 )
			{
			break;
			}
		state = RECEIVED;
		notify1();
		
		outputStream.write( buffer, 0, received );
		state = SEND;
		notify1();
		}
	}
catch( IOException e )
	{
	}

closeStreams();
state = CLOSED;
notify1();
}
//-------------------------------------------------------------------------------------------
public void breakCommand()
{
closeStreams();
}
//-------------------------------------------------------------------------------------------
private void closeStreams()
{
try
	{
	inputStream.close();
	}
catch( IOException e )
	{
	e.printStackTrace();
	}
try
	{
	outputStream.close();
	}
catch( IOException e )
	{
	e.printStackTrace();
	}
}
//-------------------------------------------------------------------------------------------
public int getState()
{
return state;
}
//-------------------------------------------------------------------------------------------
public void notify1()
{
subject.notify1();
}
//----------------------------------------------------------------
public void register1( MObserver1 observer )
{
subject.register1( observer );
}
//----------------------------------------------------------------
public void removeObservers1()
{
subject.removeObservers1();
}
//----------------------------------------------------------------
public void removeObserver1( MObserver1 observer )
{
subject.removeObserver1( observer );
}
//----------------------------------------------------------------
}

⌨️ 快捷键说明

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