Guava 15新特性介绍

原文:http://www.javacodegeeks.com/2013/10/guava-15-new-features.html
Guava 是众所周知的google出品的开源工具包,十分好用,本月退出了version 15的版本,其中主要的几个新特性有:


1 Escapers字符转义器
其目的就是在于将特殊字符进行转移,比如有:
HtmlEscapers
XmlEscapers
UrlEscapers
还可以自定义escaper,比如:

// escaping HTML
HtmlEscapers.htmlEscaper().escape("echo foo > file &");
// [result] echo foo > file &

// escaping XML attributes and content
XmlEscapers.xmlAttributeEscaper().escape("foo \"bar\"");
// [result] echo "bar"

XmlEscapers.xmlContentEscaper().escape("foo \"bar\"");
// [result] foo "bar"

// Custom Escaper
// escape single quote with another single quote
// and escape ampersand with backslash
Escaper myEscaper = Escapers.builder()
.addEscape('\'', "''")
.addEscape('&', "\&")
.build();

2 StandardSystemProperty
这个是用来方便调用如java.version, java.home 等环境变量的,使用的是enum了,比如:
StandardSystemProperty.JAVA_VERSION.value();
// [result] 1.7.0_25

StandardSystemProperty.JAVA_VERSION.key();
// [result] java.version
3 EvictingQueue
这个是一个非阻塞的队列,当队列长度满了后,自动移除头元素,比如:
EvictingQueue<String> q = EvictingQueue.create(3);
q.add("one");
q.add("two");
q.add("three");
q.add("four");
// the head of the queue is evicted after adding the fourth element
// queue contains: [two, three, four]

4
fileTreeTraverser 文件遍历递归利器
这个方法可以快速遍历某个文件目录下的所有文件,比如:
FluentIterable<File> iterable = Files.fileTreeTraverser().breadthFirstTraversal(new File("/var/tmp"));
for (File f : iterable) {
System.out.println(f.getAbsolutePath());
}
其中f.getAbsolutePath()用的是jdk 7中的方法
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值