?? mstreamconnector.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 + -