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

📄 rrdtoolgraph.java

📁 httptunnel.jar httptunnel java 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			graphDef.line( ds, color, legend, w );
		}
		else
		{
			if ( type == GRAPH_STACK )
				token	= token.substring( 6 );
			else
				token	= token.substring( 5 );

			int pos		= token.indexOf( '#' );
			int npos	= token.indexOf( ':' );

			String ds		= ( pos > 0 ? token.substring( 0, pos ) : token.substring( 0 ) );
			Color color		= null;
			String legend	= null;

			// Get the color
			if ( pos > 0 && token.charAt(pos) == '#' )
				color	= Color.decode(  npos > 0 ? token.substring( pos, npos ) : token.substring( pos ) );

			// Get the legend (if there is one)
			if ( npos > 0 )
				legend	= unescape( token.substring( npos + 1 ) );

			if ( type == GRAPH_AREA )
				graphDef.area( ds, color, legend );
			else if ( type == GRAPH_STACK )
				graphDef.stack( ds, color, legend );
		}
	}

	/**
	 *
	 * @param text
	 * @return
	 */
	private String unescape( String text )
	{
		if ( text.startsWith( "'" ) || text.startsWith( "\"" ) )
			return text.substring( 1, text.length() - 1 );

		return text;
	}

	/**
	 *
	 * @param type
	 * @throws RrdException
	 */
	private void parseTextCommand( int type ) throws RrdException
	{
		int pos	= token.indexOf( ':' );

		if ( type == TXT_COMMENT )
		{
			String text	= unescape( token.substring( pos + 1 ) );

			graphDef.comment( text );
		}
		else if ( type == TXT_GPRINT )
		{
			// GPRINT:vname:CF:format
			int npos	= token.indexOf( ':', ++pos );

			String ds	= token.substring( pos, npos );
			pos			= token.indexOf( ':', ++npos );

			String cf	= token.substring( npos, pos );
			String text	= unescape( token.substring( pos + 1 ) );

			// Change the placeholder to JRobin
			//graphDef.gprint( ds, cf, text );
		}
	}

	/**
	 *
	 * @param type
	 * @throws RrdException
	 */
	private void parseDatasource( int type ) throws RrdException
	{
		// Fetch the name of the datasource
		int pos		= token.indexOf( ':' );
		int npos	= token.indexOf( '=', ++pos );

		String name	= token.substring( pos, npos );

		if ( type == DS_DEF )
		{
			// DEF:vname=rrd:ds-name:CF
			token			= token.substring( npos + 1 );

			// Fetch reverse
			pos				= token.lastIndexOf( ':' );
			String cf		= token.substring( pos + 1 );

			npos			= token.lastIndexOf( ':', pos - 1 );
			String dsName	= token.substring( npos + 1, pos );
			String rrdFile	= token.substring( 0, npos );

			graphDef.datasource( name, rrdFile, dsName, cf );
		}
		else
		{
			// CDEF:vname=rpn-expression
			graphDef.datasource( name, token.substring( npos + 1 ) );
		}
	}

	/**
	 * Reads the next token in the rrdtool script.
	 *
	 * @return
	 */
	private int nextToken()
	{
		char[] tknChars 		= new char[512];
		int charPos 			= 0;
		int cmdPos				= tokenPos;
		boolean found			= false;

		boolean stringComplete 	= true;
		char findChar			= ' ';

		/*
		 * This will read from the current position, till the next whitespace.
		 * However, if it encounters a " or a ' that is not escaped, it will read until the next matching character.
		 */
		while ( charPos < 512 && (cmdPos < parseCmd.length) && !found )
		{
			if ( parseCmd[cmdPos] == '"' )
			{
				if ( stringComplete ) {
					stringComplete 	= false;
					findChar		= '"';
				}
				else if ( findChar == '"' && !(parseCmd[cmdPos - 1] == '\\') )
					stringComplete	= true;
			}
			else if ( parseCmd[cmdPos] == '\'' )
			{
				if ( stringComplete ) {
					stringComplete 	= false;
					findChar		= '\'';
				}
				else if ( findChar == '\'' && !(parseCmd[cmdPos - 1] == '\\') )
					stringComplete	= true;
			}
			if ( stringComplete && parseCmd[cmdPos] == ' ' )
				found = true;
			else
				tknChars[charPos++] = parseCmd[cmdPos++];
		}

		token 	= new String( tknChars, 0, charPos ).trim();

		tokenPos = cmdPos + 1;

		return charPos;
	}

	/**
	 *
	 * @param token
	 * @return
	 */
	private int parseToken( String token )
	{
		if ( token.equalsIgnoreCase("rrdtool") )
			return TKN_RRDTOOL;

		if ( token.equalsIgnoreCase("graph") )
			return TKN_GRAPH;

		if ( token.equalsIgnoreCase("--start") || token.equals("-s") )
			return TKN_START;

		if ( token.equalsIgnoreCase("--end") || token.equals("-e") )
			return TKN_END;

		if ( token.equalsIgnoreCase("--width") || token.equals("-w") )
			return TKN_WIDTH;

		if ( token.equalsIgnoreCase("--height") || token.equals("-h") )
			return TKN_HEIGHT;

		if ( token.equalsIgnoreCase("--no-minor") )
			return TKN_NOMINOR;

		if ( token.equalsIgnoreCase("--units-exponent") || token.equals("-X") )
			return TKN_UNITS_EXP;

		if ( token.equalsIgnoreCase("--vertical-label") || token.equals("-v") )
			return TKN_VERT_LABEL;

		if ( token.equalsIgnoreCase("--imgformat") || token.equals("-a") )
			return TKN_IMGFORMAT;

		if ( token.equalsIgnoreCase("--background") || token.equals("-B") )
			return TKN_BACKGROUND;

		if ( token.equalsIgnoreCase("--overlay") || token.equals("-O") )
			return TKN_OVERLAY;

		if ( token.equalsIgnoreCase("--title") || token.equals("-t") )
			return TKN_TITLE;

		if ( token.equalsIgnoreCase("--step") || token.equals("-S") )
			return TKN_STEP;

		if ( token.equalsIgnoreCase("--no-legend") || token.equals("-g") )
			return TKN_NOLEGEND;

		if ( token.equalsIgnoreCase("--base") || token.equals("-b") )
			return TKN_BASE;

		if ( token.equalsIgnoreCase("--lower-limit") || token.equals("-l") )
			return TKN_LOWERLIMIT;

		if ( token.equalsIgnoreCase("--upper-limit") || token.equals("-u") )
			return TKN_UPPERLIMIT;

		if ( token.equalsIgnoreCase("--rigid") || token.equals("-r") )
			return TKN_RIGID;

		if ( token.startsWith("COMMENT") )
			return TKN_COMMENT;

		if ( token.startsWith("GPRINT") )
			return TKN_GPRINT;

		if ( token.startsWith("LINE") )
			return TKN_LINE;

		if ( token.startsWith("AREA") )
			return TKN_AREA;

		if ( token.startsWith("STACK") )
			return TKN_STACK;

		if ( token.startsWith("HRULE") )
			return TKN_HRULE;

		if ( token.startsWith("VRULE") )
			return TKN_VRULE;

		if ( token.startsWith("CDEF") )
			return TKN_CDEF;

		if ( token.startsWith("DEF") )
			return TKN_DEF;

		if ( token.equals("-Y") || token.equals("--alt-y-grid")	|| token.equals("-R") || token.equals("--alt-y-mrtg")
								|| token.equals("-A") || token.equals("--alt-autoscale") || token.equals("-M")
								|| token.equals("--alt-autoscale-max") || token.equals("-L")
								|| token.equals("--units-length") || token.equals("-i") || token.equals("--interlaced")
								|| token.equals("-f") || token.equals("--imginfo") || token.equals("-o")
								|| token.equals("--logarithmic") || token.equals("-j") || token.equals("--only-graph")
								|| token.equals("-F") || token.equals("--force-rules-legend") || token.startsWith("PRINT")
								|| token.equals("-U") || token.startsWith("--unit") )
			return TKN_IGNORE;

		return TKN_UNKNOWN;
	}


	public static void main( String[] args ) throws Exception
	{
		String str = "rrdtool graph FNAME --start 100 --end 700\n"
					+ "DEF:inOctets=c:/file.rrd:test-run:AVERAGE "
					+ "CDEF:bitIn=inOctets,8,* "
					+ "COMMENT:'commentaar \"nr\" 1'\n"
					+ "AREA:test#ffa9b3:'this is the legend'\n"
					+ "COMMENT:\"commentaar 'nr' 2\"\n"
					+ "LINE2:test2:'this is the legend two' "
					+ "GPRINT:bitIn:AVG:'Average %2.5'";

		RrdtoolGraph rg = new RrdtoolGraph( str );

		rg.getRrdGraphDef();
	}
}

⌨️ 快捷键说明

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