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

📄 urldecoder.java

📁 基于人工免疫原理的入侵检测系统框架
💻 JAVA
字号:
/*================= * Copyright (C) 2001  The University of New Mexico. All Rights Reserved.  * * Lisys is a program that monitors TCP SYN packets to detect network * traffic anomalies. * * Licensed under the GNU General Public License (GPL), version 2 or * higher.  Please see the COPYING and PATENT files included with the * Lisys distribution, which can be found at: * *   http://www.cs.unm.edu/~judd/lisys/ * * Also, the current text of the GPL can be found at:  * *   http://www.gnu.org/copyleft/gpl.html *  * Note that Lisys has NO WARRANTY! *=================*/package edu.unm.cs.lisys.net;/**========== * URLDecoder.java *   Since java 1.1 doesn't have the URLDecoder (this appears in java *   1.2), we have written an equivalent. * *   The class contains one static function, used to decode URLs encoded *   by java.net.URLEncoder. *   @see java.net.URLEncoder * * Here are the people who have worked on this code in the order they * have worked on it: *   @author Hajime Inoue <hinoue@cs.unm.edu> *   @author Justin Balthrop <judd@cs.unm.edu> *==========*/public class URLDecoder{    /**==========     * decode:     *   When given an encoded URL as a string, it decodes it.     *      * @param url the URL to be decoded     * @return the decoded URL     *==========*/    public static String decode(String url)    {	StringBuffer sb = new StringBuffer();		for(int i=0; i < url.length(); i++) {	    int val = (int)url.charAt(i);	    if ( (val >= 'a' && val <= 'z') ||		 (val >= 'A' && val <= 'Z') ||		 (val >= '0' && val <= '9') ||		 (val == '&') || (val == '.') ||		 (val == '/') || (val == '_') ||		 (val == '?') ) {		sb.append((char)val);	    }	    else if ( val == '+') {		sb.append(' ');	    }	    else if ( val == '%') {		char first = url.charAt(i+1);		char second = url.charAt(i+2);				val = hex(first, second);		sb.append((char)val);		i = i+2;	    }	}	return sb.toString();    }	    /**==========     * hex:     *	 Utility function used to calculate hex values from two     *	 characters.  For instance, if you have the value 20 in HEX,     *	 it will return the value 32 in DECIMAL.     *     * @param first the first char in hex representation     * @param second the second char in hex representation     * @return the decimal value of the two chars as an integer      *==========*/	    protected static int hex(char first, char second)    {	int x, y;		x = (int)first;	y = (int)second;		// To upper case	if ( x > 71 ) x = x - 32;	if ( y > 71 ) y = y - 32;		if ( x > 57 ) x = 16 * ( x - 55);	else x = 16 * ( x - 48);	if ( y > 57 ) y = y - 55;	else y = y - 48;		return x + y;    }}

⌨️ 快捷键说明

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