- 浏览: 408198 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
holleyangyanges:
name327 写道LZ说句打击你的话, 首先不说Https的 ...
使用httpclient4登录百度 -
holleyangyanges:
,没有登陆成功啊!
使用httpclient4登录百度 -
shenjichao2009:
...
Spring AOP原理解析 -
wuke0210:
[color=red][/color]
CKEditor3.0在asp.net环境下上传文件的配置,集成CKFinder -
wuke0210:
CKEditor3.0在asp.net环境下上传文件的配置,集成CKFinder
本类的主要作用,就是将那些HTML编码后的字符,转回本来对应的字符。尤其适合于一些特殊的符号。大部分以&开头
代码:
import java.util.HashMap;
public class HTMLDecoder {
public static final HashMap charTable;
public static String decode(String s) {
String t;
Character ch;
int tmpPos, i;
int maxPos = s.length();
StringBuffer sb = new StringBuffer(maxPos);
int curPos = 0;
while (curPos < maxPos) {
char c = s.charAt(curPos++);
if (c == '&') {
tmpPos = curPos;
if (tmpPos < maxPos) {
char d = s.charAt(tmpPos++);
if (d == '#') {
if (tmpPos < maxPos) {
d = s.charAt(tmpPos++);
if ((d == 'x') || (d == 'X')) {
if (tmpPos < maxPos) {
d = s.charAt(tmpPos++);
if (isHexDigit(d)) {
while (tmpPos < maxPos) {
d = s.charAt(tmpPos++);
if (!isHexDigit(d)) {
if (d == ';') {
t =
s.substring(
curPos + 2,
tmpPos - 1);
try {
i =
Integer.parseInt(
t,
16);
if ((i >= 0)
&& (i < 65536)) {
c = (char) i;
curPos = tmpPos;
}
} catch (NumberFormatException e) {
}
}
break;
}
}
}
}
} else if (isDigit(d)) {
while (tmpPos < maxPos) {
d = s.charAt(tmpPos++);
if (!isDigit(d)) {
if (d == ';') {
t =
s.substring(
curPos + 1,
tmpPos - 1);
try {
i = Integer.parseInt(t);
if ((i >= 0) && (i < 65536)) {
c = (char) i;
curPos = tmpPos;
}
} catch (NumberFormatException e) {
}
}
break;
}
}
}
}
} else if (isLetter(d)) {
while (tmpPos < maxPos) {
d = s.charAt(tmpPos++);
if (!isLetterOrDigit(d)) {
if (d == ';') {
t = s.substring(curPos, tmpPos - 1);
ch = (Character) charTable.get(t);
if (ch != null) {
c = ch.charValue();
curPos = tmpPos;
}
}
break;
}
}
}
}
}
sb.append(c);
}
return sb.toString();
}
private static boolean isLetterOrDigit(char c) {
return isLetter(c) || isDigit(c);
}
private static boolean isHexDigit(char c) {
return isHexLetter(c) || isDigit(c);
}
private static boolean isLetter(char c) {
return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
}
private static boolean isHexLetter(char c) {
return ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F'));
}
private static boolean isDigit(char c) {
return (c >= '0') && (c <= '9');
}
public static String compact(String s) {
int maxPos = s.length();
StringBuffer sb = new StringBuffer(maxPos);
int curPos = 0;
while (curPos < maxPos) {
char c = s.charAt(curPos++);
if (isWhitespace(c)) {
while ((curPos < maxPos) && isWhitespace(s.charAt(curPos))) {
curPos++;
}
c = '\u0020';
}
sb.append(c);
}
return sb.toString();
}
// HTML is very particular about what constitutes white space.
public static boolean isWhitespace(char ch) {
return (ch == '\u0020')
|| (ch == '\r')
|| (ch == '\n')
|| (ch == '\u0009')
|| (ch == '\u000c')
|| (ch == '\u200b');
}
static {
charTable = new HashMap();
charTable.put("quot", new Character((char)34));
charTable.put("amp", new Character((char)38));
charTable.put("apos", new Character((char)39));
charTable.put("lt", new Character((char)60));
charTable.put("gt", new Character((char)62));
charTable.put("nbsp", new Character((char)160));
charTable.put("iexcl", new Character((char)161));
charTable.put("cent", new Character((char)162));
charTable.put("pound", new Character((char)163));
charTable.put("curren", new Character((char)164));
charTable.put("yen", new Character((char)165));
charTable.put("brvbar", new Character((char)166));
charTable.put("sect", new Character((char)167));
charTable.put("uml", new Character((char)168));
charTable.put("copy", new Character((char)169));
charTable.put("ordf", new Character((char)170));
charTable.put("laquo", new Character((char)171));
charTable.put("not", new Character((char)172));
charTable.put("shy", new Character((char)173));
charTable.put("reg", new Character((char)174));
charTable.put("macr", new Character((char)175));
charTable.put("deg", new Character((char)176));
charTable.put("plusmn", new Character((char)177));
charTable.put("sup2", new Character((char)178));
charTable.put("sup3", new Character((char)179));
charTable.put("acute", new Character((char)180));
charTable.put("micro", new Character((char)181));
charTable.put("para", new Character((char)182));
charTable.put("middot", new Character((char)183));
charTable.put("cedil", new Character((char)184));
charTable.put("sup1", new Character((char)185));
charTable.put("ordm", new Character((char)186));
charTable.put("raquo", new Character((char)187));
charTable.put("frac14", new Character((char)188));
charTable.put("frac12", new Character((char)189));
charTable.put("frac34", new Character((char)190));
charTable.put("iquest", new Character((char)191));
charTable.put("Agrave", new Character((char)192));
charTable.put("Aacute", new Character((char)193));
charTable.put("Acirc", new Character((char)194));
charTable.put("Atilde", new Character((char)195));
charTable.put("Auml", new Character((char)196));
charTable.put("Aring", new Character((char)197));
charTable.put("AElig", new Character((char)198));
charTable.put("Ccedil", new Character((char)199));
charTable.put("Egrave", new Character((char)200));
charTable.put("Eacute", new Character((char)201));
charTable.put("Ecirc", new Character((char)202));
charTable.put("Euml", new Character((char)203));
charTable.put("Igrave", new Character((char)204));
charTable.put("Iacute", new Character((char)205));
charTable.put("Icirc", new Character((char)206));
charTable.put("Iuml", new Character((char)207));
charTable.put("ETH", new Character((char)208));
charTable.put("Ntilde", new Character((char)209));
charTable.put("Ograve", new Character((char)210));
charTable.put("Oacute", new Character((char)211));
charTable.put("Ocirc", new Character((char)212));
charTable.put("Otilde", new Character((char)213));
charTable.put("Ouml", new Character((char)214));
charTable.put("times", new Character((char)215));
charTable.put("Oslash", new Character((char)216));
charTable.put("Ugrave", new Character((char)217));
charTable.put("Uacute", new Character((char)218));
charTable.put("Ucirc", new Character((char)219));
charTable.put("Uuml", new Character((char)220));
charTable.put("Yacute", new Character((char)221));
charTable.put("THORN", new Character((char)222));
charTable.put("szlig", new Character((char)223));
charTable.put("agrave", new Character((char)224));
charTable.put("aacute", new Character((char)225));
charTable.put("acirc", new Character((char)226));
charTable.put("atilde", new Character((char)227));
charTable.put("auml", new Character((char)228));
charTable.put("aring", new Character((char)229));
charTable.put("aelig", new Character((char)230));
charTable.put("ccedil", new Character((char)231));
charTable.put("egrave", new Character((char)232));
charTable.put("eacute", new Character((char)233));
charTable.put("ecirc", new Character((char)234));
charTable.put("euml", new Character((char)235));
charTable.put("igrave", new Character((char)236));
charTable.put("iacute", new Character((char)237));
charTable.put("icirc", new Character((char)238));
charTable.put("iuml", new Character((char)239));
charTable.put("eth", new Character((char)240));
charTable.put("ntilde", new Character((char)241));
charTable.put("ograve", new Character((char)242));
charTable.put("oacute", new Character((char)243));
charTable.put("ocirc", new Character((char)244));
charTable.put("otilde", new Character((char)245));
charTable.put("ouml", new Character((char)246));
charTable.put("divide", new Character((char)247));
charTable.put("oslash", new Character((char)248));
charTable.put("ugrave", new Character((char)249));
charTable.put("uacute", new Character((char)250));
charTable.put("ucirc", new Character((char)251));
charTable.put("uuml", new Character((char)252));
charTable.put("yacute", new Character((char)253));
charTable.put("thorn", new Character((char)254));
charTable.put("yuml", new Character((char)255));
charTable.put("OElig", new Character((char)338));
charTable.put("oelig", new Character((char)339));
charTable.put("Scaron", new Character((char)352));
charTable.put("scaron", new Character((char)353));
charTable.put("fnof", new Character((char)402));
charTable.put("circ", new Character((char)710));
charTable.put("tilde", new Character((char)732));
charTable.put("Alpha", new Character((char)913));
charTable.put("Beta", new Character((char)914));
charTable.put("Gamma", new Character((char)915));
charTable.put("Delta", new Character((char)916));
charTable.put("Epsilon", new Character((char)917));
charTable.put("Zeta", new Character((char)918));
charTable.put("Eta", new Character((char)919));
charTable.put("Theta", new Character((char)920));
charTable.put("Iota", new Character((char)921));
charTable.put("Kappa", new Character((char)922));
charTable.put("Lambda", new Character((char)923));
charTable.put("Mu", new Character((char)924));
charTable.put("Nu", new Character((char)925));
charTable.put("Xi", new Character((char)926));
charTable.put("Omicron", new Character((char)927));
charTable.put("i", new Character((char)928));
charTable.put("Rho", new Character((char)929));
charTable.put("Sigma", new Character((char)931));
charTable.put("Tau", new Character((char)932));
charTable.put("Upsilon", new Character((char)933));
charTable.put("hi", new Character((char)934));
charTable.put("Chi", new Character((char)935));
charTable.put("si", new Character((char)936));
charTable.put("Omega", new Character((char)937));
charTable.put("alpha", new Character((char)945));
charTable.put("beta", new Character((char)946));
charTable.put("gamma", new Character((char)947));
charTable.put("delta", new Character((char)948));
charTable.put("epsilon", new Character((char)949));
charTable.put("zeta", new Character((char)950));
charTable.put("eta", new Character((char)951));
charTable.put("theta", new Character((char)952));
charTable.put("iota", new Character((char)953));
charTable.put("kappa", new Character((char)954));
charTable.put("lambda", new Character((char)955));
charTable.put("mu", new Character((char)956));
charTable.put("nu", new Character((char)957));
charTable.put("xi", new Character((char)958));
charTable.put("omicron", new Character((char)959));
charTable.put("pi", new Character((char)960));
charTable.put("rho", new Character((char)961));
charTable.put("sigmaf", new Character((char)962));
charTable.put("sigma", new Character((char)963));
charTable.put("tau", new Character((char)964));
charTable.put("upsilon", new Character((char)965));
charTable.put("phi", new Character((char)966));
charTable.put("chi", new Character((char)967));
charTable.put("psi", new Character((char)968));
charTable.put("omega", new Character((char)969));
charTable.put("thetasym", new Character((char)977));
charTable.put("upsih", new Character((char)978));
charTable.put("piv", new Character((char)982));
charTable.put("ensp", new Character((char)8194));
charTable.put("emsp", new Character((char)8195));
charTable.put("thinsp", new Character((char)8201));
charTable.put("zwnj", new Character((char)8204));
charTable.put("zwj", new Character((char)8205));
charTable.put("lrm", new Character((char)8206));
charTable.put("rlm", new Character((char)8207));
charTable.put("ndash", new Character((char)8211));
charTable.put("mdash", new Character((char)8212));
charTable.put("lsquo", new Character((char)8216));
charTable.put("rsquo", new Character((char)8217));
charTable.put("sbquo", new Character((char)8218));
charTable.put("ldquo", new Character((char)8220));
charTable.put("rdquo", new Character((char)8221));
charTable.put("bdquo", new Character((char)8222));
charTable.put("dagger", new Character((char)8224));
charTable.put("Dagger", new Character((char)8225));
charTable.put("bull", new Character((char)8226));
charTable.put("hellip", new Character((char)8230));
charTable.put("permil", new Character((char)8240));
charTable.put("prime", new Character((char)8242));
charTable.put("rime", new Character((char)8243));
charTable.put("lsaquo", new Character((char)8249));
charTable.put("rsaquo", new Character((char)8250));
charTable.put("oline", new Character((char)8254));
charTable.put("frasl", new Character((char)8260));
charTable.put("euro", new Character((char)8364));
charTable.put("image", new Character((char)8465));
charTable.put("weierp", new Character((char)8472));
charTable.put("real", new Character((char)8476));
charTable.put("trade", new Character((char)8482));
charTable.put("alefsym", new Character((char)8501));
charTable.put("larr", new Character((char)8592));
charTable.put("uarr", new Character((char)8593));
charTable.put("rarr", new Character((char)8594));
charTable.put("darr", new Character((char)8595));
charTable.put("harr", new Character((char)8596));
charTable.put("crarr", new Character((char)8629));
charTable.put("lArr", new Character((char)8656));
charTable.put("uArr", new Character((char)8657));
charTable.put("rArr", new Character((char)8658));
charTable.put("dArr", new Character((char)8659));
charTable.put("hArr", new Character((char)8660));
charTable.put("forall", new Character((char)8704));
charTable.put("part", new Character((char)8706));
charTable.put("exist", new Character((char)8707));
charTable.put("empty", new Character((char)8709));
charTable.put("nabla", new Character((char)8711));
charTable.put("isin", new Character((char)8712));
charTable.put("notin", new Character((char)8713));
charTable.put("ni", new Character((char)8715));
charTable.put("prod", new Character((char)8719));
charTable.put("sum", new Character((char)8721));
charTable.put("minus", new Character((char)8722));
charTable.put("lowast", new Character((char)8727));
charTable.put("radic", new Character((char)8730));
charTable.put("prop", new Character((char)8733));
charTable.put("infin", new Character((char)8734));
charTable.put("ang", new Character((char)8736));
charTable.put("and", new Character((char)8743));
charTable.put("or", new Character((char)8744));
charTable.put("cap", new Character((char)8745));
charTable.put("cup", new Character((char)8746));
charTable.put("int", new Character((char)8747));
charTable.put("there4", new Character((char)8756));
charTable.put("sim", new Character((char)8764));
charTable.put("cong", new Character((char)8773));
charTable.put("asymp", new Character((char)8776));
charTable.put("ne", new Character((char)8800));
charTable.put("equiv", new Character((char)8801));
charTable.put("le", new Character((char)8804));
charTable.put("ge", new Character((char)8805));
charTable.put("sub", new Character((char)8834));
charTable.put("sup", new Character((char)8835));
charTable.put("nsub", new Character((char)8836));
charTable.put("sube", new Character((char)8838));
charTable.put("supe", new Character((char)8839));
charTable.put("oplus", new Character((char)8853));
charTable.put("otimes", new Character((char)8855));
charTable.put("perp", new Character((char)8869));
charTable.put("sdot", new Character((char)8901));
charTable.put("lceil", new Character((char)8968));
charTable.put("rceil", new Character((char)8969));
charTable.put("lfloor", new Character((char)8970));
charTable.put("rfloor", new Character((char)8971));
charTable.put("lang", new Character((char)9001));
charTable.put("rang", new Character((char)9002));
charTable.put("loz", new Character((char)9674));
charTable.put("spades", new Character((char)9824));
charTable.put("clubs", new Character((char)9827));
charTable.put("hearts", new Character((char)9829));
charTable.put("diams", new Character((char)9830));
}
}
相关问题:http://topic.csdn.net/u/20080130/01/8402ba64-d71b-4bac-b5be-81fc2958ba78.html
发表评论
-
Eclipse很卡的解决方法
2016-04-13 15:03 572配置eclipse.ini文件,可以根据内存大小视情况而定 ... -
shell 跟java 相互调用和获取结果
2011-11-08 15:16 3044被调用的shell a.sh #!/bin/bash e ... -
关于日文编码(Shift_JIS Windows-31 EUC-JP)
2011-03-02 09:50 157081、常用编码 日语的文字编码主要是Shift_JIS、EUC ... -
ITEXT 使用小结
2010-07-21 15:13 1635最近项目中使用到IText5,其实跟之前版本并无特殊差别, ... -
Java 1.5 小手册 Cheat Sheet
2009-12-26 19:07 1085Create a new object instance S ... -
SpringSide 3.2.1 寒冬日志版发布
2009-12-24 22:54 1228最近国内的开源项目非常生猛,与Play!Framework有 ... -
使用HttpComponents获取整个页面的内容
2009-12-14 11:52 2731commons-httpclient已经不再更新了, htt ... -
如何优化JAVA程序开发,提高JAVA性能
2009-12-01 13:35 1053通过使用一些辅助性工具来找到程序中的瓶颈,然后就可以对瓶颈部分 ... -
weblogic11集群之建立节点信任
2009-11-24 14:56 21741、管理server和被管server的domain名字必须一 ... -
体验一下JBOSSESB The Hello World QuickStart
2009-11-16 17:26 16741)跑到 http://www.jboss.org/jboss ... -
过滤器中向所有JSP页面插入html代码
2009-10-28 16:06 2380为公司内部开发了1个简单的MVC框架,框架中需要向所有JSP页 ... -
GlassFish替换Tomcat
2009-09-29 09:34 12191. GlassFish替换Tomcat背景 ... -
禁止apache和tomcat列出目录清单的方法
2009-09-28 16:49 2230如果用户uri中没有指定文件名,apache和tomcat在默 ... -
关于apache和tomcat的连接器
2009-09-28 16:28 1486mod_jk2确实很烂。 几天的mod_jk2的云山雾罩之后 ... -
Linux下Tomcat与Apache Web服务器的整合
2009-09-28 16:21 10471、引言 基 ... -
有关使用和部署 Java 持久性体系结构 (JPA) 的案例研究
2009-04-24 17:19 11122006 年夏天发布的 EJB 3 ... -
Spring AOP原理解析
2009-04-24 15:07 10284AOP概念: 实现AOP有两种 ... -
spring aop的原理
2009-04-24 15:06 2813AOP概念 让我们从定义一些重要的AOP概念开始。 — 方 ... -
struts2的struts.properties配置文件详解
2009-04-23 16:34 998struts.action.extension ... -
详解JRE和JDK的区别
2009-02-04 11:07 1441JDK JDK 是整个Java的核心,包括了Java运行环境 ...
相关推荐
在IT行业中,编码和解码是数据处理的重要环节,特别是在JavaScript和Java这两种广泛使用的编程语言中。本文将深入探讨“js解码”和“java编码”这两个主题,并结合标签“源码”和“工具”,讨论如何在实际项目中应用...
例如,使用 String classpath = StaticUtils.class.getResource("/").getPath().replaceFirst("/", "") 语句来获取类路径,然后使用 URLDecoder.decode(classpath, "utf-8") 语句来解码 URL。 异常处理 异常处理是...
`Android-js-htmlencode`正是这样一个工具,它提供了一个JavaScript类,使得在Android应用中进行HTML编码和解码变得简单易行。 首先,我们要理解HTML编码的重要性。HTML编码主要是为了避免浏览器将某些字符解释为...
java.nio.charset 定义用来在字节和 Unicode 字符之间转换的 charset、解码器和编码器。 java.nio.charset.spi java.nio.charset 包的服务提供者类。 java.rmi 提供 RMI 包。 java.rmi.activation 为 RMI 对象...
《Apache Commons Lang 3.1:Java HTML解码组件库》 Apache Commons Lang 是一个由Apache软件基金会开发的Java库,它提供了大量的实用工具类,用于扩展Java的标准库。在这个特定的版本——"commons-lang3-3.1.jar....
在Java 8及更高版本中,Java引入了`java.util.Base64`类,提供了方便的Base64编码和解码API。以下是一些关键的方法: 1. `encodeBytes(byte[] input)`:将字节数组进行Base64编码,返回一个包含编码结果的字符串。 ...
/** * 封装各种格式的编码解码工具类. * 1.Commons-Codec的 hex/base64 编码 * 2.自制的base62 编码 * 3.Commons-Lang的xml/html escape * 4.JDK提供的URLEncoder */
一个对chunked编码进行解码的例子,通过java socket实现发送http请求,对gzip压缩的消息体进行解码处理。
综上所述,这个项目融合了多个高级IT技术,展示了如何在Java环境中集成FFmpeg和JavaCV来实现复杂的实时视频处理功能,同时利用RTSP协议和WebSocket提供无控件的HTML5视频预览和录像服务。这样的技术组合在物联网、...
Java二进制IO类与文件复制操作实例,好像是一本书的例子,源代码有的是独立运行的,与同目录下的其它代码文件互不联系,这些代码面向初级、中级Java程序员。 Java访问权限控制源代码 1个目标文件 摘要:Java源码,...
### Java中的常用编码解码方法 在Java编程中,数据编码和解码是十分重要的环节,尤其是在处理中文或特殊字符时。本文将详细介绍Java中与编码解码相关的几个关键概念和方法,帮助开发者更好地理解并解决编码问题。 ...
在这个HTML浏览器项目中,工具类可能包含了与解析、渲染HTML页面相关的辅助函数,或者是用来处理网络请求和数据解码的代码。 "codefans.net" 这个文件名可能是项目的源代码文件夹,其中包含了整个HTML浏览器项目的...
然后,可以使用Java的`javax.imageio.ImageIO`类将字节数组保存为本地文件或上传至云存储服务。以下是一个简化的Servlet处理逻辑: ```java import javax.imageio.ImageIO; import javax.servlet.ServletException;...
通过以上步骤,我们可以编写一个Java程序,读取CHM文件,解码其内容,解析HTML,生成新的HTML文件,并保存到本地。这个过程可能涉及到对CHM结构的理解、使用特定库的API,以及处理文件I/O和异常的技巧。对于需要处理...
如何在Java程序中利用正则表达式实现对字符串的解析.另外,HTMLParser是一款很强大的对HTML网页进行解析的工具,其中大量地用到正则表达式.
h264转码MP4 支持html5播放格式 示例代码: H264TrackImpl h264TrackImpl = new H264TrackImpl(new FileDataSourceImpl("C://a.264")); Movie movie = new Movie(); movie.addTrack(h264TrackImpl); Container ...
java.nio.charset 定义用来在字节和 Unicode 字符之间转换的 charset、解码器和编码器。 java.nio.charset.spi java.nio.charset 包的服务提供者类。 java.rmi 提供 RMI 包。 java.rmi.activation 为 RMI 对象激活...
- MD5编码:展示如何使用编程语言(如Python、Java、JavaScript等)计算一个字符串或文件的MD5哈希值,并将其输出。 - MD5解码:虽然MD5是单向哈希,不能直接解码回原始数据,但可能包含验证MD5哈希值与预知值是否...
在Java后端,我们可以使用Zxing的`Reader`接口和`DecodeHintType`来设置解码提示,然后调用`decode`方法解析图像中的二维码。 4. **HTML5的Canvas元素**: HTML5的Canvas API提供了在网页上动态绘制图形的能力。在...
本文详细介绍了使用Java解析MHT文件的基本原理和技术实现,包括如何提取HTML内容、解码Quoted-Printable编码、构建DOM树以及提取所需数据。这对于需要处理MHT文件的应用开发具有很高的参考价值。