class EscapeUnescape
{
public static String escape (String src)
{
int i;
char j;
StringBuffer tmp = new StringBuffer();
tmp.ensureCapacity(src.length()*6);
for (i=0;i<src.length() ;i++ )
{
j = src.charAt(i);
if (Character.isDigit(j) || Character.isLowerCase(j) || Character.isUpperCase(j))
tmp.append(j);
else
if (j<256)
{
tmp.append( "%" );
if (j<16)
tmp.append( "0" );
tmp.append( Integer.toString(j,16) );
}
else
{
tmp.append( "%u" );
tmp.append( Integer.toString(j,16) );
}
}
return tmp.toString();
}
public static String unescape (String src)
{
StringBuffer tmp = new StringBuffer();
tmp.ensureCapacity(src.length());
int lastPos=0,pos=0;
char ch;
while (lastPos<src.length())
{
pos = src.indexOf("%",lastPos);
if (pos == lastPos)
{
if (src.charAt(pos+1)=='u')
{
ch = (char)Integer.parseInt(src.substring(pos+2,pos+6),16);
tmp.append(ch);
lastPos = pos+6;
}
else
{
ch = (char)Integer.parseInt(src.substring(pos+1,pos+3),16);
tmp.append(ch);
lastPos = pos+3;
}
}
else
{
if (pos == -1)
{
tmp.append(src.substring(lastPos));
lastPos=src.length();
}
else
{
tmp.append(src.substring(lastPos,pos));
lastPos=pos;
}
}
}
return tmp.toString();
}
public static void main(String[] args)
{
String tmp="~!@#$%^&*()_+|\\=-,. ><;'][{}\"";
System.out.println("testing escape : "+tmp);
tmp =escape(tmp);
System.out.println(tmp);
System.out.println("testing unescape :"+tmp);
System.out.println(unescape(tmp));
}
}
分享到:
相关推荐
java转码 工具类,
java转码工具,可以在GB2312和UTF-8码之间进行转换,很好用的!
java视频上传,转码,截图,播放实现java视频上传,转码,截图,播放实现java视频上传,转码,截图,播放实现
Java 程序转码(UTF-8)Java 据考察,简单易用、。
NULL 博文链接:https://gang-zai.iteye.com/blog/649655
这是一个JAVA乱码的解决代码
java转码amr,jar包
h264转码MP4 支持html5播放格式 示例代码: H264TrackImpl h264TrackImpl = new H264TrackImpl(new FileDataSourceImpl("C://a.264")); Movie movie = new Movie(); movie.addTrack(h264TrackImpl); Container ...
此代码不包含上传视频到oss存储.
Java 视频转码 可以转换视频音频 jar包 官网下载。。
java使用ffmpeg实现视频转码
音频文件转码java开发,基于jave开源技术。 音频文件转码java开发,基于jave开源技术。
JAVA 视频转码FLV 1.视频转化为在线播放格式。 2.支持视频截图。
JAVA视频操作的最常用工具包的linux开发库,支持在linux下java调用ffmpeg进行视频操作、转码、截图等操作。如果你自己编译、寻找库费了很长时间而不成功,那么,希望这个资源能够帮到你。 里面的jar及linux动态库,...
微信互动子弹时间视频转码,清晰度可以自己调整,分享出来给有需要的。
java视频上传,转码,截图,播放实现,包含数据库在里面
YV12,NV21,I420,YUV常用的几个转码方法,java编码。。。。
java读写excel包括utf8转码为可识别汉字gbk,jxl方式读取excel,生成一个新的excel
java -jar "encoding.jar" the first is the directory store your initial files in any encoding style the second is the directory you want to store the new files the third is the encoding name of your ...
ajax转码代码,网页端和Java端的使用方法