mresultwriter.java

来自「httptunnel.jar httptunnel java 源码」· Java 代码 · 共 73 行

JAVA
73
字号
package net.jumperz.app.MRemedy;

import java.util.*;
import java.io.*;
import net.jumperz.util.*;

public class MResultWriter
extends MSingleThreadCommand
{
private static final MResultWriter instance = new MResultWriter();

private int lastIndex = -1;
private Map indexResultMap = new HashMap();
//--------------------------------------------------------------------------------
public static MResultWriter getInstance()
{
return instance;
}
//--------------------------------------------------------------------------------
private MResultWriter()
{
mutex = new Object();
}
//--------------------------------------------------------------------------------
public void execute2()
{
while( true )
	{
	Integer nextIndex = new Integer( lastIndex + 1 );
	if( indexResultMap.containsKey( nextIndex ) )
		{
		try
			{
			System.out.write( ( ( String )indexResultMap.get( nextIndex ) ).getBytes( MCharset.CS_ISO_8859_1 ) );		
			System.out.write( 0x0A );
			}
		catch( IOException e )
			{
			e.printStackTrace();
			}

		lastIndex++;

		synchronized( indexResultMap )
			{
			indexResultMap.remove( nextIndex );
			}
		}
	else
		{
		break;
		}
	}
}
//--------------------------------------------------------------------------------
public void putResult( Integer index, String result )
{
synchronized( indexResultMap )
	{
	indexResultMap.put( index, result );
	}

synchronized( mutex )
	{
	mutex.notify();
	}
}
//--------------------------------------------------------------------------------
public void breakCommand()
{
}
//--------------------------------------------------------------------------------
}

⌨️ 快捷键说明

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