java编程字符串镜像串实现一个方法,能把一个字符串src的右侧出现的第一个olds子串替换为news,并把替换后的结果返回

本篇对一些常用的java知识做一个整合,三大特性、IO操作、线程处理、类集处理,目的在于能用这些只是实现一个网页爬虫的功能。
Ⅰ  首先对于一个java开发的项目有一个整体性的了解认知,项目开发流程:
项目阶段:
1)&项目准备:
  a)&根据开会得到会议纪要,了解客户的需求情况
  b)&需求分析(需求分析文档)
  c)&数据库设计和网站(产品)原型设计
  d)&架构设计
2)&项目开发
  a)&项目组长(PM,PL)进行项目的时间规划,并划分好每个人的工作任务
  b)&程序员主要完成项目代码编写和详细设计文档编写。(用户手册)
  a)&单元测试
  b)&集成测试
  c)&压力测试
  d)&回归测试
4)&上线实施
Ⅱ  三大特性(封装、继承、多态)
1、  封装重点在于一个private关键字,目的是为了让类中的属性不能直接修改或取得。也就是说,建立一个类时,所有的属性都必须通过private进行封装。
      既然属性被封装了,那么如果想设置或取得属性,就必须编写getter/setter方法。
      同时,类中在创建对象时,为了方便,一般建议编写一些带参数的构造方法。
      如果不编写构造方法,程序会自动加入一个无参的构造,但是,如果自己声明了构造方法,那么必须就手工加入一个无参构造,为了让其他的框架可以通过无参数构造来创建对象。
2、  如果数据库中有一张表,则需要你能根据表编写一个这样的类。
      这种类被称为:VO(Value Object)、TO(Transfer Object)、POJO(Plain Olds Java Object)、DTO(DaTa Object)等
