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

📄 mloggerfactory.java

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

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

public class MLoggerFactory
{
//--------------------------------------------------------------------------------
public static List load( String configFileName )
throws IOException
{
/*
<logger>
fileName=work/bitdog/access
pattern=[^:]{1,}:[0-9]
condition=match
case_sensitive=yes
type=size
rotate=104857600
eat=yes
suffix=0000
command=/bin/gzip
</logger>
*/
BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream( configFileName ), MCharset.CS_ISO_8859_1 ) );

String line = null;
String fileName = null;
String patternStr = null;
String conditionStr = null;
String caseSensitiveFlagStr = null;
String type = null;
String rotateStr = null;
String eatFlagStr = null;
String suffix = null;
String command = null;
boolean negationFlag;
boolean caseSensitiveFlag;
boolean eatFlag = false;
int rotate = 0;

List loggerList = new ArrayList();

for( int lineNumber = 1; ; ++lineNumber )
	{
	line = reader.readLine();
	if( line == null )
		{
		break;
		}
	if( line.equalsIgnoreCase( "<logger>" ) )
		{
		if( fileName			!= null
		 || patternStr			!= null
		 || conditionStr		!= null
		 || caseSensitiveFlagStr	!= null
		 || type			!= null
		 || rotateStr			!= null
		 || eatFlagStr			!= null
		 || suffix			!= null
		 || command			!= null
		 || rotate			!= 0
		  )
			{
			throwParseError( configFileName, lineNumber );
			}
		}
	else if( line.equalsIgnoreCase( "</logger>" ) )
		{
		if( fileName			== null
		 || patternStr			== null
		 || conditionStr		== null
		 || caseSensitiveFlagStr	== null
		 || type			== null
		 || rotateStr			== null
		 || eatFlagStr			== null
		 || suffix			== null
		 || command			== null
		 || rotate			== 0
		  )
			{
			throwParseError( configFileName, lineNumber );
			}

			// start construction
		MAbstractLogger logger = null;
		if( type.equalsIgnoreCase( "size" ) )
			{
			logger = new MSizeLogger();
			}
		else if( type.equalsIgnoreCase( "line" ) )
			{
			logger = new MLineLogger();
			}
		else if( type.equalsIgnoreCase( "null" ) )
			{
			logger = new MNullLogger();
			}
		else
			{
			throwParseError( configFileName, lineNumber );
			}
		
		eatFlag = ( eatFlagStr.equalsIgnoreCase( "YES" ) );
		caseSensitiveFlag = ( caseSensitiveFlagStr.equalsIgnoreCase( "YES" ) );
		negationFlag = ( conditionStr.equalsIgnoreCase( "NOT MATCH" ) );
		
		logger.setFileName( fileName );
		logger.setPattern( patternStr, !caseSensitiveFlag );
		logger.setNegationFlag( negationFlag );
		logger.setRotate( rotate );
		logger.setCommand( command );
		logger.setEat( eatFlag );
		logger.setSuffix( suffix );
		
		loggerList.add( logger );
		
		fileName		= null;
		patternStr		= null;
		conditionStr		= null;
		caseSensitiveFlagStr	= null;
		type			= null;
		rotateStr		= null;
		eatFlagStr		= null;
		suffix			= null;
		command			= null;
		rotate			= 0;
		}
	else if( line.indexOf( "fileName" ) == 0 )
		{
		if( fileName != null )
			{
			throwParseError( configFileName, lineNumber );
			}
		fileName = getParam( line, "fileName=" );
		}
	else if( line.indexOf( "pattern" ) == 0 )
		{
		if( patternStr != null )
			{
			throwParseError( configFileName, lineNumber );
			}
		patternStr = getParam( line, "pattern=" );
		}
	else if( line.indexOf( "condition" ) == 0 )
		{
		if( conditionStr != null )
			{
			throwParseError( configFileName, lineNumber );
			}
		conditionStr = getParam( line, "condition=" );
		}
	else if( line.indexOf( "case_sensitive=" ) == 0 )
		{
		if( caseSensitiveFlagStr != null )
			{
			throwParseError( configFileName, lineNumber );
			}
		caseSensitiveFlagStr = getParam( line, "case_sensitive=" );
		}
	else if( line.indexOf( "type=" ) == 0 )
		{
		if( type != null )
			{
			throwParseError( configFileName, lineNumber );
			}
		type = getParam( line, "type=" );
		}
	else if( line.indexOf( "rotate=" ) == 0 )
		{
		if( rotate != 0 )
			{
			throwParseError( configFileName, lineNumber );
			}
		rotateStr = getParam( line, "rotate=" );
		rotate = Integer.parseInt( rotateStr );
		/*
		if( rotate < 1 )
			{
			throwParseError( configFileName, lineNumber );
			}
		*/
		}
	else if( line.indexOf( "command=" ) == 0 )
		{
		if( command != null )
			{
			throwParseError( configFileName, lineNumber );
			}
		command = getParam( line, "command=" );
		}
	else if( line.indexOf( "eat=" ) == 0 )
		{
		if( eatFlagStr != null )
			{
			throwParseError( configFileName, lineNumber );
			}
		eatFlagStr = getParam( line, "eat=" );
		}
	else if( line.indexOf( "suffix=" ) == 0 )
		{
		if( suffix != null )
			{
			throwParseError( configFileName, lineNumber );
			}
		suffix = getParam( line, "suffix=" );
		/*
		if( !suffix.matches( "^0{1,}$" ) )
			{
			throwParseError( configFileName, lineNumber );			
			}
		*/
		}
	}

return loggerList;
}
//--------------------------------------------------------------------------------------
private static String getParam( String line, String paramName )
{
return line.substring( paramName.length() );
}
//--------------------------------------------------------------------------------------
private static void throwParseError( String configFileName, int lineNumber )
throws IOException
{
throw new IOException( "Parse error. " + configFileName + " line: " + lineNumber );
}
//--------------------------------------------------------------------------------
}

⌨️ 快捷键说明

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