1 class Person {
public Person() {
public Person(String name, Integer age) {
this.name =
this.age =
<span style="color: #
public String getName() {
<span style="color: #
return this.
<span style="color: #
<span style="color: #
public Integer getAge() {
<span style="color: #
<span style="color: #
<span style="color: #
public void setAge(Integer age) {
<span style="color: #
this.age =
<span style="color: #
<span style="color: #
public void setName(String name) {
<span style="color: #
this.name =
<span style="color: #
<span style="color: # }
技巧:在eclipse中编写封装类,可以声明变量后,按shift+Alt+s键出现Generate &Getters &and &Setters提示创建getter和setter方法。
继承所使用的关键字:extends,接口实现所使用的关键字是:implements。
Java开发中对于接口和抽象类区别主要是单继承和多继承。
真正开发中接口用的更多,几乎不编写抽象类。
一般都是以接口作为标准来进行声明。
这部分我们要求能够掌握接口的声明和实现方法。
1 interface Animal {
public void cry();
public void run();
5 class Cat implements Animal {
public void cry() {
System.out.println("miao");
<span style="color: #
<span style="color: #
<span style="color: #
public void run() {
<span style="color: #
System.out.println("猫爬树");
<span style="color: #
<span style="color: # }
其实就是在继承的基础上进行方法覆写和子类转型。
1 package org.liky.
2 public class InterfaceDemo {
public static void main(String[] args) {
Animal a1 = new Cat();
Animal a2 = new Dog();
<span style="color: # interface Animal {
<span style="color: #
public void cry();
<span style="color: #
public void run();
<span style="color: # }
<span style="color: # class Cat implements Animal {
<span style="color: #
<span style="color: #
public void cry() {
<span style="color: #
System.out.println("miao");
<span style="color: #
<span style="color: #
<span style="color: #
public void run() {
<span style="color: #
System.out.println("猫爬树");
<span style="color: #
<span style="color: # }
<span style="color: # class Dog implements Animal {
<span style="color: #
<span style="color: #
public void cry() {
<span style="color: #
System.out.println("Wang");
<span style="color: #
<span style="color: #
<span style="color: #
public void run() {
<span style="color: #
System.out.println("狗游泳");
<span style="color: #
<span style="color: # }
单例设计模式
单例模式有以下特点:
  1、单例类只能有一个实例。
  2、单例类必须自己创建自己的唯一实例。
  3、单例类必须给所有其他对象提供这一实例。
package org.liky.
public class TestSingleton {
public static void main(String[] args) {
Singleton s1 = Singleton.getInstance();
Singleton s2 = Singleton.getInstance();
Singleton s3 = Singleton.getInstance();
//其实只创建了一个对象
System.out.println(s1 + " --& " + s2 + " --& " + s3);
class Singleton {
private static final Singleton instance = new Singleton();
private Singleton() {
public static Singleton getInstance() {
Ⅲ  IO操作
文件内容读取:
File、FileReader、FileWriter、BufferedReader、BufferedWriter、Scanner、InputStreamReader
文件夹遍历:
文件复制操作
如果想操作文件的内容(对内容进行写出和读取),需要使用到的就是IO流中的输入输出操作。
这种输入和输出的操作流有两种:
1)&字符流:主要操作文本文件(编写爬虫操作时,肯定要使用字符流来完成)
a)&读:FileReader
b)&写:FileWriter
2)&字节流:所有文件都可以使用这种流操作
a)&读:InputStream
b)&写:OutputStream
需要能够通过我们这里的FileReader和FileWriter配合文件类:File,完成内容的读取和写出。
* IO流操作的演示类,用来演示文本文件的写出和读取
* @author Liky
public class FileTest {
public static void main(String[] args) {
// 写出内容
// writeData(
// "D:/test.txt",
// "这是“吉林一号”视频卫星 8月9日11时25分拍摄的 九寨沟县视频 显示了九寨沟县的地形地貌 县城呈狭长分布 周边山体有明显滑坡痕迹 视频中还可见县城道路大部分完好 有车辆通行 一架飞机飞过 地面与空中交通并未中断 图像提供:长光卫星技术有限公司 技术支持:北京爱太空科技发展有限公司");
System.out.println(readData("D:/test.txt"));
* 写出数据
* @param filePath
文件保存的位置
* @param data
要保存的文件内容数据
public static void writeData(String filePath, String data) {
// 先有一个文件,来保存要写出的数据
File file = new File(filePath);
// 建立输出流对象
FileWriter writer = new FileWriter(file);
// 开始完成内容的输出
writer.write(data);
// 资源必须回收,也就是必须将流关闭
writer.close();
} catch (IOException e) {
e.printStackTrace();
* 读取数据
* @param filePath
要读取的文件所在的完整路径
* @return 读取出来的文档内容
public static String readData(String filePath) {
// 也要建立文件对象
File file = new File(filePath);
// 建立读取的输入流对象
FileReader reader = new FileReader(file);
// 每次调用read可以读取一个字符,
// 按照int类型返回,返回的是字符的编码,
// 需要通过强制类型转换,变为char类型
// Java中对于String这个类一般不建议反复修改,因为会占用内存。
StringBuilder builder = new StringBuilder();
// 因为文件中有很多的字符,因此需要循环来进行内容的读取。
// 就需要判断是否还有字符进行读取
int value = -1;
// 每次读取时,如果读到内容,则会返回 0 - 65535 的char类型字符
// 如果没有读取到内容,则返回 -1 ,因此我们可以根据这个 -1 来判断后面是否还有内容
while ((value = reader.read()) != -1) {
// 将读取到的内容保存下来
char c = (char)
// 把字符放入到StringBuilder里
builder.append(c);
// 没有读取到内容,说明循环结束,已经到了文件的末尾
return builder.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
目前这样编写已经可以实现内容的输入和输出操作了。
但是还不支持换行操作,如果想换行,需要人工进行\r\n的编写。
如果不想人工编写换行,就可以使用以下两个类来完成输入。
PrintWriter(打印流)
BufferedWriter(缓冲流)
public static void writeData(String filePath, String... data) {
// 先有一个文件,来保存要写出的数据
File file = new File(filePath);
// 建立输出流对象
// FileWriter writer = new FileWriter(file);
PrintWriter pw = new PrintWriter(file);
// 开始完成内容的输出
for (String str : data) {
<span style="color: #
pw.println(str);
<span style="color: #
<span style="color: #
// 资源必须回收,也就是必须将流关闭
<span style="color: #
pw.close();
<span style="color: #
} catch (IOException e) {
<span style="color: #
e.printStackTrace();
<span style="color: #
<span style="color: #
使用时,注意我们这里加入了可变参数来动态传入多个字符串(即String... &data)。
当读取数据时,如果我们使用普通的读取方式,对于换行的处理不方便。
如果想按行读取内容,可以使用BufferedReader,Scanner
Scanner是JDK1.5新的
BufferedReader是JDK1.0就有的,所以使用BufferedReader。
为什么现在还使用BufferedReader,因为Scanner不支持编码的转换。
public static String readData(String filePath) {
// 也要建立文件对象
File file = new File(filePath);
// 建立读取的输入流对象
FileReader reader = new FileReader(file);
BufferedReader bw = new BufferedReader(reader);
// 每次调用read可以读取一个字符,
// 按照int类型返回,返回的是字符的编码,
<span style="color: #
// 需要通过强制类型转换,变为char类型
<span style="color: #
// Java中对于String这个类一般不建议反复修改,因为会占用内存。
<span style="color: #
StringBuilder builder = new StringBuilder();
<span style="color: #
// 因为文件中有很多的字符,因此需要循环来进行内容的读取。
<span style="color: #
// 就需要判断是否还有字符进行读取
<span style="color: #
String line = null;
<span style="color: #
// 每次读取时,如果读到内容,则会返回 0 - 65535 的char类型字符
<span style="color: #
// 如果没有读取到内容,则返回 -1 ,因此我们可以根据这个 -1 来判断后面是否还有内容
<span style="color: #
while ((line = bw.readLine()) != null) {
<span style="color: #
// 将读取到的内容保存下来
<span style="color: #
// 把字符放入到StringBuilder里
<span style="color: #
builder.append(line);
<span style="color: #
System.out.println(line);
<span style="color: #
<span style="color: #
// 没有读取到内容,说明循环结束,已经到了文件的末尾
<span style="color: #
return builder.toString();
<span style="color: #
} catch (Exception e) {
<span style="color: #
e.printStackTrace();
<span style="color: #
<span style="color: #
<span style="color: #
return null;
<span style="color: #
例如,将一个D盘的test.txt的内容读取出来,再写出到E盘的test.txt中
public static void copyFile(String inputFile, String outputPath) {
// 首先建立输入和输出的文件
File input = new File(inputFile);
File output = new File(outputPath);
// 建立输入和输出流
BufferedReader br = new BufferedReader(new FileReader(input));
PrintWriter pw = new PrintWriter(output);
// 每次读入一行,所以准备一个变量来接收
<span style="color: #
String line = null;
<span style="color: #
while ((line = br.readLine()) != null) {
<span style="color: #
pw.println(line);
<span style="color: #
<span style="color: #
pw.close();
<span style="color: #
br.close();
<span style="color: #
} catch (Exception e) {
<span style="color: #
e.printStackTrace();
<span style="color: #
<span style="color: #
文件夹迭代
这里只需要用到一个File类,但需要用里面的一些方法来判断是文件还是文件夹
isFile():是否是文件
isDirectory():是否是文件夹
还需要通过递归操作,将目录下的所有子目录也进行迭代。
多线程处理
使用多线程的目的肯定是为了提升程序的效率。
因为在进行网络数据爬取时,一般都是同时爬取多个网页的数据,而不是单个网页,因此在项目开发中我们需要通过多线程,来让程序同时完成多个操作。
多线程有两种实现方式:
1)&继承Thread类
2)&实现Runnable接口
使用多线程时,还有两个必须注意的方法:
1)&start()启动线程
2)&run()编写线程执行的主体。
先来完成一个倒计时功能:
public class ThreadDemo {
public static void main(String[] args) {
// new MyThread().start();
// new Thread() {
// public void run() {
// for (int i = 10; i &= 0; i--) {
// System.out.println("剩余时间:" + i);
// Thread.sleep(100);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }.start();
// new Thread(new MyRunnable()).start();
//继承Thread类必须重写run类
class MyThread extends Thread {
public void run() {
for (int i = 10; i &= 0; i--) {
System.out.println("剩余时间:" + i);
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
class MyRunnable implements Runnable {
public void run() {
for (int i = 10; i &= 0; i--) {
System.out.println("剩余时间:" + i);
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
List:允许重复,可以根据下标来取得数据,会按照放入的顺序来存储数据。
    ArrayList:以数组的形式存储,适合不经常变动,但经常查询的数据集。
    LinkedList:以链表的形式存储,适合经常变动的数据集,但是不经常查询
1 public class ListDemo {
public static void main(String[] args) {
LinkedList&Integer& list1 = new LinkedList&&();
for (int i = 0; i &= 100000; i++) {
list1.add(i);
long start = System.currentTimeMillis();
for (int i = 0; i &= 100000; i++) {
list1.get(i);
<span style="color: #
<span style="color: #
long end = System.currentTimeMillis();
<span style="color: #
System.out.println("ArrayList: " + (end - start) + " ms");
<span style="color: #
<span style="color: # }
Set:不允许重复,存储顺序看心情,没办法根据下标取得数据
    HashSet:散列排序(没有顺序)
    TreeSet:二叉树排序,按照固定的规则来排序,TreeSet中的内容必须实现一个Comparable的接口,并且必须覆写compareTo的方法,根据给定的规则来排序。
1 public class SetDemo {
public static void main(String[] args) {
Set&Person& set = new TreeSet&&();
set.add(new Person("张三", 12));
set.add(new Person("李四", 22));
set.add(new Person("王五", 42));
set.add(new Person("王八", 42));
set.add(new Person("赵六", 32));
System.out.println(set);
<span style="color: #
<span style="color: # }
<span style="color: #
<span style="color: # class Person implements Comparable&Person& {
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
public Person() {
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
public Person(String name, Integer age) {
<span style="color: #
<span style="color: #
this.name =
<span style="color: #
this.age =
<span style="color: #
<span style="color: #
<span style="color: #
public String getName() {
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
public void setName(String name) {
<span style="color: #
this.name =
<span style="color: #
<span style="color: #
<span style="color: #
public Integer getAge() {
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
public void setAge(Integer age) {
<span style="color: #
this.age =
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
public String toString() {
<span style="color: #
return "Person [name=" + name + ", age=" + age + "]";
<span style="color: #
<span style="color: #
<span style="color: #
public int compareTo(Person o) {
<span style="color: #
if (this.age & o.age) {
<span style="color: #
<span style="color: #
} else if (this.age & o.age) {
<span style="color: #
return -1;
<span style="color: #
<span style="color: #
if (this.name.equals(o.name)) {
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: #
<span style="color: # }
Map:key-value形式,可以根据key取得value,key按照Set集合的模式来保存。
    HashMap:散列
    TreeMap:有顺序
对于Map集合,要求能够循环迭代出里面的所有数据。
所以必须掌握Map的循环方法。
1 public class MapDemo {
public static void main(String[] args) {
Map&String, Integer& map = new HashMap&&();
map.put("方便面", 20);
map.put("火腿肠", 120);
map.put("矿泉水", 20);
map.put("可乐", 30);
// Map集合如果想迭代必须先按照key来进行迭代,
<span style="color: #
// 再根key查找value
<span style="color: #
Set&String& keySet = map.keySet();
<span style="color: #
for (String key : keySet) {
<span style="color: #
System.out.println(key + " ---& " + map.get(key));
<span style="color: #
<span style="color: #
<span style="color: # }
本篇对于java封装、继承、多态三大特性,IO操作,线程管理,类集处理(List、Set、Map)进行了阐述以及代码实现。
到此,对于网页数据的爬写的知识准备的可以了,下一篇我会先对一个文件进行数据爬取,然后再对网页上的数据代码实现爬虫功能。
阅读(...) 评论()您所在位置: &
&nbsp&&nbsp&nbsp&&nbsp
JAVA实验报告一运用JavaFx画时钟).doc 11页
本文档一共被下载:
次 ,您可全文免费在线阅读后下载本文档。
&#xe600;下载提示
1.本站不保证该用户上传的文档完整性,不预览、不比对内容而直接下载产生的反悔问题本站不予受理。
2.该文档所得收入(下载+内容+预览三)归上传者、原创者。
3.登录后可充值,立即自动返金币,充值渠道很便利
需要金币:150 &&
JAVA实验报告一运用JavaFx画时钟),javafx 时钟,java8 javafx,java javafx,java swing javafx,java9 javafx,javafx和java,java 时钟,java时钟代码,java时钟程序
你可能关注的文档:
··········
··········
JAVA实验报告
实验一 运用JavaFx画时钟
计算机科学与技术1306
指导教师:
一.概述 6
二.总体方案设计 7
三.详细设计 8
四.程序的调试与运行结果说明 9
五.课程设计总结 10
六.后记 11
七.附录 12
参考文献 13
课程设计的目的
设计一个带有指针、数字时钟,能方便我们的使用和操作,为我们以后的使用创造一个良好的平台。了解和掌握JavaFx基本概念和用法。
把自己所学的理论知识运用到实际操作中去,以此来发现自己的不足,及时的改正。在实际的操作中学习及运用还没有学过的知识。最后在调试与测试的过程还可以提升自己的改错能力也是自己经验的积累。
课程设计的要求
编写一个模拟时钟程序,此程序在屏幕左方有一指针式钟面,右方有两个矩形框,上面以数字方式显示日期和时间,该时间应与指针显示的时间一致,下方的矩形框作为秒表。用菜单选项或按钮设置时间和秒表。时间不必与机器系统时间相同,只要可任意设置即可。
在设计的过程中,需要用到awt组件和Swing容器与组件,布局管理器,事件处理,绘制图形,还运用到了类的继承,事件监听器和线程。还有自己还没有掌握的2D绘制图形,以及绘制各指针及之间的关系。为了完成自己的设计,必须API、教材以及相关的资料来解决这些尚未掌握的问题。
老师的要求就是尽量实现设计的功能,尽可能的锻炼自己的动手能力,提高自己的基础知识。
课程设计的主要设计思想
先是利用构造函数创建一个长为500,宽为200的窗体,颜色设置为black,并把窗体设计为固定大小,并且创建一个监听事件进行监听。随即创建一个时间计数器,最后实现ActionListener接口的实现方法。利用2D绘制图形的方法,在窗体左方画一个圆,并且绘制时钟上的12个数字刻度,然后利用Calendar类提供的HOUR,MINUTE,SECOND和MILLISECOND方法获得现在的时间,在计算时间和度数的关系;在利用2D绘制图形的方法绘制出各指针,并设置不同的颜色。在利用drawString在窗体的右上方画出一个小的框并在里面现在和时钟相对数字时间。
二 总体方案设计
编写一个模拟时钟程序,此程序在屏幕左方有一指针式钟面。
右方有矩形框,上面以数字方式显示日期和时间,该时间应与指针显示的时间一致。
三 详细设计
先是利用构造函数创建一个长为400,宽为400的窗体,颜色设置为white,并把窗体设计为固定大小,并且创建一个监听事件进行监听。随即创建一个时间计数器,最后实现ActionListener接口的实现方法。
利用2D绘制图形的方法,在窗体左方画一个圆,并且绘制时钟上的12个汉字,然后利用Calendar类提供的HOUR,MINUTE,SECOND和MILLISECOND方法获得现在的时间,在计算时间和度数的关系;在利用2D绘制图形的方法绘制出各指针,并设置不同的颜色。
在利用drawString在窗体的右上方画出一个小的框并在里面现在和时钟相对数字时间。
在编写主函数,在运行程序。
所完成的具体功能及用到的算法(详细分析)。
程序流程图
主要部分的详细流程图
四 程序的调试与运行结果说明
调试的方法:首先我是一个类一个类的完成,在每一个类完成后都会对它进行编译,待它能正常的编译之后在进行下面的类的编写。在编译的过程中会有一些错误,比如说语法错误,类的引用格式不正确,会产生一些异常。但是在经过慢慢的调试,这些问题逐渐得到解决。
运行结果:
五 课程设计总结
对于课程设计,基本上实现了模拟时钟程序的要求,此程序在屏幕左方有一指针式钟面,右方有矩形框,上面以数字方式显示日期和时间,该时间应与指针显示的时间一致。
该设计的特点是时钟上标有12个刻度,并且各指针是不同的颜色,看上去比较美观,在右上方有两个矩形框,第一个矩形框显示数字时间,这是为了能更好的看时间。
我想在不断地进行对该设计的完善,不仅能为该时钟设置背景,以增加该时钟的美观效果,也可以对时钟到了一定的时间就可以报时,并且可以设置闹钟,为闹钟设置多种音乐,可供选择,这样的话就不显得单调,这样一来该时钟更方便实用。并且加上开
正在加载中,请稍后.../ NettyChat
项目语言:None
权限:read-only(如需更高权限请先加入项目)
NettyChat/
Index: Bytes.java
===================================================================
--- Bytes.java (revision 0)
+++ Bytes.java (revision 3)
@@ -0,0 +1,402 @@
+package com.youai.chat.
+import java.io.UnsupportedEncodingE
+import java.nio.ByteB
+import java.nio.ByteO
+ * byte工具类
+ * @author lg
+public class Bytes {
+ public static short bytes2short(byte[] b) {
return bytes2short(b, null);
+ public static short bytes2short(byte[] b, ByteOrder bo) {
ByteBuffer buffer = ByteBuffer.allocate(2);
if (bo != null && !bo.equals(buffer.order()))
buffer.order(bo);
buffer.put(b);
buffer.flip();
return buffer.getShort();
+ public static byte[] short2bytes(short s) {
return short2bytes(s, null);
+ public static byte[] short2bytes(short s, ByteOrder bo) {
ByteBuffer buffer = ByteBuffer.allocate(2);
if (bo != null && !bo.equals(buffer.order()))
buffer.order(bo);
buffer.putShort(s);
buffer.flip();
return buffer.array();
+ public static float bytes2float(byte[] b) {
return bytes2float(b, null);
+ public static float bytes2float(byte[] b, ByteOrder bo) {
ByteBuffer buffer = ByteBuffer.allocate(4);
if (bo != null && !bo.equals(buffer.order()))
buffer.order(bo);
buffer.put(b);
buffer.flip();
return buffer.getFloat();
+ public static byte[] float2bytes(float f) {
return float2bytes(f, null);
+ public static byte[] float2bytes(float f, ByteOrder bo) {
ByteBuffer buffer = ByteBuffer.allocate(4);
if (bo != null && !bo.equals(buffer.order()))
buffer.order(bo);
buffer.putFloat(f);
buffer.flip();
return buffer.array();
+ public static double bytes2double(byte[] b) {
return bytes2double(b, null);
+ public static double bytes2double(byte[] b, ByteOrder bo) {
ByteBuffer buffer = ByteBuffer.allocate(8);
if (bo != null && !bo.equals(buffer.order()))
buffer.order(bo);
buffer.put(b);
buffer.flip();
return buffer.getDouble();
+ public static byte[] double2bytes(double d) {
return double2bytes(d, null);
+ public static byte[] double2bytes(double d, ByteOrder bo) {
ByteBuffer buffer = ByteBuffer.allocate(8);
if (bo != null && !bo.equals(buffer.order()))
buffer.order(bo);
buffer.putDouble(d);
buffer.flip();
return buffer.array();
+ public static char bytes2char(byte[] b) {
return bytes2char(b, null);
+ public static char bytes2char(byte[] b, ByteOrder bo) {
ByteBuffer buffer = ByteBuffer.allocate(2);
if (bo != null && !bo.equals(buffer.order()))
buffer.order(bo);
buffer.put(b);
buffer.flip();
return buffer.getChar();
+ public static byte[] char2bytes(char c) {
return char2bytes(c, null);
+ public static byte[] char2bytes(char c, ByteOrder bo) {
ByteBuffer buffer = ByteBuffer.allocate(2);
if (bo != null && !bo.equals(buffer.order()))
buffer.order(bo);
buffer.putChar(c);
buffer.flip();
return buffer.array();
+ public static byte[] int2bytes(int i) {
return int2bytes(i, null);
+ public static byte[] int2bytes(int i, ByteOrder bo) {
ByteBuffer buffer = ByteBuffer.allocate(4);
if (bo != null && !bo.equals(buffer.order()))
buffer.order(bo);
buffer.putInt(i);
buffer.flip();
return buffer.array();
+ public static int bytes2int(byte[] b) {
return bytes2int(b, null);
+ public static int bytes2int(byte[] b, ByteOrder bo) {
ByteBuffer buffer = ByteBuffer.allocate(4);
if (bo != null && !bo.equals(buffer.order()))
buffer.order(bo);
buffer.put(b);
buffer.flip();
return buffer.getInt();
+ public static byte[] long2bytes(long l) {
return long2bytes(l, null);
+ public static byte[] long2bytes(long l, ByteOrder bo) {
ByteBuffer buffer = ByteBuffer.allocate(8);
if (bo != null && !bo.equals(buffer.order()))
buffer.order(bo);
buffer.putLong(l);
buffer.flip();
return buffer.array();
+ public static long bytes2long(byte[] b) {
return bytes2long(b, null);
+ public static long bytes2long(byte[] b, ByteOrder bo) {
ByteBuffer buffer = ByteBuffer.allocate(8);
if (bo != null && !bo.equals(buffer.order()))
buffer.order(bo);
buffer.put(b);
buffer.flip();
return buffer.getLong();
* 将字节数组全置0
+ public static void zeroBytes(byte[] data) {
int j = data.
int i = 0;
setBytes(data, i, j, (byte) 0);
* 将字节数组指定位置后全置0
* @param data
* @param offset
+ public static void zeroBytes(byte[] data, int offset) {
int i = data.length -
setBytes(data, offset, i, (byte) 0);
* 将字节数组部分置0
* @param data
* @param offset
* @param len
+ public static void zeroBytes(byte[] data, int offset, int len) {
setBytes(data, offset, len, (byte) 0);
* 将字节数组全部置为指定值
* @param data
* @param value
+ public static void setBytes(byte[] data, byte value) {
setBytes(data, 0, data.length, value);
* 将字节数组指定位置后置为指定值
* @param data
* @param offset
* @param value
+ public static void setBytes(byte[] data, int offset, byte value) {
setBytes(data, offset, data.length - offset, value);
* 将字节数组部分置为指定值
* @param data
* @param offset
* @param len
* @param value
+ public static void setBytes(byte[] data, int offset, int len, byte value) {
for (int i = i & len + ++i)
* 取字节数组子数组
* @param data
* @param offset
* @param len
+ public static byte[] subBytes(byte[] data, int offset, int len) {
byte[] bb = new byte[len];
return subBytes(data, offset, bb);
+ public static byte[] subBytes(byte[] data, int offset) {
return subBytes(data, offset, data.length - offset);
+ public static byte[] subBytes(byte[] data, int offset, byte[] bb) {
int len = bb.
if (data.length - offset &= len)
System.arraycopy(data, offset, bb, 0, len);
System.arraycopy(data, offset, bb, 0, data.length - offset);
zeroBytes(bb, data.length - offset);
+ public static byte[] joinBytes(byte[] bs1, byte[] bs2) {
return joinBytes(bs1, 0, bs1.length, bs2, 0, bs2.length);
+ public static byte[] joinBytes(byte[] bs1, int offset1, int len1, byte[] bs2, int offset2, int len2) {
byte[] bs = new byte[len1 + len2];
bytesCopy(bs1, offset1, bs, 0, len1);
bytesCopy(bs2, offset2, bs, len1, len2);
+ public static void bytesCopy(byte[] src, byte[] dst, int len) {
System.arraycopy(src, 0, dst, 0, len);
+ public static void bytesCopy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int len) {
System.arraycopy(src, srcOffset, dst, dstOffset, len);
+ public static boolean bytesEquals(byte[] b1, byte[] b2) {
if (b1 == b2)
if (b1 == null || b2 == null || b1.length != b2.length)
return bytesEquals(b1, 0, b2, 0, b1.length);
+ public static boolean bytesEquals(byte[] b1, int offset1, byte[] b2, int offset2) {
if (b1 != b2 && (b1 == null || b2 == null))
if (b1.length - offset1 != b2.length - offset2)
return bytesEquals(b1, offset1, b2, offset2, b1.length - offset1);
+ public static boolean bytesEquals(byte[] b1, int offset1, byte[] b2, int offset2, int len) {
if (b1 != b2 && (b1 == null || b2 == null))
if ((b1.length & offset1 + len) || (b2.length & offset2 + len))
for (int i = 0; i & ++i) {
if (b1[(offset1 + i)] != b2[(offset2 + i)])
+ public static byte[] stringToBytes(String s, String charset, int length) throws UnsupportedEncodingException {
byte[] arr = new byte[length];
zeroBytes(arr);
if (s == null || s.length() == 0)
if (charset == null || charset.length() == 0)
arr = s.getBytes();
arr = s.getBytes(charset);
bytesCopy(arr, arr, Math.min(length, s.length()));
+ public static byte[] stringToBytes(String s, int len) {
return stringToBytes(s, null, len);
} catch (UnsupportedEncodingException e) {
+ public static String bytesToString(byte[] bb, String charset) throws UnsupportedEncodingException {
if (bb == null)
int i = 0;
for (; i & bb. ++i)
if (bb[i] == 0)
if (charset == null || charset.length() == 0)
return new String(bb, 0, i);
return new String(bb, 0, i, charset);
+ public static String bytesToString(byte[] bb) {
return bytesToString(bb, null);
} catch (UnsupportedEncodingException e) {
+ private static final char[] DIGITS = { &#39;0&#39;, &#39;1&#39;, &#39;2&#39;, &#39;3&#39;, &#39;4&#39;, &#39;5&#39;, &#39;6&#39;, &#39;7&#39;, &#39;8&#39;, &#39;9&#39;, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;,
&#39;f&#39; };
+ public static String toHexString(byte... bytes) {
char[] buffer = new char[bytes.length * 2];
for (int i = 0, j = 0; i & bytes. ++i) {
int u = toUnsigned(bytes[i]);
buffer[j++] = DIGITS[u &&& 4];
buffer[j++] = DIGITS[u & 0xf];
return new String(buffer);
+ public static String toBinaryString(byte... bytes) {
char[] buffer = new char[bytes.length * 8];
for (int i = 0, j = 0; i & bytes. ++i) {
int u = toUnsigned(bytes[i]);
buffer[j++] = DIGITS[(u &&& 7) & 0x1];
buffer[j++] = DIGITS[(u &&& 6) & 0x1];
buffer[j++] = DIGITS[(u &&& 5) & 0x1];
buffer[j++] = DIGITS[(u &&& 4) & 0x1];
buffer[j++] = DIGITS[(u &&& 3) & 0x1];
buffer[j++] = DIGITS[(u &&& 2) & 0x1];
buffer[j++] = DIGITS[(u &&& 1) & 0x1];
buffer[j++] = DIGITS[u & 0x1];
return new String(buffer);
+ private static byte charToByte(char c) {
return (byte) &ABCDEF&.indexOf(c);
+ public static byte[] hexStringToBytes(String hexString) {
if (hexString == null || hexString.equals(&&)) {
hexString = hexString.toUpperCase();
int length = hexString.length() / 2;
char[] hexChars = hexString.toCharArray();
byte[] d = new byte[length];
for (int i = 0; i & i++) {
int pos = i * 2;
d[i] = (byte) (charToByte(hexChars[pos]) && 4 | charToByte(hexChars[pos + 1]));
+ private static int toUnsigned(byte b) {
return b & 0 ? b + 256 :
Property changes on: Bytes.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Type.java
===================================================================
--- Type.java (revision 0)
+++ Type.java (revision 3)
@@ -0,0 +1,805 @@
+package com.youai.chat.
+import java.lang.reflect.A
+import java.lang.reflect.M
+import java.math.BigD
+import java.sql.T
+import java.sql.T
+import java.text.SimpleDateF
+import java.util.C
+import java.util.D
+import java.util.HashS
+import java.util.LinkedL
+import java.util.L
+import java.util.M
+import java.util.S
+ * 类型工具,get操作的第二个参数dv是默认返回值&br&
+ * Copyright (c) 2012 by 游爱.
+ * @author 梁广 Create on
上午10:10:09
+ * @version 1.0
+public class Type {
+ public static boolean isSuper(Class clazz1, Class clazz2) {
if ((clazz1 == null) || (clazz2 == null))
if ((!(clazz1.isInterface())) && (!(clazz2.isInterface()))) {
while (clazz1 != null) {
if (clazz1.equals(clazz2))
clazz1 = clazz1.getSuperclass();
} else if (clazz2.isInterface()) {
if (clazz1.equals(clazz2))
Class[] cs = clazz1.getInterfaces();
for (int i = 0; i & cs. ++i) {
if (isSuper(cs[i], clazz2))
if (!(clazz1.isInterface()))
return isSuper(clazz1.getSuperclass(), clazz2);
+ public static boolean isMap(Object o) {
return o instanceof M
+ public static boolean isArray(Object o) {
return ((o != null) && (o.getClass().isArray()));
+ public static boolean isList(Object o) {
return o instanceof L
+ public static boolean isSet(Object o) {
return o instanceof S
+ public static boolean isString(Object o) {
return o instanceof S
+ public static boolean isBoolean(Object o) {
return o instanceof B
+ public static boolean isNumber(Object o) {
return ((isByte(o)) || (isShort(o)) || (isInt(o)) || (isLong(o)) || (isFloat(o)) || (isDouble(o)));
+ public static boolean isIntegral(Object o) {
return ((isByte(o)) || (isShort(o)) || (isInt(o)) || (isLong(o)));
+ public static boolean isFloating(Object o) {
return ((isFloat(o)) || (isDouble(o)));
+ public static boolean isByte(Object o) {
return o instanceof B
+ public static boolean isShort(Object o) {
return o instanceof S
+ public static boolean isChar(Object o) {
return o instanceof C
+ public static boolean isInt(Object o) {
return o instanceof I
+ public static boolean isLong(Object o) {
return o instanceof L
+ public static boolean isFloat(Object o) {
return o instanceof F
+ public static boolean isDouble(Object o) {
return o instanceof D
+ public static boolean isDate(Object o) {
return o instanceof D
+ public static boolean isSQLTimestamp(Object o) {
return o instanceof T
+ public static boolean isSQLDate(Object o) {
return o instanceof java.sql.D
+ public static boolean isSQLTime(Object o) {
return o instanceof T
+ public static boolean isBytes(Object o) {
return o instanceof byte[];
+ public static boolean isChars(Object o) {
return o instanceof char[];
+ public static boolean isClass(Object o) {
return o instanceof C
+ public static boolean isMethod(Object o) {
return o instanceof M
+ public static boolean getBoolean(Object o, boolean dv) {
if (o == null)
if (isBoolean(o))
return ((Boolean) o).booleanValue();
if (isNumber(o))
return (getDouble(o, 0.0D) != 0.0D);
if (isString(o)) {
if (&true&.equalsIgnoreCase((String) o))
if (&false&.equalsIgnoreCase((String) o))
return (Double.parseDouble((String) o) != 0.0D);
} catch (Exception e) {
+ public static Boolean getBoolean(Object o, Boolean dv) {
return new Boolean(getBoolean(o, (dv == null) ? false : dv.booleanValue()));
+ public static byte getByte(Object o, byte dv) {
if (o == null)
if (isBoolean(o)) {
if (((Boolean) o).booleanValue())
if (isByte(o))
return ((Byte) o).byteValue();
if (isShort(o))
return ((Short) o).byteValue();
if (isInt(o))
return ((Integer) o).byteValue();
if (isLong(o))
return ((Long) o).byteValue();
if (isFloat(o))
return ((Float) o).byteValue();
if (isDouble(o))
return ((Double) o).byteValue();
if (isString(o)) {
return Byte.parseByte((String) o);
} catch (Exception e) {
+ public static Byte getByte(Object o, Byte dv) {
return new Byte(getByte(o, (dv == null) ? 0 : dv.byteValue()));
+ public static short getShort(Object o, short dv) {
if (o == null)
if (isBoolean(o))
return getByte(o, (byte) -128);
if (isByte(o))
return ((Byte) o).shortValue();
if (isShort(o))
return ((Short) o).shortValue();
if (isInt(o))
return ((Integer) o).shortValue();
if (isLong(o))
return ((Long) o).shortValue();
if (isFloat(o))
return ((Float) o).shortValue();
if (isDouble(o))
return ((Double) o).shortValue();
if (isString(o)) {
return Short.parseShort((String) o);
} catch (Exception e) {
+ public static Short getShort(Object o, Short dv) {
return new Short(getShort(o, (dv == null) ? 0 : dv.shortValue()));
+ public static char getChar(Object o, char dv) {
if (o == null)
if (isChar(o))
return ((Character) o).charValue();
if (isByte(o))
return (char) ((Byte) o).shortValue();
if (isShort(o))
return (char) ((Short) o).shortValue();
if (isInt(o))
return (char) ((Integer) o).shortValue();
if (isLong(o))
return (char) ((Long) o).shortValue();
if (isFloat(o))
return (char) ((Float) o).shortValue();
if (isDouble(o))
return (char) ((Double) o).shortValue();
String s = &&;
if ((isString(o)) && ((s = (String) o).length() == 1)) {
return s.charAt(0);
+ public static Character getChar(Object o, Character dv) {
return new Character(getChar(o, (dv == null) ? null : Character.valueOf(dv.charValue())).charValue());
+ public static int getInt(Object o, int dv) {
if (o == null)
if (isBoolean(o))
return getByte(o, (byte) -128);
if (isByte(o))
return ((Byte) o).intValue();
if (isShort(o))
return ((Short) o).intValue();
if (isInt(o))
return ((Integer) o).intValue();
if (isLong(o))
return ((Long) o).intValue();
if (isFloat(o))
return ((Float) o).intValue();
if (isDouble(o))
return ((Double) o).intValue();
if (isString(o)) {
return Integer.parseInt((String) o);
} catch (Exception e) {
+ public static Integer getInt(Object o, Integer dv) {
return new Integer(getInt(o, (dv == null) ? 0 : dv.intValue()));
+ public static long getLong(Object o, long dv) {
if (o == null)
if (isBoolean(o))
return getByte(o, (byte) -128);
if (isByte(o))
return ((Byte) o).longValue();
if (isShort(o))
return ((Short) o).longValue();
if (isInt(o))
return ((Integer) o).longValue();
if (isLong(o))
return ((Long) o).longValue();
if (isFloat(o))
return ((Float) o).longValue();
if (isDouble(o))
return ((Double) o).longValue();
if (isDate(o))
return ((Date) o).getTime();
if (isString(o)) {
return Long.parseLong((String) o);
} catch (Exception e) {
+ public static Long getLong(Object o, Long dv) {
return new Long(getLong(o, (dv == null) ? 0L : dv.longValue()));
+ public static float getFloat(Object o, float dv) {
if (o == null)
if (isByte(o))
return ((Byte) o).floatValue();
if (isShort(o))
return ((Short) o).floatValue();
if (isInt(o))
return ((Integer) o).floatValue();
if (isLong(o))
return ((Long) o).floatValue();
if (isFloat(o))
return ((Float) o).floatValue();
if (isDouble(o))
return ((Double) o).floatValue();
if (o instanceof BigDecimal)
return ((BigDecimal) o).floatValue();
if (isString(o)) {
return Float.parseFloat((String) o);
} catch (Exception e) {
+ public static Float getFloat(Object o, Float dv) {
return new Float(getFloat(o, (dv == null) ? 0.0F : dv.floatValue()));
+ public static double getDouble(Object o, double dv) {
if (o == null)
if (isByte(o))
return ((Byte) o).doubleValue();
if (isShort(o))
return ((Short) o).doubleValue();
if (isInt(o))
return ((Integer) o).doubleValue();
if (isLong(o))
return ((Long) o).doubleValue();
if (isFloat(o))
return ((Float) o).doubleValue();
if (isDouble(o))
return ((Double) o).doubleValue();
if (isDate(o))
return ((Date) o).getTime();
if (o instanceof BigDecimal)
return ((BigDecimal) o).doubleValue();
if (isString(o)) {
return Double.parseDouble((String) o);
} catch (Exception e) {
+ public static Double getDouble(Object o, Double dv) {
return new Double(getDouble(o, (dv == null) ? 0.0D : dv.doubleValue()));
+ public static Date getDateTime(Object o, String pattern, Date dv) {
if (o == null)
if (isLong(o))
return new Date(((Long) o).longValue());
if (isDate(o))
return ((Date) o);
if (isString(o))
return parseDateTime((String) o, pattern, dv);
+ private static Date parseDateTime(String s, String pattern, Date dv) {
SimpleDateFormat df = new SimpleDateFormat();
if ((pattern != null) && (pattern.length() & 0))
df.applyPattern(pattern);
return df.parse(s);
} catch (Exception e) {
+ public static Date getDateTime(Object o, Date paramDate) {
return getDateTime(o, &yyyy-MM-dd HH:mm:ss&, paramDate);
+ public static Date getDate(Object o, Date paramDate) {
return getDateTime(o, &yyyy-MM-dd&, paramDate);
+ public static Date getTime(Object o, Date paramDate) {
return getDateTime(o, &HH:mm:ss&, paramDate);
+ public static String getString(Object o, String dv) {
if (o == null)
if (o instanceof String) {
String s = (String)
if (s.trim().length() == 0)
return o.toString();
+ public static List getList(Object o, List dv) {
if (isList(o))
return ((List) o);
+ public static Map getMap(Object o, Map dv) {
if (isMap(o))
return ((Map) o);
+ public static Set getSet(Object o, Set dv) {
if (isSet(o))
return ((Set) o);
+ public static boolean[] getBooleans(Object o, boolean[] dv) {
if (o instanceof boolean[])
return ((boolean[]) o);
if (isArray(o)) {
dv = new boolean[len = Array.getLength(o)];
for (int i = 0; i & ++i)
dv[i] = getBoolean(Array.get(o, i), false);
+ public static byte[] getBytes(Object o, byte[] dv) {
if (o instanceof byte[])
return ((byte[]) o);
if (isArray(o)) {
dv = new byte[len = Array.getLength(o)];
for (int i = 0; i & ++i)
dv[i] = getByte(Array.get(o, i), (byte) -128);
+ public static short[] getShorts(Object o, short[] dv) {
if (o instanceof short[])
return ((short[]) o);
if (isArray(o)) {
dv = new short[len = Array.getLength(o)];
for (int i = 0; i & ++i)
dv[i] = getShort(Array.get(o, i), (short) -128);
+ public static int[] getInts(Object o, int[] dv) {
if (o instanceof int[])
return ((int[]) o);
if (isArray(o)) {
dv = new int[len = Array.getLength(o)];
for (int i = 0; i & ++i)
dv[i] = getInt(Array.get(o, i), 0);
+ public static long[] getLongs(Object o, long[] dv) {
if (o instanceof long[])
return ((long[]) o);
if (isArray(o)) {
dv = new long[len = Array.getLength(o)];
for (int i = 0; i & ++i)
dv[i] = getLong(Array.get(o, i), 0L);
+ public static float[] getFloats(Object o, float[] dv) {
if (o instanceof float[])
return ((float[]) o);
if (isArray(o)) {
dv = new float[len = Array.getLength(o)];
for (int i = 0; i & ++i)
dv[i] = getFloat(Array.get(o, i), 0.0F);
+ public static double[] getDoubles(Object o, double[] dv) {
if (o instanceof double[])
return ((double[]) o);
if (isArray(o)) {
dv = new double[len = Array.getLength(o)];
for (int i = 0; i & ++i)
dv[i] = getDouble(Array.get(o, i), 0.0D);
+ public static String[] getStrings(Object o, String[] paramArrayOfString) {
if (o instanceof String[])
return ((String[]) o);
if (isArray(o)) {
paramArrayOfString = new String[i = Array.getLength(o)];
for (int j = 0; j & ++j)
paramArrayOfString[j] = getString(Array.get(o, j), &&);
return paramArrayOfS
+ public static List[] getLists(Object o, List[] dv) {
if (o instanceof List[])
return ((List[]) o);
+ public static Map[] getMaps(Object o, Map[] dv) {
if (o instanceof Map[])
return ((Map[]) o);
+ public static Set[] getSets(Object o, Set[] dv) {
if (o instanceof Set[])
return ((Set[]) o);
+ public static &T& T[] getObjects(T[] vals, int from, int count) {
if (vals.length &= 0)
if (from & 0)
throw new RuntimeException(&from 不能为一个负数!&);
int len = vals.
if (from &= len)
int to = from +
to = to & len ? len :
@SuppressWarnings(&unchecked&)
T[] retvals = (T[]) Array.newInstance(vals.getClass().getComponentType(), to - from);
System.arraycopy(vals, from, retvals, 0, retvals.length);
+ public static Object[] getObjects(Object o, Object[] dv) {
if (o instanceof Object[])
return ((Object[]) o);
if (isArray(o)) {
int len = Array.getLength(o);
if (o instanceof boolean[])
dv = new Boolean[len];
else if (o instanceof byte[])
dv = new Byte[len];
else if (o instanceof char[])
dv = new Character[len];
else if (o instanceof short[])
dv = new Short[len];
else if (o instanceof int[])
dv = new Integer[len];
else if (o instanceof long[])
dv = new Long[len];
else if (o instanceof float[])
dv = new Float[len];
else if (o instanceof double[])
dv = new Double[len];
dv = new Object[len];
for (int i = 0; i & ++i)
dv[i] = Array.get(o, i);
+ public static String objectToString(Object o) {
if (o == null)
return &null&;
if (isString(o))
return ((String) o);
if (isSQLDate(o))
return getDate(&yyyy-MM-dd&, (Date) o);
if (isSQLTime(o))
return getDate(&HH:mm:ss&, (Date) o);
if (isDate(o))
return getDate(&yyyy-MM-dd HH:mm:ss&, (Date) o);
if (isChar(o))
return ((Character) o).toString();
if (isChars(o))
return new String((char[]) o);
if (isBytes(o))
return new String((byte[]) o);
return o.toString();
+ private static String getDate(String pattern, Date d) {
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern(pattern);
return sdf.format(d);
+ public static boolean objectEquals(Object o1, Object o2) {
if (o1 == null)
return (o2 == null);
return o1.equals(o2);
+ public static int objectCompares(Object o1, Object o2) {
if (o1 == o2)
if ((o1 != null) && (o2 == null))
if ((o1 == null) && (o2 != null))
return -1;
if (o1 instanceof Comparable)
return ((Comparable) o1).compareTo(o2);
if (o2 instanceof Comparable) {
return (-((Comparable) o2).compareTo(o1));
return o1.toString().compareTo(o2.toString());
+ public static Object[] toObjectArray(byte[] ar) {
Byte[] or = new Byte[ar.length];
for (int i = 0; i & ar. ++i)
or[i] = new Byte(ar[i]);
+ public static Object[] toObjectArray(char[] ar) {
Character[] or = new Character[ar.length];
for (int i = 0; i & ar. ++i)
or[i] = new Character(ar[i]);
+ public static Object[] toObjectArray(short[] ar) {
Short[] or = new Short[ar.length];
for (int i = 0; i & ar. ++i)
or[i] = new Short(ar[i]);
+ public static Object[] toObjectArray(int[] ar) {
Integer[] or = new Integer[ar.length];
for (int i = 0; i & ar. ++i)
or[i] = new Integer(ar[i]);
+ public static Object[] toObjectArray(long[] ar) {
Long[] or = new Long[ar.length];
for (int i = 0; i & ar. ++i)
or[i] = new Long(ar[i]);
+ public static Object[] toObjectArray(float[] ar) {
Float[] or = new Float[ar.length];
for (int i = 0; i & ar. ++i)
or[i] = new Float(ar[i]);
+ public static Object[] toObjectArray(double[] ar) {
Double[] or = new Double[ar.length];
for (int i = 0; i & ar. ++i)
or[i] = new Double(ar[i]);
+ public static Object[] toObjectArray(Object o) {
if (o instanceof byte[])
return toObjectArray((byte[]) o);
if (o instanceof char[])
return toObjectArray((char[]) o);
if (o instanceof short[])
return toObjectArray((short[]) o);
if (o instanceof int[])
return toObjectArray((int[]) o);
if (o instanceof long[])
return toObjectArray((long[]) o);
if (o instanceof float[])
return toObjectArray((float[]) o);
if (o instanceof double[]) {
return toObjectArray((double[]) o);
return toObjectArray((Object[]) o);
+ public static byte[] toByteArray(Object[] ar, byte dv) {
byte[] br = new byte[ar.length];
for (int i = 0; i & ar. ++i)
br[i] = getByte(ar[i], dv);
+ public static char[] toCharArray(Object[] ar, char dv) {
char[] br = new char[ar.length];
for (int i = 0; i & ar. ++i)
br[i] = getChar(ar[i], dv);
+ public static short[] toShortArray(Object[] ar, short dv) {
short[] br = new short[ar.length];
for (int i = 0; i & ar. ++i)
br[i] = getShort(ar[i], dv);
+ public static int[] toIntArray(Object[] ar, int dv) {
int[] br = new int[ar.length];
for (int i = 0; i & ar. ++i)
br[i] = getInt(ar[i], dv);
+ public static long[] toLongArray(Object[] ar, long dv) {
long[] br = new long[ar.length];
for (int i = 0; i & ar. ++i)
br[i] = getLong(ar[i], dv);
+ public static float[] toFloatArray(Object[] ar, float dv) {
float[] br = new float[ar.length];
for (int i = 0; i & ar. ++i)
br[i] = getFloat(ar[i], dv);
+ public static double[] toDoubleArray(Object[] ar, double dv) {
double[] br = new double[ar.length];
for (int i = 0; i & ar. ++i)
br[i] = getDouble(ar[i], dv);
+ public static List arrayToList(Object[] ar) {
List ls = new LinkedList();
arrayToCollection(ar, ls);
+ public static Set arrayToSet(Object[] ar) {
Set set = new HashSet();
arrayToCollection(ar, set);
+ public static void arrayToCollection(Object[] arr, Collection col) {
for (int i = 0; i & arr. ++i)
col.add(arr[i]);
Property changes on: Type.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: StringUtil.java
===================================================================
--- StringUtil.java (revision 0)
+++ StringUtil.java (revision 3)
@@ -0,0 +1,1028 @@
+package com.youai.chat.
+import java.io.BufferedR
+import java.io.ByteArrayInputS
+import java.io.ByteArrayOutputS
+import java.io.InputStreamR
+import java.io.PrintS
+import java.io.UnsupportedEncodingE
+import java.text.MessageF
+import java.util.ArrayL
+import java.util.C
+import java.util.HashM
+import java.util.I
+import java.util.LinkedHashM
+import java.util.L
+import java.util.M
+import java.util.S
+import java.util.V
+import java.util.regex.M
+import java.util.regex.P
+ * Copyright (c) 2011 by 游爱.
+ * @author XieEEE
上午10:40:33
+public final class StringUtil {
+ public static final int[] DEF_ID_ERROR = new int[0];
+ public static int[] getServerIds(String serverIds) {
if (StringUtil.isEmpty(serverIds))
String[] tmps = serverIds.split(&,&);
if (tmps == null || tmps.length &= 0) {
int[] sids = new int[tmps.length];
for (int i = 0; i & tmps. i++) {
sids[i] = Type.getInt(tmps[i], 0);
if (sids[i] &= 0) {
return DEF_ID_ERROR;
+ public static boolean outOfUtf83(String s) {
for (int i = 0; i & s.length(); i++) {
String hexString = StringUtil.toHexString(String.valueOf(s.charAt(i)).getBytes(&UTF-8&));
if (hexString.length() & 6)
byte[] b_text = s.getBytes();
for (int i = 0; i & b_text. i++) {
if ((b_text[i] & 0xF8) == 0xF0) {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
* 返回该异常的堆栈字符串信息
* @param e
+ public static String exptToString(Exception e) {
ByteArrayOutputStream baos =
PrintStream ps =
baos = new ByteArrayOutputStream();
ps = new PrintStream(baos);
e.printStackTrace(ps);
} catch (Exception e1) {
return e.toString();
} finally {
IOUtil.close(baos);
IOUtil.close(ps);
return new String(baos.toByteArray());
+ public static Map&String, String& toMap(String str) {
if (!StringUtil.isEmpty(str)) {
String[] arr = str.split(&,&);
Map&String, String& data = new LinkedHashMap&String, String&();
for (String s : arr) {
String[] v = s.split(&=&);
data.put(v[0], v.length & 1 ? v[1] : null);
+ public static boolean isEmpty(String str) {
if (str == null || str.equals(&&))
+ public static boolean equals(String str1, String str2) {
if (isEmpty(str1) && isEmpty(str2))
// 两者都为null,相等
if (str1 == null && str2 == null)
if (str1 != null && str2 == null)
if (str1 == null && str2 != null)
return str1.equals(str2);
+ public static boolean isNumber(String str) {
if (str == null)
return str.matches(&\\d+(\\.\\d+)?&);
* 在字符串的前面加上一个字符
* @param s
* @param length
添加字符后字符串的长度
* @param c
要添加的字符
+ public static String fillHeadString(String s, int length, char c) {
if (s.length() &= length)
StringBuffer sb = new StringBuffer(s.length() + length);
for (int i = 0; i & length - s.length(); ++i)
sb.append(c);
sb.append(s);
return sb.toString();
+ public static String fillEndString(String s, int length, char c) {
if (s.length() &= length)
(sb = new StringBuffer(s.length() + length)).append(s);
for (int i = 0; i & length - s.length(); ++i)
sb.append(c);
return sb.toString();
* 重复连接字符串
* @param o
需要连接的对象
* @param count
+ public static String join(Object o, int count) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i & ++i)
sb.append(o);
return sb.toString();
+ public static String join(Object[] arr, String obj) {
return join(arr, obj, arr.length);
+ public static String join(Collection&?& c, String obj) {
return join(c, obj, c.size());
+ public static String join(Object[] arr, Object obj, int maxLen) {
return join(arr, 0, ((maxLen & arr.length) || (maxLen &= 0)) ? arr.length : maxLen, obj);
+ public static String join(Collection&?& c, Object obj, int maxLen) {
return join(c, 0, ((maxLen & c.size()) || (maxLen &= 0)) ? c.size() : maxLen, obj);
+ public static String join(Object[] arr, int from, Object obj) {
return join(arr, from, arr.length, obj);
+ public static String join(Collection&?& c, int from, Object obj) {
return join(c, from, c.size(), obj);
+ public static String join(Collection&?& c, int from, int to, Object obj) {
return join(c.toArray(), from, to, obj);
* 列表中连接字符串
* @param arr
对象列表,可以是任意对象列表
* @param from
列表的起始位置
* @param to
列表的结束位置
* @param obj
连接对象,可以是任意对象
* @return 返回连接后的字符串
+ public static String join(Object[] arr, int from, int to, Object obj) {
if (from &= 0 && to &= arr.length && to - from &= 0) {
StringBuffer sb = new StringBuffer();
if (to - from & 0) {
sb.append(arr[from]);
from += 1;
if (to - from & 0) {
while (true) {
sb.append(obj + && + arr[from]);
if (from &= to) {
return sb.toString();
return sb.toString();
throw new IndexOutOfBoundsException();
* 分割字符串
* @param s
* @param num
每个子串的字符数
* @return 返回s中以num个字符为一组字符串的数组
+ public static String[] splitString(String s, int num) {
if (s == null)
if (num &= 0 || s.length() &= num)
return new String[] { s };
Vector&String& v = new Vector&String&();
for (int i = 0; i & s.length() / ++i)
v.add(s.substring(i * num, (i + 1) * num));
if (s.length() % num != 0)
v.add(s.substring(s.length() - (s.length() % num)));
String[] arr = new String[v.size()];
v.copyInto(arr);
+ public static String quote(Object s, String left, String right) {
return left + s +
* 将对象数组的每一项成员用左右字符串括起来
+ public static String[] quote(Object[] ss, String left, String right) {
String[] ar = new String[ss.length];
for (int i = 0; i & ar. ++i)
ar[i] = quote(ss[i], left, right);
* 判断是否为数字
* @param s
* @param ignoreChar
忽略的字符,如&.-&,则忽略&#39;.&#39;,&#39;-&#39;字符
+ public static boolean isNumber(String s, String ignoreChar) {
int length = s.length();
for (int i = 0; i & ++i) {
char each_char = s.charAt(i);
if (each_char &= &#39;0&#39; && each_char &= &#39;9&#39;)
if (ignoreChar == null || ignoreChar.length() == 0)
if (ignoreChar.indexOf(each_char) == -1)
* 整理字符串,去掉两边的指定字符
* @param s
* @param left
* @param right
+ public static String trim(String s, String left, String right) {
int i = 0;
int j = s.length() - 1;
if (left != null && left.length() & 0) {
for (; i & s.length(); ++i) {
if (left.indexOf(s.charAt(i)) == -1)
if (right != null && right.length() & 0) {
for (; j &= --j) {
if (right.indexOf(s.charAt(j)) == -1)
return s.substring(i, j + 1);
+ public static String trim(String s, String trimChars) {
return trim(s, trimChars, trimChars);
+ public static String trimLeft(String s, String left) {
return trim(s, left, &&);
+ public static String trimRight(String s, String right) {
return trim(s, &&, right);
* 替换字符串中的数字
* @param str
* @param news
+ public static String replaceDigits(String str, int[] news) {
return replaceDigits(str, getDigits(str), news);
* 替换字符串中的数字
* @param str
* @param olds
* @param news
+ public static String replaceDigits(String str, int[] olds, int[] news) {
for (int i = 0; i & olds. i++) {
int pos = str.indexOf(String.valueOf(olds[i]));
String tmp =
if (pos & 0)
tmp = str.substring(0, pos);
str = str.substring(pos).replace(String.valueOf(olds[i]), String.valueOf(news[i]));
if (tmp != null)
str = tmp +
* 获得字符串中的所有数字
* @param str
+ public static int[] getDigits(String str) {
List&String& ls = new ArrayList&String&();
StringBuffer s = new StringBuffer();
for (int i = 0; i & str.length(); ++i) {
char c = str.charAt(i);
if (Character.isDigit(c))
s.append(c);
if (s.length() & 0) {
ls.add(s.toString());
s = new StringBuffer();
if (s.length() & 0)
ls.add(s.toString());
return Type.getInts(ls.toArray(), null);
* 获得字符串开头的数字
* @param s
+ public static String getStartDigit(String s) {
s = s.trim();
StringBuffer sb = new StringBuffer(s.length());
for (int i = 0; i & s.length(); ++i) {
if (!Character.isDigit(s.charAt(i)))
sb.append(s.charAt(i));
return sb.toString();
+ public static long getStartDigit(String src, long dv) {
return Type.getLong(getStartDigit(src), dv);
* 获得字符串结尾的数字
* @param s
+ public static String getEndDigit(String s) {
s = s.trim();
StringBuffer sb = new StringBuffer(s.length());
for (int i = s.length() - 1; i &= 0; --i) {
if (!Character.isDigit(s.charAt(i)))
sb.insert(0, s.charAt(i));
return sb.toString();
+ public static long getEndDigit(String src, long dv) {
return Type.getLong(getEndDigit(src), dv);
+ public static String toStartUpperCase(String str, int len) {
return toStartCase(str, len, true);
+ public static String toStartLowerCase(String str, int len) {
return toStartCase(str, len, false);
+ public static String toStartCase(String str, int len, boolean upperCase) {
return toCase(str, 0, len, upperCase);
+ public static String toEndUpperCase(String str, int len) {
return toEndCase(str, len, true);
+ public static String toEndLowerCase(String str, int len) {
return toEndCase(str, len, false);
+ public static String toEndCase(String str, int len, boolean upperCase) {
return toCase(str, str.length() - len, str.length(), upperCase);
+ public static String toUpperCase(String str, int start, int end) {
return toCase(str, start, end, true);
+ public static String toLowerCase(String str, int start, int end) {
return toCase(str, start, end, false);
+ public static String toCase(String str, int start, int end, boolean upperCase) {
int strLen = str.length();
char[] chars = new char[strLen];
for (int i = 0; i & strL i++) {
char c = str.charAt(i);
if (i &= start && i & end)
chars[i] = upperCase ? Character.toUpperCase(c) : Character.toLowerCase(c);
chars[i] =
return new String(chars);
* 将byte序列转换成十六进制字符串序列,不分隔每个byte
* @param arr
+ public static String toHexString(byte[] arr) {
return toHexString(arr, &&);
* 将byte序列转换成十六进制字符串序列,不分隔每个byte
* @param arr
* @param seq
+ public static String toHexString(byte[] arr, String seq) {
StringBuffer s = new StringBuffer(arr.length && 2);
if (arr.length & 0) {
s.append(toHexString(arr[0]));
for (int i = 1; i & arr. ++i)
s.append(seq + toHexString(arr[i]));
return s.toString();
* 将char序列转换成十六进制字符串序列
* @param s
+ public static String toHexString(String s) {
return toHexString(s, &&);
* 将char序列转换成十六进制字符串序列,以sep分隔每一个char
* @param s
* @param seq
+ public static String toHexString(String s, String seq) {
StringBuffer a = new StringBuffer(s.length() * 6);
if (s.length() & 0) {
a.append(toHexString((short) s.charAt(0)));
for (int i = 1; i & s.length(); ++i)
a.append(seq + toHexString((short) s.charAt(i)));
return a.toString();
+ public static String toHexString(long n) {
return toHexString(Bytes.long2bytes(n));
+ public static String toHexString(int n) {
return fillHeadString(Integer.toHexString(n).toUpperCase(), 8, &#39;0&#39;);
+ public static String toHexString(short n) {
return fillHeadString(Integer.toHexString(n & 0xFFFF).toUpperCase(), 4, &#39;0&#39;);
+ public static String toHexString(byte n) {
return fillHeadString(Integer.toHexString(n & 0xFF).toUpperCase(), 2, &#39;0&#39;);
* 字符串是否不为空
* @param str
+ public static boolean isNotEmpty(String str) {
if (str != null && str.trim().length() & 0)
+ public static String replaceBlank(String str) {
Pattern p = pile(&\\s*|\t|\r|\n&);
Matcher m = p.matcher(str);
String rStr = m.replaceAll(&&);
+ // public static String cut(String str, int length) {
+ // return cut(str, length, 3);
+ // public static String cut(String str, int length, int dot) {
+ // if (str == null)
+ // str = str.replaceAll(&[\t\n|\n]&, &&);
+ // if (str.length() & length)
+ // int cutLength = length * 2;
+ // for (int i = 0; i & cutLength && i & str.length(); i++)
+ // if (Chinese.isCJK(str.charAt(i)))
+ // cutLength--;
+ // if (str.length() & cutLength)
+ // return str.substring(0, cutLength) + (dot == 3 ? &...& : dot == 2 ? &..&
+ // : dot == 1 ? &.& : &&);
+ public static String subBytesString(String src, int start, int end) {
byte[] sb = src.getBytes();
if (end &= 0)
return new String(Bytes.subBytes(sb, start, end - start));
+ public static String remove(String str, char remove) {
if (isEmpty(str) || str.indexOf(remove) == -1)
char[] chars = str.toCharArray();
int pos = 0;
for (int i = 0; i & chars. ++i)
if (chars[i] != remove)
chars[(pos++)] = chars[i];
return new String(chars, 0, pos);
+ public static String removeStart(String str, String remove) {
if (isEmpty(str) || isEmpty(remove))
if (str.startsWith(remove))
return str.substring(remove.length());
+ public static String removeEnd(String str, String remove) {
if (isEmpty(str) || isEmpty(remove))
if (str.endsWith(remove))
return str.substring(0, str.length() - remove.length());
+ public static String remove(String str, String remove) {
if (isEmpty(str) || isEmpty(remove))
return replace(str, remove, &&, -1);
+ public static String replaceOnce(String text, String repl, String with) {
return replace(text, repl, with, 1);
+ public static String replace(String text, String repl, String with) {
return replace(text, repl, with, -1);
+ public static String replace(String text, String repl, String with, int max) {
if (isEmpty(text) || isEmpty(repl) || with == null || max == 0)
int start = 0;
int end = text.indexOf(repl, start);
if (end == -1)
int replLength = repl.length();
int increase = with.length() - replL
increase = (increase & 0) ? 0 :
increase *= ((max & 64) ? 64 : (max & 0) ? 16 : max);
StringBuffer buf = new StringBuffer(text.length() + increase);
while (end != -1) {
buf.append(text.substring(start, end)).append(with);
start = end + replL
if (--max == 0)
end = text.indexOf(repl, start);
buf.append(text.substring(start));
return buf.toString();
+ public static String replaceChars(String str, char searchChar, char replaceChar) {
if (str == null)
return str.replace(searchChar, replaceChar);
+ public static String replaceChars(String str, String searchChars, String replaceChars) {
if (isEmpty(str) || isEmpty(searchChars))
if (replaceChars == null)
replaceChars = &&;
boolean modified =
int replaceCharsLength = replaceChars.length();
int strLength = str.length();
StringBuffer buf = new StringBuffer(strLength);
for (int i = 0; i & strL ++i) {
char ch = str.charAt(i);
int index = searchChars.indexOf(ch);
if (index &= 0) {
modified =
if (index & replaceCharsLength)
buf.append(replaceChars.charAt(index));
buf.append(ch);
if (modified)
return buf.toString();
+ public static boolean equalsIgnoreCase(String str1, String str2) {
return (str1 == null) ? false : (str2 == null) ? true : str1.equalsIgnoreCase(str2);
* 安全格式化字符串
* @param context
* @param args
+ public static String safeFormat(String context, Object... args) {
if (isEmpty(context))
if (args == null || args.length &= 0)
return String.format(context, args);
} catch (Exception e) {
+ public static String format(String struct, Object params) {
return format(struct, new Object[] { params });
+ public static String format(String struct, Object[] params) {
if (struct == null || params == null)
return &&;
MessageFormat format = new MessageFormat(struct);
return format.format(params);
+ public static String format(String struct, List&?& params) {
if (params == null)
return &&;
return format(struct, params.toArray());
+ public static String format(String struct, Set&?& params) {
if (params == null)
return &&;
return format(struct, params.toArray());
+ public static final char[] digits = { &#39;0&#39;, &#39;1&#39;, &#39;2&#39;, &#39;3&#39;, &#39;4&#39;, &#39;5&#39;, &#39;6&#39;, &#39;7&#39;, &#39;8&#39;, &#39;9&#39;, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;,
&#39;f&#39;, &#39;g&#39;, &#39;h&#39;, &#39;i&#39;, &#39;j&#39;, &#39;k&#39;, &#39;l&#39;, &#39;m&#39;, &#39;n&#39;, &#39;o&#39;, &#39;p&#39;, &#39;q&#39;, &#39;r&#39;, &#39;s&#39;, &#39;t&#39;, &#39;u&#39;, &#39;v&#39;, &#39;w&#39;, &#39;x&#39;, &#39;y&#39;, &#39;z&#39;,
&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;, &#39;F&#39;, &#39;G&#39;, &#39;H&#39;, &#39;I&#39;, &#39;J&#39;, &#39;K&#39;, &#39;L&#39;, &#39;M&#39;, &#39;N&#39;, &#39;O&#39;, &#39;P&#39;, &#39;Q&#39;, &#39;R&#39;, &#39;S&#39;, &#39;T&#39;, &#39;U&#39;,
&#39;V&#39;, &#39;W&#39;, &#39;X&#39;, &#39;Y&#39;, &#39;Z&#39; };
* 数字转字符串
* @param num
* @param radix
+ public static String numberToString(long num, int radix) {
if (radix & digits.length)
radix = digits.
if (radix &= 36)
return Long.toString(num, radix);
char[] chars = new char[65];
int k = 64;
int j = num & 0L ? 1 : 0;
if (j == 0)
while (num &= -radix) {
chars[k--] = digits[(int) (-(num % radix))];
chars[k] = digits[(int) (-num)];
if (j != 0)
chars[--k] = &#39;-&#39;;
return new String(chars, k, 65 - k);
* 显示指定编码下的字符长度
* @param encoding
* @param str
+ public static int getBytesLengthOfEncoding(String encoding, String str) {
if (str == null || str.length() == 0)
byte bytes[] = str.getBytes(encoding);
int length = bytes.
} catch (Exception e) {
e.printStackTrace();
* 转化指定字符串为指定编码格式
* @param context
* @param encoding
+ public static String getSpecialString(String context, String encoding) {
ByteArrayInputStream in = new ByteArrayInputStream(context.getBytes());
InputStreamReader isr = new InputStreamReader(in, encoding);
BufferedReader reader = new BufferedReader(isr);
StringBuffer buffer = new StringBuffer();
while ((result = reader.readLine()) != null) {
buffer.append(result);
return buffer.toString();
} catch (Exception ex) {
* 返回指定字符串长度
* @param s
+ public static int length(String s) {
if (s == null)
return s.getBytes().
* 获得特定字符总数
* @param str
* @param chr
+ public static int charCount(String str, char chr) {
int count = 0;
if (str != null) {
int length = str.length();
for (int i = 0; i & i++) {
if (str.charAt(i) == chr) {
+ private static Pattern PATTERN_XML = pile(&[&&&&#39;\&]&);
+ private static Map&String, String& ESCAPE_XML_MAP = new HashMap&String, String&();
+ private static Pattern PATTERN_XML_UN = Pattern
.compile(&(\\&)|(&)|(&)|(&#39;)|(&)|(\\$\\$)|(&)&);
+ private static Map&String, String& UNESCAPE_XML_MAP = new HashMap&String, String&();
+ static {
ESCAPE_XML_MAP = stringToMap(&&:&,&:&,&:&,&#39;:&#39;,\&:&,$:$$, :&&);
UNESCAPE_XML_MAP = stringToMap(&&:&,&:&,&:&,&#39;:&#39;,&:\&,$$:$,&: &);
+ public static String escapeReplacementSpecialChars(String s) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i & s.length(); ++i) {
char c = s.charAt(i);
if (c == &#39;\\&#39; || c == &#39;$&#39;)
sb.append(&#39;\\&#39;);
sb.append(c);
return sb.toString();
+ public static String escapeXML(String s) {
return replaceAll(s, PATTERN_XML, ESCAPE_XML_MAP);
+ public static String unescapeXML(String s) {
return replaceAll(s, PATTERN_XML_UN, UNESCAPE_XML_MAP);
+ private static Pattern PATTERN_WML = pile(&[&&&&#39;\& \\$]&);
+ public static String escapeWML(String s) {
s = s.replaceAll(&[\1- &&[^\n ]]&, &&);
s = replaceAll(s, PATTERN_WML, ESCAPE_XML_MAP);
s = s.replaceAll(&\n&, &&br/&\r\n&);
+ private static Pattern PATTERN_HTML = pile(&[&&&&#39;\& ]&);
+ public static String escapeHTML(String s) {
s = replaceAll(s, PATTERN_HTML, ESCAPE_XML_MAP);
s = s.replaceAll(&\n&, &&br&\r\n&);
+ private static Pattern PATTERN_CHAR = pile(&(\\&#\\d{1,5};)|(\\&#x[0-9a-fA-F]{1,4};)&);
+ public static String unescape(String s) {
Matcher matcher = PATTERN_CHAR.matcher(s);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
String grp = matcher.group();
String str = &&;
if (grp.startsWith(&&#x&))
str = String.valueOf((char) Integer.parseInt(grp.substring(3, grp.length() - 1), 16));
str = String.valueOf((char) Integer.parseInt(grp.substring(2, grp.length() - 1)));
if (str == null)
str = escapeReplacementSpecialChars(str);
matcher.appendReplacement(sb, str);
matcher.appendTail(sb);
return sb.toString();
+ private static Map&String, String& mapToStringSpecialChars = new HashMap&String, String&();
+ private static Map&String, String& stringToMapSpecialChars = new HashMap&String, String&();
+ static {
mapToStringSpecialChars.put(&%&, &%25&);
mapToStringSpecialChars.put(&:&, &%3A&);
mapToStringSpecialChars.put(&,&, &%2C&);
stringToMapSpecialChars.put(&%25&, &%&);
stringToMapSpecialChars.put(&%3A&, &:&);
stringToMapSpecialChars.put(&%2C&, &,&);
+ public static String escapeMapToStringSpecialChars(String s) {
return replaceAll(s, pile(&(%)|(:)|(,)&), mapToStringSpecialChars);
+ public static String mapToString(Map&?, ?& map) {
List&Object& ls = new ArrayList&Object&();
Iterator&?& it = map.entrySet().iterator();
while (it.hasNext()) {
@SuppressWarnings(&rawtypes&)
Map.Entry e = (Map.Entry) it.next();
String str = escapeMapToStringSpecialChars((String) e.getKey());
String str2 = escapeMapToStringSpecialChars((String) e.getValue());
ls.add(str + &:& + str2);
return join(ls, &,&);
+ public static String unescapeStringToMapSpecialChars(String s) {
return replaceAll(s, pile(&(%25)|(%3A)|(%2C)&), stringToMapSpecialChars);
+ public static void stringToMap(String str, Map&String, String& paramMap, boolean trim)

我要回帖

更多关于 java实现字符串的反转 的文章

 

随机推荐