﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-逛奔的蜗牛-随笔分类-Java</title><link>http://www.cppblog.com/biao/category/9971.html</link><description> 我不聪明，但我会很努力</description><language>zh-cn</language><lastBuildDate>Mon, 18 Aug 2014 12:37:26 GMT</lastBuildDate><pubDate>Mon, 18 Aug 2014 12:37:26 GMT</pubDate><ttl>60</ttl><item><title>Java：static final 变量的初始化</title><link>http://www.cppblog.com/biao/archive/2014/08/18/208047.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Mon, 18 Aug 2014 00:48:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2014/08/18/208047.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/208047.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2014/08/18/208047.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/208047.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/208047.html</trackback:ping><description><![CDATA[<div>
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;Avatar&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">final</span>&nbsp;String&nbsp;NAME;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">final</span>&nbsp;String&nbsp;INFO&nbsp;=&nbsp;"avatar";<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NAME&nbsp;=&nbsp;"Biao";&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;可以从文件读取</span><span style="color: #008000; "><br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;main(String[]&nbsp;args)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Name:&nbsp;"&nbsp;+&nbsp;Avatar.NAME&nbsp;+&nbsp;",&nbsp;info:&nbsp;"&nbsp;+&nbsp;Avatar.INFO);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</div>
</div>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/208047.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2014-08-18 08:48 <a href="http://www.cppblog.com/biao/archive/2014/08/18/208047.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：Sublimetext格式化插件</title><link>http://www.cppblog.com/biao/archive/2014/08/16/208037.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sat, 16 Aug 2014 10:36:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2014/08/16/208037.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/208037.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2014/08/16/208037.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/208037.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/208037.html</trackback:ping><description><![CDATA[<ol>
    <li>格式化 HTML：Tag</li>
    <li>格式化 JavaScript, CSS, PHP: CodeFormatter，快捷键 Ctrl + Alt + F</li>
</ol>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<div>CodeFormatter也能格式化HTML，但是效果没有Tag的好</div><img src ="http://www.cppblog.com/biao/aggbug/208037.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2014-08-16 18:36 <a href="http://www.cppblog.com/biao/archive/2014/08/16/208037.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Log4J 配置</title><link>http://www.cppblog.com/biao/archive/2014/07/16/207660.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Tue, 15 Jul 2014 16:03:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2014/07/16/207660.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/207660.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2014/07/16/207660.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/207660.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/207660.html</trackback:ping><description><![CDATA[<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<div style="font-family: Monaco; font-size: medium; line-height: normal;"><font face="Andale Mono"># 7 levels: all&lt;debug&lt;info&lt;warn&lt;error&lt;fatal&lt;off</font>
<div><font face="Andale Mono"><br />
</font></div>
<div><font face="Andale Mono"># Root logger option</font></div>
<div><font face="Andale Mono">log4j.rootLogger=INFO, stdout, file, error</font></div>
<div><font face="Andale Mono"><br />
</font></div>
<div><font face="Andale Mono"># Redirect log messages to console</font></div>
<div><font face="Andale Mono">log4j.appender.stdout=org.apache.log4j.ConsoleAppender</font></div>
<div><font face="Andale Mono">log4j.appender.stdout.layout=org.apache.log4j.PatternLayout</font></div>
<div><font face="Andale Mono">log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] [%-5p] [%C.%M():%L] - %m%n</font></div>
<div><font face="Andale Mono"><br />
</font></div>
<div><font face="Andale Mono"># Redirect log messages to a log file, support file rolling.</font></div>
<div><font face="Andale Mono">log4j.appender.file=org.apache.log4j.DailyRollingFileAppender</font></div>
<div><font face="Andale Mono">log4j.appender.file.File=logs/app.log</font></div>
<div><font face="Andale Mono">log4j.appender.file.DatePattern='_'yyyyMMdd'.log'</font></div>
<div><font face="Andale Mono">log4j.appender.file.layout=org.apache.log4j.PatternLayout</font></div>
<div><font face="Andale Mono">log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] [%-5p] [%C.%M():%L] - %m%n</font></div>
<div><font face="Andale Mono"><br />
</font></div>
<div><font face="Andale Mono"># Redirect log messages to a log file, support file rolling.</font></div>
<div><font face="Andale Mono">log4j.appender.error=org.apache.log4j.DailyRollingFileAppender</font></div>
<div><font face="Andale Mono">log4j.appender.error.File=logs/error.log</font></div>
<div><font face="Andale Mono">log4j.appender.error.DatePattern='_'yyyyMMdd'.log'</font></div>
<div><font face="Andale Mono">log4j.appender.error.Threshold=ERROR</font></div>
<div><font face="Andale Mono">log4j.appender.error.layout=org.apache.log4j.PatternLayout</font></div>
<div><font face="Andale Mono">log4j.appender.error.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] [%-5p] [%C.%M():%L] - %m%n</font></div>
<div><br />
</div>
</div>
<div style="font-family: Monaco; font-size: medium; line-height: normal;"><hr />
<br />
</div>
<div style="font-family: Monaco; font-size: medium; line-height: normal;"><span style="font-family: 'Andale Mono';">log4j.appender.error.Threshold=ERROR&nbsp;</span><font color="#C03AFF" style="font-family: 'Andale Mono';"># 这个 Appender 输出 &gt;= ERROR 级别的信息</font><br />
</div>
<div style="font-family: Monaco; font-size: medium; line-height: normal;"><font face="Andale Mono"><br />
</font></div>
<div style="font-family: Monaco; font-size: medium; line-height: normal;"><font face="Andale Mono">Refer to:&nbsp;</font></div>
<div style="font-family: Monaco; font-size: medium; line-height: normal;"><a href="http://www.cnblogs.com/likwo/archive/2010/09/01/1814994.html">http://www.cnblogs.com/likwo/archive/2010/09/01/1814994.html</a><font face="Andale Mono"><br />
</font></div>
<div style="font-family: Monaco; font-size: medium; line-height: normal;"><a href="http://www.open-open.com/bbs/view/1318596826374">http://www.open-open.com/bbs/view/1318596826374</a></div>
<div style="font-family: Monaco; font-size: medium; line-height: normal;"><a href="http://zhw2527.iteye.com/blog/1006302">http://zhw2527.iteye.com/blog/1006302</a><br />
</div>
<div style="font-family: Monaco; font-size: medium; line-height: normal;"><br />
</div>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/207660.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2014-07-16 00:03 <a href="http://www.cppblog.com/biao/archive/2014/07/16/207660.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：FastJson 主要API与类型</title><link>http://www.cppblog.com/biao/archive/2014/03/06/206062.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Thu, 06 Mar 2014 00:01:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2014/03/06/206062.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/206062.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2014/03/06/206062.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/206062.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/206062.html</trackback:ping><description><![CDATA[<div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;"><strong style="color: red;">主要的使用入口</strong></div>
<div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">Fastjson API入口类是com.alibaba.fastjson.JSON，常用的序列化操作都可以在JSON类上的静态方法直接完成。</div>
<div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">
<div style="padding: 4px; margin: 0px; border-left-color: #cccccc; font-size: 10pt; width: 705px; color: #000000; word-break: break-all; line-height: 16px; font-family: verdana, 宋体; background-color: #eeeeee;"><font color="#0000ff" style="padding: 0px; margin: 0px;">public</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">static</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">final</font>&nbsp;Object parse(String text);&nbsp;<font color="#008000" style="padding: 0px; margin: 0px;">// 把JSON文本parse为JSONObject或者JSONArray&nbsp;</font><br style="padding: 0px; margin: 0px;" />
<font color="#0000ff" style="padding: 0px; margin: 0px;">public</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">static</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">final</font>&nbsp;JSONObject parseObject(String text)；&nbsp;<font color="#008000" style="padding: 0px; margin: 0px;">// 把JSON文本parse成JSONObject&nbsp;&nbsp;&nbsp;&nbsp;</font><br style="padding: 0px; margin: 0px;" />
<font color="#0000ff" style="padding: 0px; margin: 0px;">public</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">static</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">final</font>&nbsp;&lt;T&gt; T parseObject(String text, Class&lt;T&gt; clazz);&nbsp;<font color="#008000" style="padding: 0px; margin: 0px;">// 把JSON文本parse为JavaBean&nbsp;</font><br style="padding: 0px; margin: 0px;" />
<font color="#0000ff" style="padding: 0px; margin: 0px;">public</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">static</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">final</font>&nbsp;JSONArray parseArray(String text);&nbsp;<font color="#008000" style="padding: 0px; margin: 0px;">// 把JSON文本parse成JSONArray&nbsp;</font><br style="padding: 0px; margin: 0px;" />
<font color="#0000ff" style="padding: 0px; margin: 0px;">public</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">static</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">final</font>&nbsp;&lt;T&gt; List&lt;T&gt; parseArray(String text, Class&lt;T&gt; clazz);&nbsp;<font color="#008000" style="padding: 0px; margin: 0px;">//把JSON文本parse成JavaBean集合&nbsp;</font><br style="padding: 0px; margin: 0px;" />
<font color="#0000ff" style="padding: 0px; margin: 0px;">public</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">static</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">final</font>&nbsp;String toJSONString(Object object);&nbsp;<font color="#008000" style="padding: 0px; margin: 0px;">// 将JavaBean序列化为JSON文本&nbsp;</font><br style="padding: 0px; margin: 0px;" />
<font color="#0000ff" style="padding: 0px; margin: 0px;">public</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">static</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">final</font>&nbsp;String toJSONString(Object object,&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">boolean</font>&nbsp;prettyFormat);&nbsp;<font color="#008000" style="padding: 0px; margin: 0px;">// 将JavaBean序列化为带格式的JSON文本&nbsp;</font><br style="padding: 0px; margin: 0px;" />
<font color="#0000ff" style="padding: 0px; margin: 0px;">public</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">static</font>&nbsp;<font color="#0000ff" style="padding: 0px; margin: 0px;">final</font>&nbsp;Object toJSON(Object javaObject); 将JavaBean转换为JSONObject或者JSONArray。</div>
</div>
<div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">&nbsp;</div>
<div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;"><strong style="color: red;">有关类库的一些说明</strong></div>
<div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">SerializeWriter：相当于StringBuffer</div>
<div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">JSONArray：相当于List&lt;Object&gt;</div>
<div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">JSONObject：相当于Map&lt;String, Object&gt;</div>
<div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">&nbsp;</div>
<div style="margin: 0px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">JSON反序列化没有真正数组，本质类型都是List&lt;Object&gt;</div>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/206062.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2014-03-06 08:01 <a href="http://www.cppblog.com/biao/archive/2014/03/06/206062.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：用 Java 7 运行 IDEA 13</title><link>http://www.cppblog.com/biao/archive/2014/02/23/205916.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sun, 23 Feb 2014 15:19:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2014/02/23/205916.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/205916.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2014/02/23/205916.html#Feedback</comments><slash:comments>16</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/205916.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/205916.html</trackback:ping><description><![CDATA[<div><br />
</div>
系统: MacOS X 10.9
<div>IDEA版本: 13</div>
<div>Java版本: 7</div>
<div>运行IDEA是提示需要安装Java 6.</div>
<div><img src="http://www.cppblog.com/images/cppblog_com/biao/Need-Install-Java6.png" border="0" alt="" width="480" height="190" /><br />
</div>
<div><br />
</div>
<div>难道必须安装Java 6 才能运行IDEA? 似乎不太合理。</div>
<div>其实不必安装Java 6也能够运行IDEA.</div>
<div>打开IDEA的Info.plist (<span style="background-color: #000000; color: #f5f5f5; font-family: Monaco; font-size: 12px; line-height: normal;">/Applications/IntelliJ\ IDEA\ 13\ CE.app/Contents/Info.plist</span>)，找到</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp;&lt;key&gt;JVMVersion&lt;/key&gt;</div>
<div>&nbsp; &nbsp; &nbsp; &lt;string&gt;1.6*&lt;/string&gt;</div>
<div>修改为</div>
<div>
<div>&nbsp; &nbsp; &nbsp; &lt;key&gt;JVMVersion&lt;/key&gt;</div>
<div>&nbsp; &nbsp; &nbsp; &lt;string&gt;1.7*&lt;/string&gt;</div>
</div>
<div><br />
</div>
<div>然后启动IDEA，这时就不会提示安装Java 6就能正常运行IDEA了。</div><img src ="http://www.cppblog.com/biao/aggbug/205916.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2014-02-23 23:19 <a href="http://www.cppblog.com/biao/archive/2014/02/23/205916.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：Mavericks里安装Java 6</title><link>http://www.cppblog.com/biao/archive/2013/10/23/203892.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Wed, 23 Oct 2013 15:56:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/10/23/203892.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/203892.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/10/23/203892.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/203892.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/203892.html</trackback:ping><description><![CDATA[<a href="http://medievalcode.com/blog/2013/08/29/osx-mavericks-you-need-a-java-6-runtime-to-run-x-error-dialog-fix/">http://medievalcode.com/blog/2013/08/29/osx-mavericks-you-need-a-java-6-runtime-to-run-x-error-dialog-fix/</a>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/203892.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-10-23 23:56 <a href="http://www.cppblog.com/biao/archive/2013/10/23/203892.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：编码范围</title><link>http://www.cppblog.com/biao/archive/2013/10/15/203755.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Tue, 15 Oct 2013 12:45:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/10/15/203755.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/203755.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/10/15/203755.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/203755.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/203755.html</trackback:ping><description><![CDATA[<div>编码范围</div>
<div>1. GBK (GB2312/GB18030)</div>
<div>x00-xff GBK双字节编码范围</div>
<div>x20-x7f ASCII</div>
<div>xa1-xff 中文</div>
<div>x80-xff 中文</div>
<div><br />
</div>
<div>2. UTF-8 (Unicode)</div>
<div>u4e00-u9fa5 (中文)</div>
<div>x3130-x318F (韩文)</div>
<div>xAC00-xD7A3 (韩文)</div>
<div>u0800-u4e00 (日文)</div>
<div>ps: 韩文是大于[u9fa5]的字符</div>
<div><br />
</div>
<div>有时候我们也会用到全角英文、特殊符号等</div>
<div>全角英文的UTF8是: uff21 &#8211; uff5a ，是从大写A开始到小写的z。</div>
<div>utf8中的全角数字是 uff10 &#8211; uff19 ，对应关系自然是　０ &#8211; ９ 。</div>
<div>utf8中的 uff01 到 uff09 是我们美式键盘上shift + 从1到9键上的特殊符号。</div>
<div><br />
</div>
<div>utf8中的 uff20是@, 要注意的是因为@是 uff20，所以 uff02 是双引号，</div>
<div>6的&#8230;&#8230;是两个符号的组合，</div>
<div>也就是说ff06是＆， ff09是 ）。</div>
<div><br />
</div>
<div>正则例子（使用PHP）:</div>
<div>preg_replace(&#8220;/([x80-xff])/&#8221;,&#8221;",$str); //GBK中匹配</div>
<div>preg_replace(&#8220;/([u4e00-u9fa5])/&#8221;,&#8221;",$str); //UTF8中匹配</div>
<div><br />
</div>
<div>转载地址：http://blog.csdn.net/sjw890821sjw/article/details/7004474</div>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/203755.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-10-15 20:45 <a href="http://www.cppblog.com/biao/archive/2013/10/15/203755.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：内存映射</title><link>http://www.cppblog.com/biao/archive/2013/09/03/202983.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Tue, 03 Sep 2013 03:23:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/09/03/202983.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/202983.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/09/03/202983.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/202983.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/202983.html</trackback:ping><description><![CDATA[<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; ">From: <a href="http://bbs.csdn.net/topics/390577067">http://bbs.csdn.net/topics/390577067</a><br />/**</span><span style="color: #008000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;内存映射<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080; ">@throws</span><span style="color: #008000; ">&nbsp;IOException<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">*/</span><span style="color: #000000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">static</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;mapChannel()&nbsp;</span><span style="color: #0000FF; ">throws</span><span style="color: #000000; ">&nbsp;IOException&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">long</span><span style="color: #000000; ">&nbsp;t1&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;System.currentTimeMillis();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileInputStream&nbsp;in&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">new</span><span style="color: #000000; ">&nbsp;FileInputStream(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">d:/1.txt</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">long</span><span style="color: #000000; ">&nbsp;size&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;in.available();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RandomAccessFile&nbsp;out&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">new</span><span style="color: #000000; ">&nbsp;RandomAccessFile(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">d:/2.txt</span><span style="color: #000000; ">"</span><span style="color: #000000; ">,&nbsp;</span><span style="color: #000000; ">"</span><span style="color: #000000; ">rw</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileChannel&nbsp;inc&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;in.getChannel();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MappedByteBuffer&nbsp;bf&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;inc.map(FileChannel.MapMode.READ_ONLY,&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">,&nbsp;size);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileChannel&nbsp;outc&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;out.getChannel();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MappedByteBuffer&nbsp;outbf&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;outc.map(FileChannel.MapMode.READ_WRITE,&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">,&nbsp;size);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outbf.put(bf);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inc.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outc.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;in.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">long</span><span style="color: #000000; ">&nbsp;t2&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;System.currentTimeMillis();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(t2&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">&nbsp;t1);<br />&nbsp;&nbsp;&nbsp;&nbsp;}</span></div><img src ="http://www.cppblog.com/biao/aggbug/202983.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-09-03 11:23 <a href="http://www.cppblog.com/biao/archive/2013/09/03/202983.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：Java NIO之Buffer基础</title><link>http://www.cppblog.com/biao/archive/2013/08/07/202395.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Wed, 07 Aug 2013 14:04:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/08/07/202395.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/202395.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/08/07/202395.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/202395.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/202395.html</trackback:ping><description><![CDATA[<div><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">From:&nbsp;<a href="http://hhyyllgg.iteye.com/blog/1921386">http://hhyyllgg.iteye.com/blog/1921386</a></span></div>
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">Java NIO 由以下几个核心部分组成：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<ul style="margin: 0px 0px 1.5em; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">
    <li style="margin: 0px 0px 0.25em 30px; padding: 0px; ">Channels</li>
    <li style="margin: 0px 0px 0.25em 30px; padding: 0px; ">Buffers</li>
    <li style="margin: 0px 0px 0.25em 30px; padding: 0px; ">Selectors</li>
</ul>
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">虽然Java NIO 中除此之外还有很多类和组件，但在我看来，Channel，Buffer 和 Selector 构成了核心的API。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">Buffers 缓冲区，以及缓冲区如何工作，是所有 I/O 的基础。所谓&#8220;输入／输出&#8221;讲的无非就是把数据移 进或移出缓冲区。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<strong style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: large; ">概念</span></strong><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">：实际上缓冲区就是一个包含在对象里的基本数据元素数组&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; font-size: large; "><strong>属性</strong></span><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">：所有的缓冲区都具有四个属性来提供关于其所包含的数据元素的信息。它们是：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<ul style="margin: 0px 0px 1.5em; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">
    <li style="margin: 0px 0px 0.25em 30px; padding: 0px; "><strong>容量（Capacity）</strong>&nbsp;缓冲区能够容纳的数据元素的最大数量。这一容量在缓冲区创建时被设定，并且永远不能被改变。</li>
    <li style="margin: 0px 0px 0.25em 30px; padding: 0px; "><strong>上界（Limit）</strong>&nbsp;缓冲区的第一个不能被读或写的元素。或者说，缓冲区中现存元素的计数。</li>
    <li style="margin: 0px 0px 0.25em 30px; padding: 0px; "><strong>位置（Position）</strong>&nbsp;下一个要被读或写的元素的索引。位置会自动由相应的get( )和put( )函数更新。</li>
    <li style="margin: 0px 0px 0.25em 30px; padding: 0px; "><strong>标记（Mark）</strong>&nbsp;一个备忘位置。调用mark( )来设定mark = postion。调用reset( )设定position = mark。标记在设定前是未定义的(undefined)。</li>
</ul>
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">看下图 新创建一个ByteBuffer&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<img src="http://dl2.iteye.com/upload/attachment/0087/9399/c806cb41-3fea-3bdd-8cf9-19316f11029b.bmp" style="border: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "  alt="" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">我们通过 ByteBuffer.allocate(11) 方法创建一个 10 个 byte 的数组缓冲区，初始状态如上图所示，position 的位置为 0，capacity 和 limit 默认都是数组长度。当我们写入 5 个字节时位置变化如下图所示：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<img src="http://dl2.iteye.com/upload/attachment/0087/9401/6a9dfbcb-7ecb-338b-aec0-1a66d46c1fdb.bmp" style="border: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "  alt="" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">这时如果我们想在不丢失位置的情况下进行一些修改，比如说将hello更改为MelloW&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">可以这样实现&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">buffer.put(0,(byte)'M').put((byte)'w');&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">修改后的Buffer图像如下图&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<img src="http://dl2.iteye.com/upload/attachment/0087/9403/0d043329-2d17-3add-9746-75f68fec8c53.bmp" style="border: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "  alt="" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">如果我们想将缓冲区的 5 个字节数据写入 Channel 通信信道，我们需要调用 byteBuffer.flip() 方法，数组的状态又发生如下变化&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<img src="http://dl2.iteye.com/upload/attachment/0087/9405/e9fc5046-ac81-3683-a830-7c6cd0952091.bmp" style="border: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "  alt="" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">还有一个方法 rewind ()，会重置position的位置为0 但不改变limit的位置，可以使用rewind()后退，重读已经被翻转的缓冲区中的数据。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<ul style="margin: 0px 0px 1.5em; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">
    <li style="margin: 0px 0px 0.25em 30px; padding: 0px; ">一旦读完Buffer中的数据，需要让Buffer准备好再次被写入。可以通过clear()或compact()方法来完成。</li>
    <li style="margin: 0px 0px 0.25em 30px; padding: 0px; ">如果调用的是clear()方法，position将被设回0，limit被设置成 capacity的值。换句话说，Buffer 被清空了。但这个时候Buffer中的数据并未清除，只是这些标记告诉我们可以从哪里开始往Buffer里写数据。</li>
</ul>
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">看下面代码	</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<div class="dp-highlighter" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25px; text-align: left; ">
<div class="bar">
<div class="tools" style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; color: black; font-weight: bold; ">Java代码&nbsp;<embed wmode="transparent" src="http://hhyyllgg.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=public%20static%20void%20main(String%5B%5D%20argv)%20throws%20Exception%20%7B%0A%09%09CharBuffer%20buffer%20%3D%20CharBuffer.allocate(20)%3B%0A%09%09System.out.println(%22%E5%88%9D%E5%A7%8B%E5%8C%96%E6%97%B6%E5%80%99%EF%BC%9Aposition%3D%22%2Bbuffer.position()%2B%22%20limit%3D%22%2Bbuffer.limit())%3B%0A%09%09fillBuffer(buffer%2C%22hello%22)%3B%0A%09%09System.out.println(%22%E5%A1%AB%E5%85%A5hello%E4%BB%A5%E5%90%8E%EF%BC%9Aposition%3D%22%2Bbuffer.position()%2B%22%20limit%3D%22%2Bbuffer.limit())%3B%0A%09%09buffer.put(0%2C'M').put('w')%3B%0A%09%09System.out.println(%22%E4%BF%AE%E6%94%B9%E6%88%90Mellow%E5%90%8E%EF%BC%9Aposition%3D%22%2Bbuffer.position()%2B%22%20limit%3D%22%2Bbuffer.limit())%3B%0A%09%09buffer.flip()%3B%0A%09%09System.out.println(%22%E7%BF%BB%E8%BD%AC%E5%90%8E%EF%BC%9Aposition%3D%22%2Bbuffer.position()%2B%22%20limit%3D%22%2Bbuffer.limit())%3B%0A%09%09buffer.clear()%3B%0A%09%09System.out.println(%22clear%E5%90%8E%EF%BC%9Aposition%3D%22%2Bbuffer.position()%2B%22%20limit%3D%22%2Bbuffer.limit())%3B%0A%09%09buffer.position(0)%3B%0A%09%09while%20(buffer.hasRemaining())%20%7B%0A%09%09%09System.out.println(buffer.get())%3B%0A%09%09%7D%0A%09%7Dprivate%20static%20void%20fillBuffer(CharBuffer%20buffer)%20%7B%0A%09%09String%20string%20%3D%20%22MY%20TEST%20BUFFER%22%3B%0A%09%09for%20(int%20i%20%3D%200%3B%20i%20%3C%20string.length()%3B%20i%2B%2B)%20%7B%0A%09%09%09buffer.put(string.charAt(i))%3B%0A%09%09%7D%0A%09%7D%0A%0A%E7%BB%93%E6%9E%9C%EF%BC%9A%0A%E5%88%9D%E5%A7%8B%E5%8C%96%E6%97%B6%E5%80%99%EF%BC%9Aposition%3D0%20limit%3D20%0A%E5%A1%AB%E5%85%A5hello%E4%BB%A5%E5%90%8E%EF%BC%9Aposition%3D5%20limit%3D20%0A%E4%BF%AE%E6%94%B9%E6%88%90Mellow%E5%90%8E%EF%BC%9Aposition%3D6%20limit%3D20%0A%E7%BF%BB%E8%BD%AC%E5%90%8E%EF%BC%9Aposition%3D0%20limit%3D6%0Aclear%E5%90%8E%EF%BC%9Aposition%3D0%20limit%3D20%0AM%0Ae%0Al%0Al%0Ao%0Aw" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://hhyyllgg.iteye.com/blog/1921386" title="收藏这段代码" style="color: #108ac6; text-decoration: underline; "><img class="star" src="http://hhyyllgg.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px; " /></a></div>
</div>
<ol start="1" class="dp-j" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af; ">
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span class="keyword" style="color: #7f0055; ">public</span>&nbsp;<span class="keyword" style="color: #7f0055; ">static</span>&nbsp;<span class="keyword" style="color: #7f0055; ">void</span>&nbsp;main(String[]&nbsp;argv)&nbsp;<span class="keyword" style="color: #7f0055; ">throws</span>&nbsp;Exception&nbsp;{&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CharBuffer&nbsp;buffer&nbsp;=&nbsp;CharBuffer.allocate(<span class="number" style="color: #c00000; ">20</span>);&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="string">"初始化时候：position="</span>+buffer.position()+<span class="string">"&nbsp;limit="</span>+buffer.limit());&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fillBuffer(buffer,<span class="string">"hello"</span>);&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="string">"填入hello以后：position="</span>+buffer.position()+<span class="string">"&nbsp;limit="</span>+buffer.limit());&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.put(<span class="number" style="color: #c00000; ">0</span>,<span class="string">'M'</span>).put(<span class="string">'w'</span>);&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="string">"修改成Mellow后：position="</span>+buffer.position()+<span class="string">"&nbsp;limit="</span>+buffer.limit());&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.flip();&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="string">"翻转后：position="</span>+buffer.position()+<span class="string">"&nbsp;limit="</span>+buffer.limit());&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.clear();&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="string">"clear后：position="</span>+buffer.position()+<span class="string">"&nbsp;limit="</span>+buffer.limit());&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.position(<span class="number" style="color: #c00000; ">0</span>);&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #7f0055; ">while</span>&nbsp;(buffer.hasRemaining())&nbsp;{&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(buffer.get());&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}<span class="keyword" style="color: #7f0055; ">private</span>&nbsp;<span class="keyword" style="color: #7f0055; ">static</span>&nbsp;<span class="keyword" style="color: #7f0055; ">void</span>&nbsp;fillBuffer(CharBuffer&nbsp;buffer)&nbsp;{&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;string&nbsp;=&nbsp;<span class="string">"MY&nbsp;TEST&nbsp;BUFFER"</span>;&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #7f0055; ">for</span>&nbsp;(<span class="keyword" style="color: #7f0055; ">int</span>&nbsp;i&nbsp;=&nbsp;<span class="number" style="color: #c00000; ">0</span>;&nbsp;i&nbsp;&lt;&nbsp;string.length();&nbsp;i++)&nbsp;{&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.put(string.charAt(i));&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">结果：&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">初始化时候：position=<span class="number" style="color: #c00000; ">0</span>&nbsp;limit=<span class="number" style="color: #c00000; ">20</span>&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">填入hello以后：position=<span class="number" style="color: #c00000; ">5</span>&nbsp;limit=<span class="number" style="color: #c00000; ">20</span>&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">修改成Mellow后：position=<span class="number" style="color: #c00000; ">6</span>&nbsp;limit=<span class="number" style="color: #c00000; ">20</span>&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">翻转后：position=<span class="number" style="color: #c00000; ">0</span>&nbsp;limit=<span class="number" style="color: #c00000; ">6</span>&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">clear后：position=<span class="number" style="color: #c00000; ">0</span>&nbsp;limit=<span class="number" style="color: #c00000; ">20</span>&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">M&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">e&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">l&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">l&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">o&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">w&nbsp;&nbsp;</li>
</ol>
</div>
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">从上面例子可以看出clear后实际上buffer中数据还是存在的&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">如果Buffer中有一些未读的数据，调用clear()方法，数据将&#8220;被遗忘&#8221;，意味着不再有任何标记会告诉你哪些数据被读过，哪些还没有。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">如果Buffer中仍有未读的数据，且后续还需要这些数据，但是此时想要先先写些数据，那么使用compact()方法。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">看下面代码：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<div class="dp-highlighter" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25px; text-align: left; ">
<div class="bar">
<div class="tools" style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; color: black; font-weight: bold; ">Java代码&nbsp;<embed wmode="transparent" src="http://hhyyllgg.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=public%20static%20void%20compactTest()%7B%0A%09%09CharBuffer%20buffer%20%3D%20CharBuffer.allocate(11)%3B%0A%09%09fillBuffer(buffer%2C%22hello%20world%22)%3B%0A%09%09buffer.position(6)%3B%0A%09%09buffer.compact()%3B%0A%09%09buffer.put(%22j%22)%3B%0A%09%09buffer.put(%22a%22)%3B%0A%09%09buffer.put(%22v%22)%3B%0A%09%09buffer.put(%22a%22)%3B%0A%09%09buffer.flip()%3B%0A%09%09while%20(buffer.hasRemaining())%20%7B%0A%09%09%09System.out.print(buffer.get())%3B%0A%09%09%7D%0A%09%7D%0A%E6%89%93%E5%8D%B0%E7%BB%93%E6%9E%9C%E4%B8%BAworldjava" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://hhyyllgg.iteye.com/blog/1921386" title="收藏这段代码" style="color: #108ac6; text-decoration: underline; "><img class="star" src="http://hhyyllgg.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px; " /></a></div>
</div>
<ol start="1" class="dp-j" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af; ">
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span class="keyword" style="color: #7f0055; ">public</span>&nbsp;<span class="keyword" style="color: #7f0055; ">static</span>&nbsp;<span class="keyword" style="color: #7f0055; ">void</span>&nbsp;compactTest(){&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CharBuffer&nbsp;buffer&nbsp;=&nbsp;CharBuffer.allocate(<span class="number" style="color: #c00000; ">11</span>);&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fillBuffer(buffer,<span class="string">"hello&nbsp;world"</span>);&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.position(<span class="number" style="color: #c00000; ">6</span>);&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.compact();&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.put(<span class="string">"j"</span>);&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.put(<span class="string">"a"</span>);&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.put(<span class="string">"v"</span>);&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.put(<span class="string">"a"</span>);&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.flip();&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #7f0055; ">while</span>&nbsp;(buffer.hasRemaining())&nbsp;{&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(buffer.get());&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">打印结果为worldjava&nbsp;&nbsp;</li>
</ol>
</div>
<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">compact()方法将所有未读的数据拷贝到Buffer起始处。然后将position设到最后一个未读元素正后面。limit属性依然像clear()方法一样，设置成capacity。现在Buffer准备好写数据了，但是不会覆盖未读的数据。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">其它还有mark()与reset() equals()等方法 就不一一介绍了。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; " />
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/202395.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-08-07 22:04 <a href="http://www.cppblog.com/biao/archive/2013/08/07/202395.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：URLConnection访问网页</title><link>http://www.cppblog.com/biao/archive/2013/08/07/202393.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Wed, 07 Aug 2013 12:54:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/08/07/202393.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/202393.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/08/07/202393.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/202393.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/202393.html</trackback:ping><description><![CDATA[参考：http://lamoop.diandian.com/post/2012-08-07/40032367973@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<div><br />
</div>
<div>示例:</div>
<div>
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000FF; ">package</span>&nbsp;com.tur.demo;<br />
<br />
<span style="color: #0000FF; ">import</span>&nbsp;java.io.InputStream;<br />
<span style="color: #0000FF; ">import</span>&nbsp;java.net.URL;<br />
<span style="color: #0000FF; ">import</span>&nbsp;java.net.URLConnection;<br />
<span style="color: #0000FF; ">import</span>&nbsp;java.net.URLEncoder;<br />
<span style="color: #0000FF; ">import</span>&nbsp;java.util.Scanner;<br />
<br />
<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;URLConnectionDemo&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;有道词典的在线查询功能.</span><span style="color: #008000; "><br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;query1()&nbsp;<span style="color: #0000FF; ">throws</span>&nbsp;Exception&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;如果URL有中文，则会出现乱码，这种情况需要用方法query2中的URLEncoder处理.</span><span style="color: #008000; "><br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;URLConnection&nbsp;connection&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;URL(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"http://fanyi.youdao.com/openapi.do?keyfrom=N3verL4nd&amp;key=208118276&amp;type=data&amp;doctype=xml&amp;version=1.1&amp;q=investigate")<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.openConnection();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream&nbsp;response&nbsp;=&nbsp;connection.getInputStream();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scanner&nbsp;scanner&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Scanner(response);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">while</span>&nbsp;(scanner.hasNextLine())&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(scanner.nextLine());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;query2()&nbsp;<span style="color: #0000FF; ">throws</span>&nbsp;Exception&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;url&nbsp;=&nbsp;"http://fanyi.youdao.com/openapi.do";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;charset&nbsp;=&nbsp;"UTF-8";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;keyFrom&nbsp;=&nbsp;"N3verL4nd";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;key&nbsp;=&nbsp;"208118276";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;type&nbsp;=&nbsp;"data";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;docType&nbsp;=&nbsp;"xml";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;version&nbsp;=&nbsp;"1.1";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;q&nbsp;=&nbsp;"中国";<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;query&nbsp;=&nbsp;String.format("keyfrom=%s&amp;key=%s&amp;type=%s&amp;doctype=%s&amp;version=%s&amp;q=%s",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;URLEncoder.encode(keyFrom,&nbsp;charset),<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;URLEncoder.encode(key,&nbsp;charset),<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;URLEncoder.encode(type,&nbsp;charset),<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;URLEncoder.encode(docType,&nbsp;charset),<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;URLEncoder.encode(version,&nbsp;charset),<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;URLEncoder.encode(q,&nbsp;charset));<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;URLConnection&nbsp;connection&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;URL(url&nbsp;+&nbsp;"?"&nbsp;+&nbsp;query).openConnection();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream&nbsp;response&nbsp;=&nbsp;connection.getInputStream();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scanner&nbsp;scanner&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Scanner(response);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">while</span>&nbsp;(scanner.hasNextLine())&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(scanner.nextLine());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;main(String[]&nbsp;args)&nbsp;<span style="color: #0000FF; ">throws</span>&nbsp;Exception&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;query1();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;query2();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</div>
</div><img src ="http://www.cppblog.com/biao/aggbug/202393.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-08-07 20:54 <a href="http://www.cppblog.com/biao/archive/2013/08/07/202393.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Qt：FontMetrics</title><link>http://www.cppblog.com/biao/archive/2013/08/03/202322.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sat, 03 Aug 2013 10:27:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/08/03/202322.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/202322.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/08/03/202322.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/202322.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/202322.html</trackback:ping><description><![CDATA[<div>在一个Rect的正中间绘制文本: rect的中点与文本的中点重合.</div>
<div>
<div>int cx = rect.x + rect.width / 2;</div>
<div>int fx = cx - fm.width(text);</div>
</div>
<div><br />
</div>
<div>int cy = rect.y + rect.height / 2;</div>
<div>int fy = cy + fm.xHeight&nbsp;/ 2;</div>
<div><br />
</div>
<div><br />
</div>
<div><br />
</div>
<img src="http://www.cppblog.com/images/cppblog_com/biao/FontMetrics.png" width="506" height="274" alt="" />
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/202322.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-08-03 18:27 <a href="http://www.cppblog.com/biao/archive/2013/08/03/202322.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mac：Mac下安装PHP, MySql开发环境</title><link>http://www.cppblog.com/biao/archive/2013/08/03/202319.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sat, 03 Aug 2013 02:24:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/08/03/202319.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/202319.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/08/03/202319.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/202319.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/202319.html</trackback:ping><description><![CDATA[最简单的两个选择: XAMPP, MAMP
<div>都集成了&nbsp;<span style="color: red; ">MySql + PhpMyAdmin&nbsp;</span>+ PHP 开发环境，建立开发环境简单（都只需要安装一个程序）。</div>
<div>如果单独的安装MySql，PhpMyAdmin，PHP开发环境，会麻烦很多。</div>
<div><br />
<div><span style="color: red; ">XAMPP</span>: 提供多平台版本:&nbsp;Mac,&nbsp;Windows，Linux, Solaris，但是几乎不更新了，相对MAMP来说易用性就差那么一点点。</div>
<div>下载地址：<a href="http://www.apachefriends.org/zh_cn/xampp.html">http://www.apachefriends.org/zh_cn/xampp.html</a></div>
<div><span style="color: red; "><br />
</span></div>
<div><span style="color: red; ">MAMP</span>: 只能运行于Mac，经常更新，帮助文档丰富，易用性更好。</div>
<div>下载地址：<a href="http://www.mamp.info/en/index.html">http://www.mamp.info/en/index.html</a></div>
<div><img src="http://www.cppblog.com/images/cppblog_com/biao/MAMP.png" width="537" height="458" alt="" /><br />
</div>
<div><img src="http://www.cppblog.com/images/cppblog_com/biao/MAMP-Preferences.png" width="537" height="458" alt="" /><br />
</div>
<div><br />
</div>
</div><img src ="http://www.cppblog.com/biao/aggbug/202319.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-08-03 10:24 <a href="http://www.cppblog.com/biao/archive/2013/08/03/202319.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：使用JDK中的安全包对数据进行加解密</title><link>http://www.cppblog.com/biao/archive/2013/06/27/201337.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Thu, 27 Jun 2013 00:05:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/06/27/201337.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/201337.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/06/27/201337.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/201337.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/201337.html</trackback:ping><description><![CDATA[From:&nbsp;<a href="http://blog.csdn.net/noliyo/article/details/9166365">http://blog.csdn.net/noliyo/article/details/9166365</a>@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<div><br />
</div>
<div>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">本文以使用DES对称加密算法为例使用jdk对数据进行加密解密。</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><br />
</p>
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">首先需要了解Provider类，它是jdk引入的密码服务提供者概念，实现了Java安全性的一部分或者全部。Provider 可能实现的服务包括：&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">算法（如DES、RSA、MD5）；密钥的生成、转换和管理。&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">通常java运行时环境至少安装了一个名字为&#8220;SUN&#8221;的预设Provider，如果查看本机支持的Provider类型可以通过以下代码：</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<div class="dp-highlighter bg_java" style="width: 687px; overflow: hidden; text-align: left; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/black/java.gif); background-color: #333333; opacity: 0.6; color: #333333; line-height: 26px; background-position: 100% 0%; background-repeat: no-repeat no-repeat; ">
<div class="bar" style="position: relative; ">
<div class="tools" style="border-left-color: #999999; "><strong>[java]</strong>&nbsp;<a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="ViewSource" title="view plain" style="color: #cccccc; ">view plain</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="CopyToClipboard" title="copy" style="color: #cccccc; ">copy</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="PrintSource" title="print" style="color: #cccccc; ">print</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="About" title="?" style="color: #cccccc; ">?</a>
<div style="position: absolute; left: 416px; top: 627px; width: 21px; height: 11px; z-index: 99; "><embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="21" height="11" name="ZeroClipboardMovie_1" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&amp;width=21&amp;height=11" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-j" style="position: relative; ">
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">for</span><span style="color: #ffffff; ">(Provider&nbsp;p&nbsp;:&nbsp;Security.getProviders()){&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(p.getName()+<span class="string" style="color: #ff9900; ">"："</span><span style="color: #ffffff; ">+p.getInfo());&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">}&nbsp;&nbsp;</span></li>
</ol>
</div>
<br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">我本机运行结果为：</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<div class="dp-highlighter bg_java" style="width: 687px; overflow: hidden; text-align: left; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/black/java.gif); background-color: #333333; opacity: 0.6; color: #333333; line-height: 26px; background-position: 100% 0%; background-repeat: no-repeat no-repeat; ">
<div class="bar" style="position: relative; ">
<div class="tools" style="border-left-color: #999999; "><strong>[java]</strong>&nbsp;<a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="ViewSource" title="view plain" style="color: #cccccc; ">view plain</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="CopyToClipboard" title="copy" style="color: #cccccc; ">copy</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="PrintSource" title="print" style="color: #cccccc; ">print</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="About" title="?" style="color: #cccccc; ">?</a>
<div style="position: absolute; left: 416px; top: 795px; width: 21px; height: 11px; z-index: 99; "><embed id="ZeroClipboardMovie_2" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="21" height="11" name="ZeroClipboardMovie_2" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&amp;width=21&amp;height=11" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-j" style="position: relative; ">
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span style="color: #ffffff; ">SUN：SUN&nbsp;(DSA&nbsp;key/parameter&nbsp;generation;&nbsp;DSA&nbsp;signing;&nbsp;SHA-</span><span class="number" style="color: #c00000; ">1</span><span style="color: #ffffff; ">,&nbsp;MD5&nbsp;digests;&nbsp;SecureRandom;&nbsp;X.</span><span class="number" style="color: #c00000; ">509</span><span style="color: #ffffff; ">&nbsp;certificates;&nbsp;JKS&nbsp;keystore;&nbsp;PKIX&nbsp;CertPathValidator;&nbsp;PKIX&nbsp;CertPathBuilder;&nbsp;LDAP,&nbsp;Collection&nbsp;CertStores,&nbsp;JavaPolicy&nbsp;Policy;&nbsp;JavaLoginConfig&nbsp;Configuration)&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">SunRsaSign：Sun&nbsp;RSA&nbsp;signature&nbsp;provider&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">SunJSSE：Sun&nbsp;JSSE&nbsp;provider(PKCS12,&nbsp;SunX509&nbsp;key/trust&nbsp;factories,&nbsp;SSLv3,&nbsp;TLSv1)&nbsp;&nbsp;</span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">SunJCE：SunJCE&nbsp;Provider&nbsp;(<span class="keyword" style="color: #66ccff; ">implements</span><span style="color: #ffffff; ">&nbsp;RSA,&nbsp;DES,&nbsp;Triple&nbsp;DES,&nbsp;AES,&nbsp;Blowfish,&nbsp;ARCFOUR,&nbsp;RC2,&nbsp;PBE,&nbsp;Diffie-Hellman,&nbsp;HMAC)&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">SunJGSS：Sun&nbsp;(Kerberos&nbsp;v5,&nbsp;SPNEGO)&nbsp;&nbsp;</span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">SunSASL：Sun&nbsp;SASL&nbsp;provider(<span class="keyword" style="color: #66ccff; ">implements</span><span style="color: #ffffff; ">&nbsp;client&nbsp;mechanisms&nbsp;</span><span class="keyword" style="color: #66ccff; ">for</span><span style="color: #ffffff; ">:&nbsp;DIGEST-MD5,&nbsp;GSSAPI,&nbsp;EXTERNAL,&nbsp;PLAIN,&nbsp;CRAM-MD5;&nbsp;server&nbsp;mechanisms&nbsp;</span><span class="keyword" style="color: #66ccff; ">for</span><span style="color: #ffffff; ">:&nbsp;DIGEST-MD5,&nbsp;GSSAPI,&nbsp;CRAM-MD5)&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">XMLDSig：XMLDSig&nbsp;(DOM&nbsp;XMLSignatureFactory;&nbsp;DOM&nbsp;KeyInfoFactory)&nbsp;&nbsp;</span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">SunPCSC：Sun&nbsp;PC/SC&nbsp;provider&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">SunMSCAPI：Sun's&nbsp;Microsoft&nbsp;Crypto&nbsp;API&nbsp;provider&nbsp;&nbsp;</span></li>
</ol>
</div>
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">从结果中可以看到名称为&#8220;SunJCE&#8221;的Provider提供DES、Triple DES（即3DES）, AES、RSA、Diffie-Hellman等算法的实现，下面使用此Provider完成对称加密。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">KeyGenerator类提供（对称）密钥生成器的功能，使用getInstance 类方法构造，代码如下：</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<div class="dp-highlighter bg_java" style="width: 687px; overflow: hidden; text-align: left; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/black/java.gif); background-color: #333333; opacity: 0.6; color: #333333; line-height: 26px; background-position: 100% 0%; background-repeat: no-repeat no-repeat; ">
<div class="bar" style="position: relative; ">
<div class="tools" style="border-left-color: #999999; "><strong>[java]</strong>&nbsp;<a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="ViewSource" title="view plain" style="color: #cccccc; ">view plain</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="CopyToClipboard" title="copy" style="color: #cccccc; ">copy</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="PrintSource" title="print" style="color: #cccccc; ">print</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="About" title="?" style="color: #cccccc; ">?</a>
<div style="position: absolute; left: 416px; top: 1213px; width: 21px; height: 11px; z-index: 99; "><embed id="ZeroClipboardMovie_3" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="21" height="11" name="ZeroClipboardMovie_3" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=3&amp;width=21&amp;height=11" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-j" style="position: relative; ">
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span style="color: #ffffff; ">KeyGenerator&nbsp;kg&nbsp;=&nbsp;KeyGenerator.getInstance(</span><span class="string" style="color: #ff9900; ">"DES"</span><span style="color: #ffffff; ">,</span><span class="string" style="color: #ff9900; ">"SunJCE"</span><span style="color: #ffffff; ">);&nbsp;&nbsp;</span></span></li>
</ol>
</div>
<br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">SecretKey类是对称密钥的封装类，它不包含方法或常量，其唯一目的是分组对称密钥（并为其提供类型安全），从kg中获取&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<div class="dp-highlighter bg_java" style="width: 687px; overflow: hidden; text-align: left; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/black/java.gif); background-color: #333333; opacity: 0.6; color: #333333; line-height: 26px; background-position: 100% 0%; background-repeat: no-repeat no-repeat; ">
<div class="bar" style="position: relative; ">
<div class="tools" style="border-left-color: #999999; "><strong>[java]</strong>&nbsp;<a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="ViewSource" title="view plain" style="color: #cccccc; ">view plain</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="CopyToClipboard" title="copy" style="color: #cccccc; ">copy</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="PrintSource" title="print" style="color: #cccccc; ">print</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="About" title="?" style="color: #cccccc; ">?</a>
<div style="position: absolute; left: 416px; top: 1371px; width: 21px; height: 11px; z-index: 99; "><embed id="ZeroClipboardMovie_4" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="21" height="11" name="ZeroClipboardMovie_4" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=4&amp;width=21&amp;height=11" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-j" style="position: relative; ">
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span style="color: #ffffff; ">SecretKey&nbsp;key&nbsp;=&nbsp;kg.generateKey();&nbsp;&nbsp;</span></span></li>
</ol>
</div>
<br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">以上是产生密钥的过程，真正实现对数据加解密功能的类是Cipher，此类为加密和解密提供密码功能，它构成了 Java Cryptographic Extension (JCE) 框架的核心。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">为创建 Cipher 对象，应用程序调用 Cipher 的 getInstance 方法并将所请求&#8220;转换&#8221;的名称传递给它，还可以指定Provider的名称，本文中采用&#8220;SunJCE&#8221;。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">&#8220;转换&#8221;是一个字符串，它描述为产生某种输出而在给定的输入上执行的操作（或一组操作）。转换始终包括加密算法的名称（例如，DES），后面可能跟有一个反馈模式和填充方案（反馈模式和填充方案可以理解为 加密前对数据的预处理）</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">&#8220;转换&#8221;具有以下两种形式：&#8220;算法/模式/填充&#8221;或&#8220;算法&#8221;（这种情况，使用模式和填充方案特定于Provider的默认值）。本例中采用以下有效的转换：</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<div class="dp-highlighter bg_java" style="width: 687px; overflow: hidden; text-align: left; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/black/java.gif); background-color: #333333; opacity: 0.6; color: #333333; line-height: 26px; background-position: 100% 0%; background-repeat: no-repeat no-repeat; ">
<div class="bar" style="position: relative; ">
<div class="tools" style="border-left-color: #999999; "><strong>[java]</strong>&nbsp;<a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="ViewSource" title="view plain" style="color: #cccccc; ">view plain</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="CopyToClipboard" title="copy" style="color: #cccccc; ">copy</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="PrintSource" title="print" style="color: #cccccc; ">print</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="About" title="?" style="color: #cccccc; ">?</a>
<div style="position: absolute; left: 416px; top: 1711px; width: 21px; height: 11px; z-index: 99; "><embed id="ZeroClipboardMovie_5" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="21" height="11" name="ZeroClipboardMovie_5" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=5&amp;width=21&amp;height=11" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-j" style="position: relative; ">
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span style="color: #ffffff; ">Cipher&nbsp;c&nbsp;=&nbsp;Cipher.getInstance(</span><span class="string" style="color: #ff9900; ">"DES/CBC/PKCS5Padding"</span><span style="color: #ffffff; ">,</span><span class="string" style="color: #ff9900; ">"SunJCE"</span><span style="color: #ffffff; ">);</span><span class="comment" style="color: #cccccc; ">//DES加密算法，CBC的反馈模式，PKCS5Padding的填充方案</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
</ol>
</div>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">使用CBC反馈模式需要一个初始化向量，由类IvParameterSpec来完成，它需要是一个长度为8的byte数组。<br />
</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><br />
</p>
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">Cipher的init方法负责初始化，初始化需要指定模式和密钥，密钥本文采用上面已经生成的key，模式有四种ENCRYPT_MODE、DECRYPT_MODE、WRAP_MODE、UNWRAP_MODE分别表示加密、解密、密钥包装或密钥解包。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">如果加密则采用方法init(Cipher.ENCRYPT_MODE, key)；</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">如果解密则采用方法init(Cipher.DECRYPT_MODE, key)；</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">WRAP_MODE、UNWRAP_MODE模式是用来实现数字信封用的，本文不作介绍。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">通常对数据进行加解密，使用方法doFinal(byte[] input)，传入参数是byte数组。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">为了在http协议下快速传输数据，且某些系统中只能使用ASCII字符，通常采用Base64编码。Base64就是用来将非ASCII字符的数据转换成ASCII字符的一种方法。还可以提高可视性。</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">通过以上分析可以得到以下代码：&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<div class="dp-highlighter bg_java" style="width: 687px; overflow: hidden; text-align: left; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/black/java.gif); background-color: #333333; opacity: 0.6; color: #333333; line-height: 26px; background-position: 100% 0%; background-repeat: no-repeat no-repeat; ">
<div class="bar" style="position: relative; ">
<div class="tools" style="border-left-color: #999999; "><strong>[java]</strong>&nbsp;<a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="ViewSource" title="view plain" style="color: #cccccc; ">view plain</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="CopyToClipboard" title="copy" style="color: #cccccc; ">copy</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="PrintSource" title="print" style="color: #cccccc; ">print</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="About" title="?" style="color: #cccccc; ">?</a>
<div style="position: absolute; left: 416px; top: 2175px; width: 21px; height: 11px; z-index: 99; "><embed id="ZeroClipboardMovie_6" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="21" height="11" name="ZeroClipboardMovie_6" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=6&amp;width=21&amp;height=11" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-j" style="position: relative; ">
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;java.io.IOException;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;java.io.UnsupportedEncodingException;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;java.security.InvalidAlgorithmParameterException;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;java.security.InvalidKeyException;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;java.security.NoSuchAlgorithmException;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;java.security.NoSuchProviderException;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;javax.crypto.BadPaddingException;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;javax.crypto.Cipher;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;javax.crypto.IllegalBlockSizeException;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;javax.crypto.KeyGenerator;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;javax.crypto.NoSuchPaddingException;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;javax.crypto.SecretKey;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;javax.crypto.spec.IvParameterSpec;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;sun.misc.BASE64Decoder;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">import</span><span style="color: #ffffff; ">&nbsp;sun.misc.BASE64Encoder;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="keyword" style="color: #66ccff; ">public</span><span style="color: #ffffff; ">&nbsp;</span><span class="keyword" style="color: #66ccff; ">class</span><span style="color: #ffffff; ">&nbsp;SecurityTest&nbsp;{&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">//密钥生成器</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">private</span><span style="color: #ffffff; ">&nbsp;KeyGenerator&nbsp;kg;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">//对称密钥&nbsp;&nbsp;</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">private</span><span style="color: #ffffff; ">&nbsp;SecretKey&nbsp;key;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">//加解密时的初始化向量must&nbsp;be&nbsp;8&nbsp;bytes&nbsp;long</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">private</span><span style="color: #ffffff; ">&nbsp;IvParameterSpec&nbsp;iv;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">//Cipher,加解密主体实例</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">private</span><span style="color: #ffffff; ">&nbsp;Cipher&nbsp;c;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">//该构造方法初始化DES密钥和Cipher&nbsp;&nbsp;</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">public</span><span style="color: #ffffff; ">&nbsp;SecurityTest()&nbsp;</span><span class="keyword" style="color: #66ccff; ">throws</span><span style="color: #ffffff; ">&nbsp;NoSuchAlgorithmException,&nbsp;NoSuchProviderException,&nbsp;NoSuchPaddingException,&nbsp;UnsupportedEncodingException{&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;kg&nbsp;=&nbsp;KeyGenerator.getInstance(<span class="string" style="color: #ff9900; ">"DES"</span><span style="color: #ffffff; ">,</span><span class="string" style="color: #ff9900; ">"SunJCE"</span><span style="color: #ffffff; ">);&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key&nbsp;=&nbsp;kg.generateKey();&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iv&nbsp;=&nbsp;<span class="keyword" style="color: #66ccff; ">new</span><span style="color: #ffffff; ">&nbsp;IvParameterSpec(</span><span class="string" style="color: #ff9900; ">"12345678"</span><span style="color: #ffffff; ">.getBytes(</span><span class="string" style="color: #ff9900; ">"UTF-8"</span><span style="color: #ffffff; ">));&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c&nbsp;=&nbsp;Cipher.getInstance(<span class="string" style="color: #ff9900; ">"DES/CBC/PKCS5Padding"</span><span style="color: #ffffff; ">,</span><span class="string" style="color: #ff9900; ">"SunJCE"</span><span style="color: #ffffff; ">);</span><span class="comment" style="color: #cccccc; ">//DES加密算法，CBC的反馈模式，PKCS5Padding的填充方案&nbsp;，SunJCE：Provider</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">/**&nbsp;</span>&nbsp;</span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="comment" style="color: #cccccc; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;DES加密</span>&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="comment" style="color: #cccccc; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">public</span><span style="color: #ffffff; ">&nbsp;String&nbsp;encrypt(String&nbsp;src)&nbsp;</span><span class="keyword" style="color: #66ccff; ">throws</span><span style="color: #ffffff; ">&nbsp;InvalidKeyException,&nbsp;IllegalBlockSizeException,&nbsp;BadPaddingException,&nbsp;InvalidAlgorithmParameterException{&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">//初始化--&nbsp;ENCRYPT_MODE：加密模式，&nbsp;key：密钥，iv：初始化向量</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.init(Cipher.ENCRYPT_MODE,&nbsp;key,&nbsp;iv);&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">byte</span><span style="color: #ffffff; ">[]&nbsp;srcByte&nbsp;=&nbsp;src.getBytes();&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">//加密</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">byte</span><span style="color: #ffffff; ">[]&nbsp;targetByte&nbsp;=&nbsp;c.doFinal(srcByte);&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">//Base64编码</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;targetString&nbsp;=&nbsp;<span class="keyword" style="color: #66ccff; ">new</span><span style="color: #ffffff; ">&nbsp;BASE64Encoder().encode(targetByte);&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">return</span><span style="color: #ffffff; ">&nbsp;targetString;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">/**&nbsp;</span>&nbsp;</span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="comment" style="color: #cccccc; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;DES解密&nbsp;</span>&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span class="comment" style="color: #cccccc; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">public</span><span style="color: #ffffff; ">&nbsp;String&nbsp;decrypt(String&nbsp;srcString)&nbsp;</span><span class="keyword" style="color: #66ccff; ">throws</span><span style="color: #ffffff; ">&nbsp;InvalidKeyException,&nbsp;IllegalBlockSizeException,&nbsp;BadPaddingException,&nbsp;IOException,&nbsp;InvalidAlgorithmParameterException&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">//初始化--&nbsp;DECRYPT_MODE：解密模式，&nbsp;key：密钥，iv：初始化向量</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.init(Cipher.DECRYPT_MODE,&nbsp;key,&nbsp;iv);&nbsp;&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">//Base64解码</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">byte</span><span style="color: #ffffff; ">[]&nbsp;srcByte&nbsp;=&nbsp;</span><span class="keyword" style="color: #66ccff; ">new</span><span style="color: #ffffff; ">&nbsp;BASE64Decoder().decodeBuffer(srcString);&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: #cccccc; ">//解密</span><span style="color: #ffffff; ">&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">byte</span><span style="color: #ffffff; ">[]&nbsp;targetByte&nbsp;=&nbsp;c.doFinal(srcByte);&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">return</span><span style="color: #ffffff; ">&nbsp;</span><span class="keyword" style="color: #66ccff; ">new</span><span style="color: #ffffff; ">&nbsp;String(targetByte);&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: #66ccff; ">public</span><span style="color: #ffffff; ">&nbsp;</span><span class="keyword" style="color: #66ccff; ">static</span><span style="color: #ffffff; ">&nbsp;</span><span class="keyword" style="color: #66ccff; ">void</span><span style="color: #ffffff; ">&nbsp;main(String[]&nbsp;args)&nbsp;</span><span class="keyword" style="color: #66ccff; ">throws</span><span style="color: #ffffff; ">&nbsp;Exception&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SecurityTest&nbsp;test&nbsp;=&nbsp;<span class="keyword" style="color: #66ccff; ">new</span><span style="color: #ffffff; ">&nbsp;SecurityTest();&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;src&nbsp;=&nbsp;<span class="string" style="color: #ff9900; ">"使用JKD进行加解密--DES算法测试！__小印"</span><span style="color: #ffffff; ">;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="string" style="color: #ff9900; ">"原文:"</span><span style="color: #ffffff; ">&nbsp;+&nbsp;src);&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;secret&nbsp;=&nbsp;test.encrypt(src);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="string" style="color: #ff9900; ">"密文:"</span><span style="color: #ffffff; ">&nbsp;+&nbsp;secret);&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;target&nbsp;=&nbsp;test.decrypt(secret);&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="string" style="color: #ff9900; ">"解密得到原文:"</span><span style="color: #ffffff; ">&nbsp;+&nbsp;target);&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;</span></li>
</ol>
</div>
<br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">我本机运行结果为：</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "></p>
<div class="dp-highlighter bg_java" style="width: 687px; overflow: hidden; text-align: left; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/black/java.gif); background-color: #333333; opacity: 0.6; color: #333333; line-height: 26px; background-position: 100% 0%; background-repeat: no-repeat no-repeat; ">
<div class="bar" style="position: relative; ">
<div class="tools" style="border-left-color: #999999; "><strong>[java]</strong>&nbsp;<a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="ViewSource" title="view plain" style="color: #cccccc; ">view plain</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="CopyToClipboard" title="copy" style="color: #cccccc; ">copy</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="PrintSource" title="print" style="color: #cccccc; ">print</a><a href="http://blog.csdn.net/noliyo/article/details/9166365#" class="About" title="?" style="color: #cccccc; ">?</a>
<div style="position: absolute; left: 416px; top: 3653px; width: 21px; height: 11px; z-index: 99; "><embed id="ZeroClipboardMovie_7" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="21" height="11" name="ZeroClipboardMovie_7" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=7&amp;width=21&amp;height=11" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-j" style="position: relative; ">
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; "><span style="color: #ffffff; ">原文:使用JKD进行加解密--DES算法测试！__小印&nbsp;&nbsp;</span></span></li>
    <li class="" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">密文:P8Xi4Jfvq9Eus0c1OTE32wK60rjHwPxZ8tRiElxOd5m69+vI37IGtw==&nbsp;&nbsp;</span></li>
    <li class="alt" style="border-left-color: #999999; color: #eeeeee; line-height: 18px; "><span style="color: #ffffff; ">解密得到原文:使用JKD进行加解密--DES算法测试！__小印&nbsp;&nbsp;</span></li>
</ol>
</div>
<br style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; " />
<span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">注意：本文采用的是随机密钥，所以每次运行得到的密文是不一样的，jdk也提供自定义的密钥 ^_^</span></div><img src ="http://www.cppblog.com/biao/aggbug/201337.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-06-27 08:05 <a href="http://www.cppblog.com/biao/archive/2013/06/27/201337.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java: Swing Ninepath使用的jar包与Nine Patch Editor</title><link>http://www.cppblog.com/biao/archive/2013/06/05/200803.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Wed, 05 Jun 2013 00:17:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/06/05/200803.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/200803.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/06/05/200803.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/200803.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/200803.html</trackback:ping><description><![CDATA[<br />
<div><span style="color: red; ">zip的jar文件下载后把.zip后缀去掉即可.</span></div>
<div><br />
</div>
1. ninepath jar:&nbsp;<a href="/Files/biao/android.ninepatch.jar.zip">/Files/biao/android.ninepatch.jar.zip</a>
<div><br />
</div>
<div>2. Android自带的九宫格编辑器:&nbsp;<a href="/Files/biao/Android-NinePatchEditor.jar.zip">/Files/biao/Android-NinePatchEditor.jar.zip</a></div>
<div><img src="http://www.cppblog.com/images/cppblog_com/biao/Android-NinePatchEditor.png" width="832" height="527" alt="" /><br />
</div>
<div><br />
</div>
<div>3. 第三方的九宫格编辑器(与Android自带的各有所长，带了标尺):&nbsp;<a href="/Files/biao/NinePatchEditor.jar.zip">/Files/biao/NinePatchEditor.jar.zip</a></div>
<div>(from:&nbsp;http://weblookandfeel.com/nine-patch-editor/)</div>
<div><img src="http://www.cppblog.com/images/cppblog_com/biao/NinePatchEditor.png" width="881" height="582" alt="" /><br />
</div>
<div><br />
</div>
<div>4. 测试图片(from: http://www.cnblogs.com/jb2011/archive/2012/05/02/2479002.html):</div>
<div><a href="/Files/biao/one.9.png">/Files/biao/one.9.png</a><br />
</div>
<div><a href="/Files/biao/two.9.png">/Files/biao/two.9.png</a><br />
</div>
<div><br />
</div><img src ="http://www.cppblog.com/biao/aggbug/200803.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-06-05 08:17 <a href="http://www.cppblog.com/biao/archive/2013/06/05/200803.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java: Swing中引入Android的NinePatch技术，让Swing拥有Android的外观定制能力</title><link>http://www.cppblog.com/biao/archive/2013/06/05/200802.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Wed, 05 Jun 2013 00:07:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/06/05/200802.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/200802.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/06/05/200802.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/200802.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/200802.html</trackback:ping><description><![CDATA[<h1 style="margin: 0px 0px 0px 5px; padding-top: 5px; font-size: 1.8em; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">【摘要】</h1>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">本文诣在展示如何在Swing中引入 NinePatch技术（早期有文章里中文译作九格图，暂且这么叫吧^_^，但此术非传统移动手机上的功能布局&#8212;&#8212;九格图哦）。</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">&nbsp;</p>
<h1 style="margin: 0px 0px 0px 5px; padding-top: 5px; font-size: 1.8em; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">【准备篇】</h1>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">Q：何为 NinePatch技术？</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">A：说简单点，就是用于对图片据屏幕大小进行自动拉伸的技术。更准确的介绍详见此文：<a href="http://www.yixieshi.com/ucd/9142.html" style="color: #1d58d1; text-decoration: none; ">http://www.yixieshi.com/ucd/9142.html</a>。</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">NinePatch技术本身虽微不足道，但它对于 UI定制开发来说无疑是相当有价值的。也可直接看官方指南：<a href="http://developer.android.com/guide/developing/tools/draw9patch.html" style="color: #1d58d1; text-decoration: none; ">http://developer.android.com/guide/developing/tools/draw9patch.html</a>。</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">&nbsp;</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">Q：NinePatch对Swing意味着什么？</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">A：利用NinePatch技术，比如：你在美化Swing的按钮UI时，再也不用根据不同的按钮大小准备不同的图片了，一张图片解决不同按钮按各自大小自动拉伸填充的问题，多么神奇！</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">当然，如果你对 程序比较熟，或者说对 程序外观定制比较熟的话，你将会更清楚这一点&#8212;&#8212;Swing的外观定制能力将会因此变的无比灵活和强大，</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">很多不可能将成为现实。Android程序的外观定制其实有点Java标准平台换肤技术Synth的影子，但显然，这个聪名的小改进，使得 外观定制比Swing更容易、更灵活。</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">&nbsp;</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; "><span style="line-height: 1.5; ">Q：从何处获得NinePatch技术呢？</span></p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">A：NinePatch技术的核心只有3到4个类，拿过来用就可以了，源码地址可以在此链接找到：</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; "><a href="http://www.java2s.com/Open-Source/Android/android-core/platform-sdk/com.android.ninepatch.htm%EF%BC%8C" style="color: #1d58d1; text-decoration: none; ">http://www.java2s.com/Open-Source/Android/android-core/platform-sdk/com.android.ninepatch.htm</a>，我打好的包稍</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">后可以在附件里下载哦。</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">&nbsp;</p>
<h1 style="margin: 0px 0px 0px 5px; padding-top: 5px; font-size: 1.8em; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">【准备好.9.png图片】</h1>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">本图片将使用NinePatch技术作为演示代码中的一JPanel背景进行自动填充之用，用不同的2张图是为了方便进行效果展示：</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">&nbsp;<img src="http://pic002.cnblogs.com/images/2012/285428/2012050215422167.png" alt="" style="border: 0px; " />&nbsp; &nbsp; &nbsp;<img src="http://pic002.cnblogs.com/images/2012/285428/2012050309005469.png" alt="" style="border: 0px; " /></p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">&nbsp;</p>
<h1 style="margin: 0px 0px 0px 5px; padding-top: 5px; font-size: 1.8em; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">【测试代码】</h1>
<div class="cnblogs_code" style="font-size: 12px; margin: 5px 0px; line-height: 25px; ">
<div class="cnblogs_code_toolbar" style="margin-top: 5px; "><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5; "><a href="http://www.cnblogs.com/jb2011/archive/2012/05/02/2479002.html" title="复制代码" style="color: #1d58d1; text-decoration: none; border: none !important; "><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important; " /></a></span></div>
<pre style="margin-top: 0px; margin-bottom: 0px; margin-left: 22px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New'; "><span style="line-height: 1.5; color: #0000ff; ">package</span><span style="line-height: 1.5; "> jb2011.t;
</span><span style="line-height: 1.5; color: #0000ff; ">import</span><span style="line-height: 1.5; "> java.awt.BorderLayout;
</span><span style="line-height: 1.5; color: #0000ff; ">import</span><span style="line-height: 1.5; "> java.awt.Graphics;
</span><span style="line-height: 1.5; color: #0000ff; ">import</span><span style="line-height: 1.5; "> java.awt.Graphics2D;
</span><span style="line-height: 1.5; color: #0000ff; ">import</span><span style="line-height: 1.5; "> java.awt.Rectangle;
</span><span style="line-height: 1.5; color: #0000ff; ">import</span><span style="line-height: 1.5; "> java.io.InputStream;
</span><span style="line-height: 1.5; color: #0000ff; ">import</span><span style="line-height: 1.5; "> javax.swing.BorderFactory;
</span><span style="line-height: 1.5; color: #0000ff; ">import</span><span style="line-height: 1.5; "> javax.swing.JButton;
</span><span style="line-height: 1.5; color: #0000ff; ">import</span><span style="line-height: 1.5; "> javax.swing.JFrame;
</span><span style="line-height: 1.5; color: #0000ff; ">import</span><span style="line-height: 1.5; "> javax.swing.JPanel;
</span><span style="line-height: 1.5; color: #0000ff; ">import</span><span style="line-height: 1.5; "> javax.swing.SwingUtilities;
</span><span style="line-height: 1.5; color: #0000ff; ">import</span><span style="line-height: 1.5; "> com.android.ninepatch.NinePatch;
</span><span style="line-height: 1.5; color: #008000; ">/**</span><span style="line-height: 1.5; color: #008000; ">
* 本类用于测试从Android中引入的NinePatch（九格图）技术的可行性.
*
* </span><span style="line-height: 1.5; color: #808080; ">@author</span><span style="line-height: 1.5; color: #008000; "> jb2011@163.com
* </span><span style="line-height: 1.5; color: #808080; ">@version</span><span style="line-height: 1.5; color: #008000; "> 1.0
</span><span style="line-height: 1.5; color: #008000; ">*/</span>
<span style="line-height: 1.5; color: #0000ff; ">class</span> Test <span style="line-height: 1.5; color: #0000ff; ">extends</span><span style="line-height: 1.5; "> JPanel
{
</span><span style="line-height: 1.5; color: #008000; ">//</span><span style="line-height: 1.5; color: #008000; ">NinePatch作为全局对象，提高性能</span>
<span style="line-height: 1.5; color: #0000ff; ">private</span><span style="line-height: 1.5; "> NinePatch mPatch;
</span><span style="line-height: 1.5; color: #0000ff; ">public</span><span style="line-height: 1.5; "> Test()
{
</span><span style="line-height: 1.5; color: #0000ff; ">super</span> (<span style="line-height: 1.5; color: #0000ff; ">new</span><span style="line-height: 1.5; "> BorderLayout());
</span><span style="line-height: 1.5; color: #008000; ">//</span><span style="line-height: 1.5; color: #008000; ">*** 关键代码：读取9格图 START</span>
<span style="line-height: 1.5; color: #0000ff; ">try</span><span style="line-height: 1.5; ">{
InputStream stream </span>= <span style="line-height: 1.5; color: #0000ff; ">this</span><span style="line-height: 1.5; "> .getClass().getResourceAsStream(
</span><span style="line-height: 1.5; color: #008000; ">//</span><span style="line-height: 1.5; color: #008000; ">                    "content_bg2.9.png"</span>
"content_bg3.9.png"<span style="line-height: 1.5; ">
);
mPatch </span>= NinePatch.load(stream, <span style="line-height: 1.5; color: #0000ff; ">true</span> <span style="line-height: 1.5; color: #008000; ">/*</span><span style="line-height: 1.5; color: #008000; "> is9Patch</span><span style="line-height: 1.5; color: #008000; ">*/</span>, <span style="line-height: 1.5; color: #0000ff; ">false</span> <span style="line-height: 1.5; color: #008000; ">/*</span><span style="line-height: 1.5; color: #008000; "> convert </span><span style="line-height: 1.5; color: #008000; ">*/</span><span style="line-height: 1.5; ">);
}
</span><span style="line-height: 1.5; color: #0000ff; ">catch</span><span style="line-height: 1.5; "> (Exception e){
e.printStackTrace();
}
</span><span style="line-height: 1.5; color: #008000; ">//</span><span style="line-height: 1.5; color: #008000; ">*** 关键代码：读取9格图 END
</span><span style="line-height: 1.5; color: #008000; ">//</span><span style="line-height: 1.5; color: #008000; ">加入一个面板，用于演示</span>
JPanel p = <span style="line-height: 1.5; color: #0000ff; ">new</span><span style="line-height: 1.5; "> JPanel();
p.setBorder(BorderFactory.createEmptyBorder(</span>20, 20, 20, 20<span style="line-height: 1.5; ">));
</span><span style="line-height: 1.5; color: #008000; ">//</span><span style="line-height: 1.5; color: #008000; ">该面板设置成背景透明</span>
p.setOpaque(<span style="line-height: 1.5; color: #0000ff; ">false</span><span style="line-height: 1.5; ">);
</span><span style="line-height: 1.5; color: #0000ff; ">this</span><span style="line-height: 1.5; ">.add(p);
</span><span style="line-height: 1.5; color: #008000; ">//</span><span style="line-height: 1.5; color: #008000; ">加入演示组件</span>
p.add(<span style="line-height: 1.5; color: #0000ff; ">new</span> JButton("JButton 1"<span style="line-height: 1.5; ">));
p.add(</span><span style="line-height: 1.5; color: #0000ff; ">new</span> JButton("JButton 2"<span style="line-height: 1.5; ">));
p.add(</span><span style="line-height: 1.5; color: #0000ff; ">new</span> JButton("JButton 3"<span style="line-height: 1.5; ">));
p.add(</span><span style="line-height: 1.5; color: #0000ff; ">new</span> JButton("JButton 4"<span style="line-height: 1.5; ">));
}
</span><span style="line-height: 1.5; color: #008000; ">/**</span><span style="line-height: 1.5; color: #008000; ">
* 重写父类方法，以便实现自定义背景的绘制.
</span><span style="line-height: 1.5; color: #008000; ">*/</span><span style="line-height: 1.5; ">
@Override </span><span style="line-height: 1.5; color: #0000ff; ">protected</span> <span style="line-height: 1.5; color: #0000ff; ">void</span><span style="line-height: 1.5; "> paintComponent(Graphics g)
{
Graphics2D g2 </span>=<span style="line-height: 1.5; "> (Graphics2D) g;
Rectangle clip </span>=<span style="line-height: 1.5; "> g2.getClipBounds(); // 有点小问题，要用(0, 0, getWidth(), getHeight())，否则每次绘制的clip都不一样而导致异常现象.
</span><span style="line-height: 1.5; color: #008000; ">//</span><span style="line-height: 1.5; color: #008000; ">*** 关键代码：使用9格图 START
</span><span style="line-height: 1.5; color: #008000; ">//</span><span style="line-height: 1.5; color: #008000; ">使用9格图绘制面板的背景</span>
<span style="line-height: 1.5; ">        mPatch.draw(g2, clip.x, clip.y, clip.width, clip.height);
</span><span style="line-height: 1.5; color: #008000; ">//</span><span style="line-height: 1.5; color: #008000; ">*** 关键代码：使用9格图 END</span>
<span style="line-height: 1.5; ">    }
</span><span style="line-height: 1.5; color: #0000ff; ">public</span> <span style="line-height: 1.5; color: #0000ff; ">static</span> <span style="line-height: 1.5; color: #0000ff; ">void</span> main(<span style="line-height: 1.5; color: #0000ff; ">final</span><span style="line-height: 1.5; "> String[] args)
{
SwingUtilities.invokeLater(</span><span style="line-height: 1.5; color: #0000ff; ">new</span><span style="line-height: 1.5; "> Runnable() {
</span><span style="line-height: 1.5; color: #0000ff; ">public</span> <span style="line-height: 1.5; color: #0000ff; ">void</span><span style="line-height: 1.5; "> run() {
JFrame frame </span>= <span style="line-height: 1.5; color: #0000ff; ">new</span><span style="line-height: 1.5; "> JFrame();
frame.setContentPane(</span><span style="line-height: 1.5; color: #0000ff; ">new</span> JPanel(<span style="line-height: 1.5; color: #0000ff; ">new</span><span style="line-height: 1.5; "> BorderLayout()));
((JPanel)frame.getContentPane()).setBorder(BorderFactory.createEmptyBorder(</span>5,5,5,5<span style="line-height: 1.5; ">));
frame.getContentPane().add(</span><span style="line-height: 1.5; color: #0000ff; ">new</span><span style="line-height: 1.5; "> Test(), BorderLayout.CENTER);
frame.setSize(</span>300,250<span style="line-height: 1.5; ">);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(</span><span style="line-height: 1.5; color: #0000ff; ">null</span><span style="line-height: 1.5; ">);
frame.setVisible(</span><span style="line-height: 1.5; color: #0000ff; ">true</span><span style="line-height: 1.5; ">);
}
});
}
}</span></pre>
<div class="cnblogs_code_toolbar" style="margin-top: 5px; "><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5; "><a href="http://www.cnblogs.com/jb2011/archive/2012/05/02/2479002.html" title="复制代码" style="color: #1d58d1; text-decoration: none; border: none !important; "><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="border: none !important; " /></a></span></div>
</div>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">&nbsp;</p>
<h1 style="margin: 0px 0px 0px 5px; padding-top: 5px; font-size: 1.8em; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">&nbsp;【运行效果图】</h1>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; "><img src="http://pic002.cnblogs.com/images/2012/285428/2012050309002243.png" alt="" style="border: 0px; " /></p>
<h1 style="margin: 0px 0px 0px 5px; padding-top: 5px; font-size: 1.8em; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">&nbsp;【附件下载】</h1>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">测试代码完整Eclipse3.5.2工程（含NinePatch的jar包哦）：</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; "><a title="测试工程（含NinePatch的jar包哦）" href="http://files.cnblogs.com/jb2011/jb2011blog_testNinePatch.rar" style="color: #1d58d1; text-decoration: none; ">http://files.cnblogs.com/jb2011/jb2011blog_testNinePatch.rar</a></p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">&nbsp;</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">================================================================================</p>
<h1 style="margin: 0px 0px 0px 5px; padding-top: 5px; font-size: 1.8em; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">【最后再啰嗦几句】</h1>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">　　潜水了很多年，得益于许多无私网友的奉献，越发觉得很有必要与人分享一些东西。接下来将陆续写出&#8220;Swing整容&#8221;系列文章，</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">希望对需要的人有用，但因水平确实有限，不喜者还请勿喷，多谢。</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">　　有人说，Swing很丑，这话没错，但Swing真的没救了？答案当然是否定的。接下来的文章将会与Swing的L&amp;F有关，谢谢关注。</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">　　&#8220;民工甲&#8221;的&#8220;Swing三刀&#8221;系列文章给了我最近一次Swing美化工作的部分灵感，非常感谢作者的无私，文章地址是：</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; "><a href="http://joshuaxiao.iteye.com/blog/707514" style="color: #1d58d1; text-decoration: none; ">http://joshuaxiao.iteye.com/blog/707514</a>。&#8220;WilliamChen&#8221;的Swing技术文章也是相当不错，可惜多年不更新了，有兴趣的朋</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">友可以去围观哦，<a href="http://blog.sina.com.cn/swingjava" style="color: #1d58d1; text-decoration: none; ">http://blog.sina.com.cn/swingjava</a>。</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; "><br />
</p>
<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff; ">From:&nbsp;http://www.cnblogs.com/jb2011/archive/2012/05/02/2479002.html</p>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/200802.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-06-05 08:07 <a href="http://www.cppblog.com/biao/archive/2013/06/05/200802.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java: android平台下使用点九PNG技术</title><link>http://www.cppblog.com/biao/archive/2013/06/05/200801.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Wed, 05 Jun 2013 00:05:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/06/05/200801.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/200801.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/06/05/200801.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/200801.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/200801.html</trackback:ping><description><![CDATA[<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">&#8220;点九&#8221;是andriod平台的应用软件开发里的一种特殊的图片形式，文件扩展名为：.9.png</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　智能手机中有自动横屏的功能,同一幅界面会在随着手机(或平板电脑)中的方向传感器的参数不同而改变显示的方向,在界面改变方向后,界面上的图形会因为长宽的变化而产生拉伸,造成图形的失真变形。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　我们都知道android平台有多种不同的分辨率，很多控件的切图文件在被放大拉伸后，边角会模糊失真。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　OK，在android平台下使用点九PNG技术，可以将图片横向和纵向同时进行拉伸，以实现在多分辨率下的完美显示效果。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; "><strong style="padding: 0px; margin: 0px; ">　　【普通拉伸和点九拉伸效果对比】</strong></p>
<center style="padding: 0px; margin: 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; background-color: #ffffff; "><img alt="android平台下使用点九PNG技术,互联网的一些事" src="http://www.yixieshi.com/uploads/allimg/110908/020RQB7-0.jpg" width="430" height="216" original="http://www.yixieshi.com/uploads/allimg/110908/020RQB7-0.jpg" style="padding: 0px; margin: 0px; border: none; max-width: 650px; " /></center>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　对比很明显，使用点九后，仍能保留图像的渐变质感，和圆角的精细度。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　从中我们也可以理解为什么叫&#8220;点九PNG&#8221;，其实相当于把一张png图分成了9个部分(九宫格)，分别为4个角，4条边，以及一个中间区域，4个角是不做拉升的，所以还能一直保持圆角的清晰状态，而2条水 平边和垂直边分别只做水平和垂直拉伸，所以不会出现边会被拉粗的情况，只有中间用黑线指定的区域做拉伸。结果是图片不会走样</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; "><strong style="padding: 0px; margin: 0px; ">　　二.&#8220;点九&#8221;的制作方法</strong></p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　方法1：使用 &#8220;draw9patch&#8221;工具绘制，流程如下</p>
<center style="padding: 0px; margin: 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; background-color: #ffffff; "><img alt="android平台下使用点九PNG技术,互联网的一些事" src="http://www.yixieshi.com/uploads/allimg/110908/020RQ532-1.jpg" width="540" height="68" original="http://www.yixieshi.com/uploads/allimg/110908/020RQ532-1.jpg" style="padding: 0px; margin: 0px; border: none; max-width: 650px; display: inline; " /></center>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; "><strong style="padding: 0px; margin: 0px; ">　　1. 安装工具</strong></p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　首先你需要给自己的电脑安装上java于系统的默认目录下。没有安装java的同学可以在百度搜索：jdk-6u20-windows-i586，安装包大小80M左右。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　然后使用andriod模拟器&#8212;android-sdk-windows，打开SDK/tools目录下的&#8220;draw9patch.bat&#8221;文件，出现载入窗口：</p>
<center style="padding: 0px; margin: 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; background-color: #ffffff; "><img alt="android平台下使用点九PNG技术,互联网的一些事" src="http://www.yixieshi.com/uploads/allimg/110908/020RV249-2.jpg" width="376" height="356" original="http://www.yixieshi.com/uploads/allimg/110908/020RV249-2.jpg" style="padding: 0px; margin: 0px; border: none; max-width: 650px; display: inline; " /></center>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; "><strong style="padding: 0px; margin: 0px; ">　　2.导入并编辑</strong></p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　将png图片拖拽到该窗口中</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　如下图，自动进入编辑界面。图中介绍了每个区域的内容及功能注释。</p>
<center style="padding: 0px; margin: 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; background-color: #ffffff; "><img alt="android平台下使用点九PNG技术,互联网的一些事" src="http://www.yixieshi.com/uploads/allimg/110908/020RVZ2-3.jpg" width="532" height="469" original="http://www.yixieshi.com/uploads/allimg/110908/020RVZ2-3.jpg" style="padding: 0px; margin: 0px; border: none; max-width: 650px; display: inline; " /></center>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　预览右侧的视图发现，图片的边缘处于普通拉伸状态。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　现在我们在图片边缘点击左键，绘制出黑线，即图片需要被拉伸的部分。如下图，对4条黑线做了注释。</p>
<center style="padding: 0px; margin: 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; background-color: #ffffff; "><img alt="android平台下使用点九PNG技术,互联网的一些事" src="http://www.yixieshi.com/uploads/allimg/110908/020RW320-4.jpg" width="558" height="294" original="http://www.yixieshi.com/uploads/allimg/110908/020RW320-4.jpg" style="padding: 0px; margin: 0px; border: none; max-width: 650px; display: inline; " /></center>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　如果失误多绘的部分，可按住shift键的同时点击鼠标左键擦除)。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　如图所见，三种拉伸结果均已完美显示，已实现我们想要的拉伸效果，假设这是一个有显示文字的窗体，那么文字显示的区域，程序也会控制在黑线对应范围。</p>
<center style="padding: 0px; margin: 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; background-color: #ffffff; "><img alt="android平台下使用点九PNG技术,互联网的一些事" src="http://www.yixieshi.com/uploads/allimg/110908/020RU3b-5.jpg" width="449" height="489" original="http://www.yixieshi.com/uploads/allimg/110908/020RU3b-5.jpg" style="padding: 0px; margin: 0px; border: none; max-width: 650px; display: inline; " /></center>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　以下这些图片，包括异性(非规则图形)图片，也可以通过点九PNG实现横纵向的自然拉伸。</p>
<center style="padding: 0px; margin: 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; background-color: #ffffff; "><img alt="android平台下使用点九PNG技术,互联网的一些事" src="http://www.yixieshi.com/uploads/allimg/110908/020RWJ8-6.jpg" width="560" height="507" original="http://www.yixieshi.com/uploads/allimg/110908/020RWJ8-6.jpg" style="padding: 0px; margin: 0px; border: none; max-width: 650px; display: inline; " /></center><center style="padding: 0px; margin: 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; background-color: #ffffff; "><img alt="android平台下使用点九PNG技术,互联网的一些事" src="http://www.yixieshi.com/uploads/allimg/110908/020RWS1-7.jpg" width="452" height="458" original="http://www.yixieshi.com/uploads/allimg/110908/020RWS1-7.jpg" style="padding: 0px; margin: 0px; border: none; max-width: 650px; display: inline; " /></center>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　【draw9patch.bat其他功能说明】</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　&#9313; Show lock：显示不可绘区域</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　&#9313; Show patches：预览这个绘图区中的可延伸宫格(粉红色代表一个可延伸区域)</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　&#9314; Show patches：预览视图中的高亮区域(紫色区域)</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　&#9315; Show bad patches：在宫格区域四周增加一个红色边界，这可能会在图像被延伸时产生人工痕迹。如果你消除所有的坏宫格，延伸视图的视觉一致性将得到维护。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; "><strong style="padding: 0px; margin: 0px; ">　　3.保存和输出</strong></p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　点击左上file- save，保存文件，自动生成一张后缀名为&#8220;*.9.png&#8221;格式的图片，图片上下左右各增加了1px的黑线。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　方法2：直接使用 PS等平面工具绘制，流程图如下</p>
<center style="padding: 0px; margin: 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; background-color: #ffffff; "><img alt="android平台下使用点九PNG技术,互联网的一些事" src="http://www.yixieshi.com/uploads/allimg/110908/020RR003-8.jpg" width="521" height="78" original="http://www.yixieshi.com/uploads/allimg/110908/020RR003-8.jpg" style="padding: 0px; margin: 0px; border: none; max-width: 650px; display: inline; " /></center>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　如流程图所示，相对与方法1，只需2个步骤就可得到.9.png图片，具体步骤为：</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　1. 确定切图后直接改变图片的画布大小，</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　2. 手动将上下左右各增加1px</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　3. 使用铅笔工具，手动绘制拉伸区域，色值必须为黑色(#000000)。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　4. 存储为web所用格式，选择png-24，储存时手动将后缀名改为.9.png</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　不过这种方法的缺点是不能实时预览，判断并测试拉伸区域的准确性。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　使用此方法需要注意以下2点:</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　1. 手绘的黑线拉伸区必须是#000000，透明度100%，并且图像四边不能出现半透明像素;</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　2. 你的.9.png必须绘有拉伸区域的黑线;</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　否则，图片不会通过android系统编译，导致程序报错。还有，有同学疑惑解压缩apk文件后，.9.png图片里的黑线怎么没了?</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　那是因为andriod程序在把文件打包成apk的时候，程序会自动把*.9.png图片边缘的黑线去掉，所以解压缩apk后看到的.9.png文件是没有黑线的。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; "><strong style="padding: 0px; margin: 0px; ">　　三.使用&#8220;点九&#8221;的意义</strong></p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　关于下图，经过测试发现使用普通png的显示效果出现明显的变色横纹。而.9.png图片的显示效果明显优于普通png。</p>
<center style="padding: 0px; margin: 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; background-color: #ffffff; "><img alt="android平台下使用点九PNG技术,互联网的一些事" src="http://www.yixieshi.com/uploads/allimg/110908/020RW501-9.jpg" width="536" height="218" original="http://www.yixieshi.com/uploads/allimg/110908/020RW501-9.jpg" style="padding: 0px; margin: 0px; border: none; max-width: 650px; display: inline; " /></center>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　使用.9.png格式后，横纹问题基本已解决。因为对于.9.png图片，android系统程序有对其优化的算法。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　由于android手机屏幕的材质质量差距大。很多屏幕不支持16位以上的颜色显示。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　所以渲染后结果出现丢失颜色，故造成横纹显示。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　经与多款android手机对比后发现，屏幕越次的手机横纹越明显。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　而使用了*.9.png图片技术后，只需要采用一套界面切图去适配不同的分辨率，而且大幅减少安装包的大小。而且这样程序不需要专门做处理的就可以实现其拉伸，也减少了代码量和开发工作量。</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　相信每个人android平台的切图工作，会有不同的技巧和心得，非常欢迎大家能在评论中留下自己的个人经验及心得。相互交流会让我们的工作模式更灵活，更高效，同时带给大家更多优质的移动端应用：)</p>
<p style="padding: 0px; margin: 10px 0px; color: #333333; font-family: Arial, SimSun, Tahoma; line-height: 28px; text-align: left; background-color: #ffffff; ">　　转载请注明出自&#8221;百度MUX&#8221;</p>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/200801.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-06-05 08:05 <a href="http://www.cppblog.com/biao/archive/2013/06/05/200801.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenGL：展示OpenGL特性的软件Tutors</title><link>http://www.cppblog.com/biao/archive/2013/04/19/199557.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Thu, 18 Apr 2013 16:24:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2013/04/19/199557.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/199557.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2013/04/19/199557.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/199557.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/199557.html</trackback:ping><description><![CDATA[<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td><img src="http://user.xmission.com/~nate/pics/naterobins.jpg" alt="nate robins" width="600" height="80" border="0" vspace="0" hspace="0" /></td>
        </tr>
    </tbody>
</table>
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td><img src="http://user.xmission.com/~nate/pics/menu-left.jpg" alt="" width="20" height="30" border="0" vspace="0" hspace="0" /></td>
            <td><a href="http://user.xmission.com/~nate/index.html"><img src="http://user.xmission.com/~nate/pics/main-dim.jpg" alt="main" width="80" height="30" border="0" vspace="0" hspace="0" /></a></td>
            <td><a href="http://user.xmission.com/~nate/opengl.html"><img src="http://user.xmission.com/~nate/pics/opengl-lit.jpg" alt="OPENGL" width="145" height="30" border="0" vspace="0" hspace="0" /></a></td>
            <td><a href="http://user.xmission.com/~nate/chronicles.html"><img src="http://user.xmission.com/~nate/pics/chronicles-dim.jpg" alt="chronicles" width="215" height="30" border="0" vspace="0" hspace="0" /></a></td>
            <td><a href="http://user.xmission.com/~nate/allies.html"><img src="http://user.xmission.com/~nate/pics/allies-dim.jpg" alt="allies" width="120" height="30" border="0" vspace="0" hspace="0" /></a></td>
            <td><img src="http://user.xmission.com/~nate/pics/menu-right.jpg" alt="" width="20" height="30" border="0" vspace="0" hspace="0" /></td>
        </tr>
    </tbody>
</table>
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td><img src="http://user.xmission.com/~nate/pics/up-left.jpg" alt="---" width="300" height="50" border="0" vspace="0" hspace="0" /></td>
            <td align="center" valign="bottom" width="200"><em>Tutors</em></td>
            <td><img src="http://user.xmission.com/~nate/pics/up-right.jpg" alt="---" width="100" height="50" border="0" vspace="0" hspace="0" /></td>
        </tr>
    </tbody>
</table>
<br style="font-family: 'arial narrow', helvetica; font-size: medium; line-height: normal; text-align: " />
<table width="550" border="0" cellpadding="0" cellspacing="20" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td align="center"><a href="http://user.xmission.com/~nate/tutors/tutors-src.zip">Tutors source code package (tutors-src.zip 920KB)</a>&nbsp;<br />
            <br />
            <a href="http://user.xmission.com/~nate/tutors/tutors-win32.zip">Source package + Windows executables (tutors-win32.zip 1.24MB)</a>&nbsp;<br />
            <br />
            <a href="http://user.xmission.com/~nate/tutors/tutors-macosx.zip">Source package + Mac OS X universal binaries (tutors-macosx.zip 1.2MB)</a>&nbsp;<br />
            <br />
            <a href="http://user.xmission.com/~nate/tutors-contrib.html">Contributions</a>&nbsp;from various people (Unix makefiles, etc).&nbsp;<br />
            <br />
            </td>
        </tr>
        <tr>
            <td>
            <table align="right" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/fog.png"><img src="http://user.xmission.com/~nate/tutors/fog-.png" alt="fog" width="225" height="225" border="1" vspace="0" hspace="5" align="right" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The fog tutorial program (shown at right) demonstrates how to use depth cueing (or fog) in OpenGL. It includes command panels that allow dynamic update of the parameters for linear, exponential and exponential<sup>2</sup>&nbsp;fog functions. The fog color can also be dynamically changed.</td>
        </tr>
        <tr>
            <td>
            <table align="left" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/lightposition.png"><img src="http://user.xmission.com/~nate/tutors/lightposition-.png" alt="lightposition" width="225" height="225" border="1" vspace="0" hspace="5" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The lightposition tutorial program (shown at left) demonstrates how lighting position is effected by the viewing transformation. The order in which the light position and the viewing transform are established is configurable, as are the parameters for the position and transform.</td>
        </tr>
        <tr>
            <td>
            <table align="center" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/lightmaterial.png"><img src="http://user.xmission.com/~nate/tutors/lightmaterial-.png" alt="lightmaterial" width="475" height="317" border="1" vspace="0" hspace="5" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            <br />
            The lightmaterial tutorial program (shown above) demonstrates how OpenGL lighting and material properties interact and effect each other. All material &amp; light properties are tweakable. A second command panel allows spotlight parameters &amp; attenuation factors to be changed.</td>
        </tr>
        <tr>
            <td>
            <table align="right" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/projection.png"><img src="http://user.xmission.com/~nate/tutors/projection-.png" alt="projection" width="225" height="225" border="1" vspace="0" hspace="5" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The projection tutorial program (shown at right) demonstrates how the many types of projection transformations work. A command panel is included for gluPerspective(), glOrtho() and glFrustum(). In addition, the viewing transform can be modified via the gluLookat() function.</td>
        </tr>
        <tr>
            <td>
            <table align="left" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/transformation.png"><img src="http://user.xmission.com/~nate/tutors/transformation-.png" alt="transformation" width="225" height="225" border="1" vspace="0" hspace="5" align="left" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The transformation tutorial program (shown at left) demonstrates how the basic transformations of rotate, translate and scale operate in OpenGL. The order of the transforms can be changed to see how that effects rendering.</td>
        </tr>
        <tr>
            <td>
            <table align="center" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/texture.png"><img src="http://user.xmission.com/~nate/tutors/texture-.png" alt="texture" width="475" height="317" border="1" vspace="0" hspace="5" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            <br />
            The texture tutorial program (shown above) demonstrates how OpenGL texturing works. Specifically, the texture coordinates for a polygon are provided for manipulation as are the polygons coordinates themselves. The texture parameter &amp; environment attributes are tweakable. A separate command panel allows manipulation of the texture matrix.</td>
        </tr>
        <tr>
            <td>
            <table align="right" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr>
                        <td><a href="http://user.xmission.com/~nate/tutors/shapes.png"><img src="http://user.xmission.com/~nate/tutors/shapes-.png" alt="shapes" width="263" height="225" border="1" vspace="0" hspace="5" align="right" /></a></td>
                    </tr>
                    <tr>
                        <td><center><font size="1">(click on image to enlarge it)</font></center></td>
                    </tr>
                </tbody>
            </table>
            The shapes tutorial program (shown at right) demonstrates how the many types of primitives work. A command panel for each primitive type is included. This tutorial was written by Mason Woo (<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#109;&#97;&#115;&#111;&#110;&#64;&#119;&#111;&#111;&#46;&#99;&#111;&#109;">mason@woo.com</a>).</td>
        </tr>
    </tbody>
</table>
<br style="font-family: 'arial narrow', helvetica; font-size: medium; line-height: normal; text-align: " />
<br style="font-family: 'arial narrow', helvetica; font-size: medium; line-height: normal; text-align: " />
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td align="center"><a href="http://www.digits.com/web_counter"><img src="http://counter.digits.com/wc/-d/8/-r/-z/-c/26/-f/aaaaaa/-b/ffffff/opengl_tutors" border="0"  alt="" /></a></td>
        </tr>
    </tbody>
</table>
<br style="font-family: 'arial narrow', helvetica; font-size: medium; line-height: normal; text-align: " />
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-family: 'arial narrow', helvetica; background-color: #ffffff; ">
    <tbody>
        <tr>
            <td><img src="http://user.xmission.com/~nate/pics/dn-left.jpg" alt="---" width="100" height="50" border="0" vspace="0" hspace="0" /></td>
            <td><img src="http://user.xmission.com/~nate/pics/dn-middle.jpg" alt="---" width="200" height="50" border="0" vspace="0" hspace="0" /></td>
            <td><img src="http://user.xmission.com/~nate/pics/dn-right.jpg" alt="---" width="300" height="50" border="0" vspace="0" hspace="0" /><br />
            <br />
            </td>
        </tr>
    </tbody>
</table>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/199557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2013-04-19 00:24 <a href="http://www.cppblog.com/biao/archive/2013/04/19/199557.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：大小写不敏感的正则表达式写法</title><link>http://www.cppblog.com/biao/archive/2012/12/09/196128.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sun, 09 Dec 2012 10:19:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/12/09/196128.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/196128.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/12/09/196128.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/196128.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/196128.html</trackback:ping><description><![CDATA[在前面加上 (?i)即可，如<br />String name = "names.NSF".replaceAll("(?i)\\.nsf$", "");<br />name的值为 names<img src ="http://www.cppblog.com/biao/aggbug/196128.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-12-09 18:19 <a href="http://www.cppblog.com/biao/archive/2012/12/09/196128.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MVN：Maven bundle error：解决Maven管理的项目下"Missing artifact xxx bundle"问题</title><link>http://www.cppblog.com/biao/archive/2012/11/27/195716.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Mon, 26 Nov 2012 22:32:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/11/27/195716.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/195716.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/11/27/195716.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/195716.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/195716.html</trackback:ping><description><![CDATA[<div>例如使用maven编译使用了mina的包的工程，出现如下提示:&nbsp;</div>
<div>[INFO] Scanning for projects...</div>
<div>[INFO] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div>
<div>[INFO] ------------------------------------------------------------------------</div>
<div>[INFO] Building Hello 1.0</div>
<div>[INFO] ------------------------------------------------------------------------</div>
<div>[INFO] ------------------------------------------------------------------------</div>
<div>[INFO] BUILD FAILURE</div>
<div>[INFO] ------------------------------------------------------------------------</div>
<div>[INFO] Total time: 1.187s</div>
<div>[INFO] Finished at: Tue Nov 27 06:27:12 CST 2012</div>
<div>[INFO] Final Memory: 3M/81M</div>
<div>[INFO] ------------------------------------------------------------------------</div>
<div>[ERROR] Failed to execute goal on project Hello: Could not resolve dependencies for project tur:Hello:jar:1.0: <span style="color: red; ">The following artifacts could not be resolved: org.apache.mina:mina-core:</span><span style="color: #ff00ff; ">bundle</span><span style="color: red; ">:2.0.7</span>, org.apache.mina:mina-integration-beans:bundle:2.0.7, org.apache.mina:mina-integration-jmx:bundle:2.0.7, org.apache.mina:mina-integration-ognl:bundle:2.0.7, org.apache.mina:mina-statemachine:bundle:2.0.7: Failure to find org.apache.mina:mina-core:bundle:2.0.7 in http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -&gt; [Help 1]</div>
<div>[ERROR]&nbsp;</div>
<div>[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.</div>
<div>[ERROR] Re-run Maven using the -X switch to enable full debug logging.</div>
<div>[ERROR]&nbsp;</div>
<div>[ERROR] For more information about the errors and possible solutions, please read the following articles:</div>
<div>[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException</div>
<div><br />
</div>
<div>From:&nbsp;<a href="http://blog.csdn.net/jialechan/article/details/6821389">http://blog.csdn.net/jialechan/article/details/6821389</a></div>
<div>
<div style="color: #333333; line-height: 26px; text-align: left; background-color: #ffffff; font-family: 'AR PL UKai CN'; font-size: 16px; ">这个问题可能是依赖的项目打包成bundle造成，比如mina就是这样的，打包成bundle,例子：</div>
<div style="color: #333333; line-height: 26px; text-align: left; background-color: #ffffff; font-family: 'AR PL UKai CN'; font-size: 16px; ">
<div class="dp-highlighter bg_html" style="width: 687px; ">
<div class="bar">
<div class="tools"><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/jialechan/article/details/6821389#" class="ViewSource" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a><a href="http://blog.csdn.net/jialechan/article/details/6821389#" class="CopyToClipboard" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">copy</a>
<div style="position: absolute; left: 392px; top: 434px; width: 18px; height: 18px; z-index: 99; "><embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_1" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&amp;width=18&amp;height=18" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-xml">
    <li class="alt" style="line-height: 18px; "><span class="tag" style="color: #993300; font-weight: bold; ">&lt;</span><span class="tag-name" style="color: #993300; font-weight: bold; ">dependency</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
    <li class="" style="line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: #993300; font-weight: bold; ">&lt;</span><span class="tag-name" style="color: #993300; font-weight: bold; ">groupId</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>org.apache.mina<span class="tag" style="color: #993300; font-weight: bold; ">&lt;/</span><span class="tag-name" style="color: #993300; font-weight: bold; ">groupId</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
    <li class="alt" style="line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: #993300; font-weight: bold; ">&lt;</span><span class="tag-name" style="color: #993300; font-weight: bold; ">artifactId</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>mina-core<span class="tag" style="color: #993300; font-weight: bold; ">&lt;/</span><span class="tag-name" style="color: #993300; font-weight: bold; ">artifactId</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
    <li class="" style="line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: #993300; font-weight: bold; ">&lt;</span><span class="tag-name" style="color: #993300; font-weight: bold; ">version</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>2.0.4<span class="tag" style="color: #993300; font-weight: bold; ">&lt;/</span><span class="tag-name" style="color: #993300; font-weight: bold; ">version</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
    <li class="alt" style="line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: #993300; font-weight: bold; ">&lt;</span><span class="tag-name" style="color: #993300; font-weight: bold; ">type</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>bundle<span class="tag" style="color: #993300; font-weight: bold; ">&lt;/</span><span class="tag-name" style="color: #993300; font-weight: bold; ">type</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
    <li class="" style="line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: #993300; font-weight: bold; ">&lt;</span><span class="tag-name" style="color: #993300; font-weight: bold; ">scope</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>compile<span class="tag" style="color: #993300; font-weight: bold; ">&lt;/</span><span class="tag-name" style="color: #993300; font-weight: bold; ">scope</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
    <li class="alt" style="line-height: 18px; "><span class="tag" style="color: #993300; font-weight: bold; ">&lt;/</span><span class="tag-name" style="color: #993300; font-weight: bold; ">dependency</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
</ol>
</div>
<br />
</div>
<div style="color: #333333; line-height: 26px; text-align: left; background-color: #ffffff; font-family: 'AR PL UKai CN'; font-size: 16px; ">加入上面依赖出现错误如下：</div>
<div align="left" style="color: #333333; line-height: 26px; background-color: #ffffff; font-family: 'AR PL UKai CN'; font-size: 16px; "><span style="color: #008080; font-family: 'Courier New'; font-size: 10pt; ">11-9-26 上午10时21分30秒: Maven Builder: AUTO_BUILD requireFullBuild</span></div>
<div align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><span style="font-family: 'Courier New'; font-size: 10pt; color: #008080; ">11-9-26 上午10时21分30秒: Build errors for test-http-mina; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project test-http-mina: Could not resolve dependencies for project com.tecno:test-http-mina:jar:0.0.1-SNAPSHOT: Failure to find org.apache.mina:mina-core:bundle:2.0.4 in http://uk.maven.org/maven2/ was cached in the local repository, resolution will not be reattempted until the update interval of uk.maven.org has elapsed or updates are forced</span><br />
<span style="font-family: 'Courier New'; font-size: 10pt; color: #008080; ">11-9-26 上午10时22分11秒: Refreshing [/test-http-mina/pom.xml]</span><br />
<span style="font-family: 'Courier New'; font-size: 10pt; color: #008080; ">11-9-26 上午10时22分11秒: Missing artifact org.apache.mina:mina-core:bundle:2.0.4:compile</span><br />
<span style="font-family: 'Courier New'; font-size: 10pt; color: #008080; ">11-9-26 上午10时22分11秒: Maven Builder: AUTO_BUILD&nbsp;</span>
<div align="left" style="color: #008080; font-family: 'AR PL UKai CN'; font-size: 16px; ">
<div align="left"><span style="font-family: 'Courier New'; font-size: 10px; "><span style="color: #0000ff; "></span></span></div>
</div>
<br />
</div>
<div align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">
<div align="left">原因</div>
<div align="left">mina打包为了bundle格式，为此，需要添加插件</div>
<div align="left">在maven的pom.xml中plugins段中加入plugin即可</div>
<div align="left">
<div align="left">
<div class="dp-highlighter bg_html" style="width: 687px; ">
<div class="bar">
<div class="tools"><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/jialechan/article/details/6821389#" class="ViewSource" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a><a href="http://blog.csdn.net/jialechan/article/details/6821389#" class="CopyToClipboard" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">copy</a>
<div style="position: absolute; left: 392px; top: 1071px; width: 18px; height: 18px; z-index: 99; "><embed id="ZeroClipboardMovie_2" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_2" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&amp;width=18&amp;height=18" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-xml">
    <li class="alt" style="line-height: 18px; "><span class="tag" style="color: #993300; font-weight: bold; ">&lt;</span><span class="tag-name" style="color: #993300; font-weight: bold; ">plugin</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
    <li class="" style="line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: #993300; font-weight: bold; ">&lt;</span><span class="tag-name" style="color: #993300; font-weight: bold; ">groupId</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>org.apache.felix<span class="tag" style="color: #993300; font-weight: bold; ">&lt;/</span><span class="tag-name" style="color: #993300; font-weight: bold; ">groupId</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
    <li class="alt" style="line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: #993300; font-weight: bold; ">&lt;</span><span class="tag-name" style="color: #993300; font-weight: bold; ">artifactId</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>maven-bundle-plugin<span class="tag" style="color: #993300; font-weight: bold; ">&lt;/</span><span class="tag-name" style="color: #993300; font-weight: bold; ">artifactId</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
    <li class="" style="line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: #993300; font-weight: bold; ">&lt;</span><span class="tag-name" style="color: #993300; font-weight: bold; ">extensions</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>true<span class="tag" style="color: #993300; font-weight: bold; ">&lt;/</span><span class="tag-name" style="color: #993300; font-weight: bold; ">extensions</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
    <li class="alt" style="line-height: 18px; "><span class="tag" style="color: #993300; font-weight: bold; ">&lt;/</span><span class="tag-name" style="color: #993300; font-weight: bold; ">plugin</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
</ol>
</div>
其中
<div class="dp-highlighter bg_html" style="width: 687px; ">
<div class="bar">
<div class="tools"><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/jialechan/article/details/6821389#" class="ViewSource" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a><a href="http://blog.csdn.net/jialechan/article/details/6821389#" class="CopyToClipboard" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">copy</a>
<div style="position: absolute; left: 392px; top: 1282px; width: 18px; height: 18px; z-index: 99; "><embed id="ZeroClipboardMovie_3" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_3" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=3&amp;width=18&amp;height=18" wmode="transparent"></div>
</div>
</div>
<ol start="1" class="dp-xml">
    <li class="alt" style="line-height: 18px; "><span class="tag" style="color: #993300; font-weight: bold; ">&lt;</span><span class="tag-name" style="color: #993300; font-weight: bold; ">extensions</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>true<span class="tag" style="color: #993300; font-weight: bold; ">&lt;/</span><span class="tag-name" style="color: #993300; font-weight: bold; ">extensions</span><span class="tag" style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li>
</ol>
</div>
是必须的。</div>
</div>
</div>
</div>
<div><br />
</div>
@import url(http://www.cppblog.com/cutesoft_client/cuteeditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/195716.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-11-27 06:32 <a href="http://www.cppblog.com/biao/archive/2012/11/27/195716.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：逆转字符串</title><link>http://www.cppblog.com/biao/archive/2012/11/22/195571.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Thu, 22 Nov 2012 12:20:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/11/22/195571.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/195571.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/11/22/195571.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/195571.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/195571.html</trackback:ping><description><![CDATA[<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000FF; ">package</span>&nbsp;com.tur.demo;<br />
<br />
<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;Hello&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;main(String[]&nbsp;args)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(reverseWords("How&nbsp;are&nbsp;you!"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(reverseWords("do&nbsp;justice&nbsp;to&nbsp;a&nbsp;dinner"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(reverseWords(""));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(reverseWords("A"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(reverseWords("A&nbsp;Biao"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(reverseWords("!A&nbsp;Biao&nbsp;C."));<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;String&nbsp;reverseWords(String&nbsp;str)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;start&nbsp;=&nbsp;1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;end&nbsp;=&nbsp;0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">char</span>[]&nbsp;chs&nbsp;=&nbsp;str.toCharArray();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;1.&nbsp;先逆转整个字符串</span><span style="color: #008000; "><br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reverseCharactersInRange(chs,&nbsp;0,&nbsp;chs.length&nbsp;-&nbsp;1);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;2.&nbsp;再逆转逆转后的字符数组中组成单词的字符</span><span style="color: #008000; "><br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>&nbsp;(<span style="color: #0000FF; ">int</span>&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;chs.length;&nbsp;++i)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;(Character.isLetter(chs[i]))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;找到组成单词的字符的起始和结束位置</span><span style="color: #008000; "><br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;(start&nbsp;&gt;&nbsp;end)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start&nbsp;=&nbsp;end&nbsp;=&nbsp;i;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;++end;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;(start&nbsp;&lt;&nbsp;end)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reverseCharactersInRange(chs,&nbsp;start,&nbsp;end);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start&nbsp;=&nbsp;chs.length;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;(start&nbsp;&lt;&nbsp;end)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reverseCharactersInRange(chs,&nbsp;start,&nbsp;end);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;String(chs);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;reverseCharactersInRange(<span style="color: #0000FF; ">char</span>[]&nbsp;chs,&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;start,&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;end)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;times&nbsp;=&nbsp;(end&nbsp;-&nbsp;start&nbsp;+&nbsp;1)&nbsp;/&nbsp;2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>&nbsp;(<span style="color: #0000FF; ">int</span>&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;times;&nbsp;++i)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">char</span>&nbsp;temp&nbsp;=&nbsp;chs[start&nbsp;+&nbsp;i];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chs[start&nbsp;+&nbsp;i]&nbsp;=&nbsp;chs[end&nbsp;-&nbsp;i];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chs[end&nbsp;-&nbsp;i]&nbsp;=&nbsp;temp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</div><img src ="http://www.cppblog.com/biao/aggbug/195571.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-11-22 20:20 <a href="http://www.cppblog.com/biao/archive/2012/11/22/195571.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：Nio的MD5</title><link>http://www.cppblog.com/biao/archive/2012/10/23/193711.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Tue, 23 Oct 2012 02:04:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/10/23/193711.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/193711.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/10/23/193711.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/193711.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/193711.html</trackback:ping><description><![CDATA[<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; ">from:&nbsp;</span>
<a href="http://www.iteye.com/topic/1127319">http://www.iteye.com/topic/1127319</a>&nbsp;<br /><br /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; ">MD5 nio的简单版，看你们老是怀疑java慢&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; ">C++ MD5工具验证结果：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; ">File: K:\Games\World of Warcraft\Data\common.MPQ&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; ">Size: 2226587191 bytes&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; ">Modified: 2008年11月19日 星期三, 12:57:24&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; ">MD5: CD9F9C5523F3BA3866B81CCC74ED6476&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; ">java运行结果，毫秒&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14.399999618530273px; line-height: 25.200000762939453px; background-color: #efefef; ">耗时：12672,cd9f9c5523f3ba3866b81ccc74ed6476&nbsp;</span>&nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;hashType&nbsp;=&nbsp;"MD5";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileInputStream&nbsp;fStream&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">try</span>&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageDigest&nbsp;md5&nbsp;=&nbsp;MessageDigest.getInstance(hashType);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fStream&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;FileInputStream(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">"K:\\Games\\World&nbsp;of&nbsp;Warcraft\\Scan.dll");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">"K:\\Games\\World&nbsp;of&nbsp;Warcraft\\Data\\patch-3.MPQ");</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"K:\\Games\\World&nbsp;of&nbsp;Warcraft\\Data\\common.MPQ");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileChannel&nbsp;fChannel&nbsp;=&nbsp;fStream.getChannel();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ByteBuffer&nbsp;buffer&nbsp;=&nbsp;ByteBuffer.allocate(8*1024);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">long</span>&nbsp;s&nbsp;=&nbsp;System.currentTimeMillis();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>&nbsp;(&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;count&nbsp;=&nbsp;fChannel.read(&nbsp;buffer&nbsp;);&nbsp;count&nbsp;!=-1&nbsp;;&nbsp;count&nbsp;=&nbsp;fChannel.read(&nbsp;buffer&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.flip();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;md5.update(&nbsp;buffer&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(&nbsp;!buffer.hasRemaining()&nbsp;){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">System.out.println("count:"+count);</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.clear();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;=&nbsp;System.currentTimeMillis()&nbsp;-&nbsp;s;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&nbsp;"耗时："+s+","+getString(&nbsp;md5.digest()&nbsp;)&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #0000FF; ">catch</span>&nbsp;(NoSuchAlgorithmException&nbsp;e)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #0000FF; ">catch</span>&nbsp;(FileNotFoundException&nbsp;e)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #0000FF; ">catch</span>&nbsp;(IOException&nbsp;e)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<span style="color: #0000FF; ">finally</span>{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">try</span>&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(&nbsp;fStream!=<span style="color: #0000FF; ">null</span>&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fStream.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #0000FF; ">catch</span>&nbsp;(IOException&nbsp;e)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</div><img src ="http://www.cppblog.com/biao/aggbug/193711.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-10-23 10:04 <a href="http://www.cppblog.com/biao/archive/2012/10/23/193711.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：展开树节点</title><link>http://www.cppblog.com/biao/archive/2012/10/10/193098.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Tue, 09 Oct 2012 23:40:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/10/10/193098.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/193098.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/10/10/193098.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/193098.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/193098.html</trackback:ping><description><![CDATA[<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><span style="color: red; ">使用方法：SwingUtil.expandTree(tree);</span></div>
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><span style="color: #0000FF; "><br />
</span></div>
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;SwingUtil&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;expandTree(JTree&nbsp;tree)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TreeNode&nbsp;root&nbsp;=&nbsp;(TreeNode)&nbsp;tree.getModel().getRoot();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expandTree(tree,&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;TreePath(root));<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;expandTree(JTree&nbsp;tree,&nbsp;TreePath&nbsp;path)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TreeNode&nbsp;node&nbsp;=&nbsp;(TreeNode)&nbsp;path.getLastPathComponent();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Go&nbsp;to&nbsp;leaf</span><span style="color: #008000; "><br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;(node.getChildCount()&nbsp;&gt;&nbsp;0)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enumeration&lt;TreeNode&gt;&nbsp;children&nbsp;=&nbsp;node.children();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">while</span>&nbsp;(children.hasMoreElements())&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TreeNode&nbsp;n&nbsp;=&nbsp;children.nextElement();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TreePath&nbsp;newPath&nbsp;=&nbsp;path.pathByAddingChild(n);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expandTree(tree,&nbsp;newPath);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tree.expandPath(path);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</div>
@import url(http://www.cppblog.com/cutesoft_client/cuteeditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/193098.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-10-10 07:40 <a href="http://www.cppblog.com/biao/archive/2012/10/10/193098.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：unicode big endian</title><link>http://www.cppblog.com/biao/archive/2012/10/08/193012.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Mon, 08 Oct 2012 09:43:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/10/08/193012.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/193012.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/10/08/193012.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/193012.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/193012.html</trackback:ping><description><![CDATA[<h2>endian词源</h2><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　&#8220;</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">endian</strong><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">&#8221;一词来源于</span><a target="_blank" href="http://baike.baidu.com/view/177903.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">乔纳森&#183;斯威夫特</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">的小说</span><a target="_blank" href="http://baike.baidu.com/view/79427.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">格列佛游记</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">。小说中，</span><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; color: red; ">小人国为水煮蛋该从大的一端（Big-End）剥开还是小的一端（Little-End）剥开而争论，争论的双方分别被称为Big-endians和Little-endians。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　1980年，Danny Cohen在其著名的论文"</span><em style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">On Holy Wars and a Plea for Peace</em><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">"中为平息一场关于</span><a target="_blank" href="http://baike.baidu.com/view/60408.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">字节</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">该以什么样的顺序传送的争论而引用了该词。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">endian翻译为&#8220;<a target="_blank" href="http://baike.baidu.com/view/2194385.htm" style="color: #136ec2; ">字节序</a>&#8221;</strong><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">，又称</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">端序</strong><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">，</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">尾序</strong><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">。在</span><a target="_blank" href="http://baike.baidu.com/view/92404.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">计算机科学</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">领域中，</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">字节序</strong><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">是指存放多字节数据的字节（byte）的顺序，典型的情况是整数在</span><a target="_blank" href="http://baike.baidu.com/view/1082.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">内存</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">中的存放方式和</span><a target="_blank" href="http://baike.baidu.com/view/1542295.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">网络传输</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">的传输顺序。Endianness有时候也可以用指</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">位序</strong><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">（bit）。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　一般而言，字节序指示了一个UCS-2</span><a target="_blank" href="http://baike.baidu.com/view/263416.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">字符</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">的哪个字节存储在低地址。如果LSByte在MSByte的前面，即LSB为低地址，则该字节序是</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">小端序</strong><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">；反之则是</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; "><a target="_blank" href="http://baike.baidu.com/view/911873.htm" style="color: #136ec2; ">大端</a>序</strong><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">。在</span><a target="_blank" href="http://baike.baidu.com/view/1317473.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">网络编程</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">中，字节序是一个必须被考虑的因素，因为不同的</span><a target="_blank" href="http://baike.baidu.com/view/50152.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">处理器</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">体系可能采用不同的字节序。在多平台的代码编程中，字节序可能会导致难以察觉的</span><a target="_blank" href="http://baike.baidu.com/view/1743.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">bug</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">BIG ENDIAN</strong><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">：</strong><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">最低位地址存放高位字节，可称高位优先，内存从最低地址开始按顺序存放（高数位数字先写）。</span><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; color: red; ">最高位字节放最前面。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　</span><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">LITTLE ENDIAN</strong><strong style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">：</strong><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">最低位地址存放低位字节，可称低位优先，内存从最低地址开始按顺序存放（低数位数字先写）。</span><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; color: red; ">最低位字节放最前面。</span><div style="height: 30px; line-height: 30px; overflow: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><h2><span editable-title"="" data-edit-id="1485693:1485693:2" style="font-size: 12px; float: right; display: block; margin: 10px 0px 0px; color: #3366cc; font-weight: normal; "><a href="http://baike.baidu.com/view/1485693.htm#" style="color: #136ec2; background-image: url(http://baike.bdimg.com/static/lemma/css/img/content_icon.gif?@=7apxk1); height: 15px; line-height: 16px; display: block; width: 52px; padding-left: 18px; background-position: -86px -573px; background-repeat: no-repeat no-repeat; ">编辑本段</a></span><a name="2" style="text-decoration: underline; color: rgb(19, 110, 194); width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a><a name="sub1485693_2" style="text-decoration: underline; color: rgb(19, 110, 194); width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a>Big Endian解释</h2><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　最低位地址存放高位字节，可称高位优先，内存从最低地址开始按顺序存放（高数位数字先写）。最高位字节放最前面。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　例如&#8220;汉&#8221;字的Unicode编码是6C49。如果将6C写在前面，就是big endian。还是将49写在前面，就是little endian</span><div style="height: 30px; line-height: 30px; overflow: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><h2><span editable-title"="" data-edit-id="1485693:1485693:3" style="font-size: 12px; float: right; display: block; margin: 10px 0px 0px; color: #3366cc; font-weight: normal; "><a href="http://baike.baidu.com/view/1485693.htm#" style="color: #136ec2; background-image: url(http://baike.bdimg.com/static/lemma/css/img/content_icon.gif?@=7apxk1); height: 15px; line-height: 16px; display: block; width: 52px; padding-left: 18px; background-position: -86px -573px; background-repeat: no-repeat no-repeat; ">编辑本段</a></span><a name="3" style="text-decoration: underline; color: rgb(19, 110, 194); width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a><a name="sub1485693_3" style="text-decoration: underline; color: rgb(19, 110, 194); width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a>Big Endian示例图</h2><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　对于单一的</span><a target="_blank" href="http://baike.baidu.com/view/60408.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">字节</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">（</span><em style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">a byte</em><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">），大部分</span><a target="_blank" href="http://baike.baidu.com/view/50152.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">处理器</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">以相同的顺序处理</span><a target="_blank" href="http://baike.baidu.com/view/1541880.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">位元</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">（bit），因此单字节的存放方法和传输方式一般相同。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　对于多字节数据，如整数（32位机中一般占4字节），在不同的处理器的存放方式主要有两种，以</span><a target="_blank" href="http://baike.baidu.com/view/1082.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">内存</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">中0x0A0B0C0D的存放方式为例，分别有以下几种方式：</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　</span><em style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">注: 0x前缀代表十六进制。</em><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　</span><em style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">数据以8bit为单位</em><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">:</span><table log-set-param"="" log-set-param="table_view" style="border-collapse: collapse; border-spacing: 0px; margin: 5px 0px; word-wrap: break-word; word-break: break-all; font-size: 12px; line-height: 12px; color: #666666; font-family: arial, 宋体, sans-serif; text-align: start; background-color: #ffffff; "><tbody><tr><td style="margin: 0px; padding: 0px 10px; border-style: solid; border-color: #dddddd; line-height: 22px; "><em>地址增长方向</em>&nbsp;&#8594;</td></tr><tr><td style="margin: 0px; padding: 0px 10px; border-style: solid; border-color: #dddddd; line-height: 22px; ">...</td><td style="margin: 0px; padding: 0px 10px; border-style: solid; border-color: #dddddd; line-height: 22px; ">0x0A</td><td style="margin: 0px; padding: 0px 10px; border-style: solid; border-color: #dddddd; line-height: 22px; ">0x0B</td><td style="margin: 0px; padding: 0px 10px; border-style: solid; border-color: #dddddd; line-height: 22px; ">0x0C</td><td style="margin: 0px; padding: 0px 10px; border-style: solid; border-color: #dddddd; line-height: 22px; ">0x0D</td><td style="margin: 0px; padding: 0px 10px; border-style: solid; border-color: #dddddd; line-height: 22px; ">...</td></tr></tbody></table><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">示例中，</span><a target="_blank" href="http://baike.baidu.com/view/5150456.htm" style="color: #136ec2; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">最高有效位</a><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">（MSB, Most Significant Byte）是0x0A 存储在最低的内存地址处。下一个字节0x0B存在后面的地址处。正类似于十六进制字节从左到右的阅读顺序。</span><div style="height: 14px; line-height: 14px; font-size: 12px; overflow: hidden; font-family: arial, 宋体, sans-serif; background-color: #ffffff; "></div><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">　　</span><em style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">数据以16bit为单位</em><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">:</span><table log-set-param"="" log-set-param="table_view" style="border-collapse: collapse; border-spacing: 0px; margin: 5px 0px; word-wrap: break-word; word-break: break-all; font-size: 12px; line-height: 12px; color: #666666; font-family: arial, 宋体, sans-serif; text-align: start; background-color: #ffffff; "><tbody><tr><td style="margin: 0px; padding: 0px 10px; border-style: solid; border-color: #dddddd; line-height: 22px; "><em>地址增长方向</em>&nbsp;&#8594;</td></tr><tr><td style="margin: 0px; padding: 0px 10px; border-style: solid; border-color: #dddddd; line-height: 22px; ">...</td><td style="margin: 0px; padding: 0px 10px; border-style: solid; border-color: #dddddd; line-height: 22px; ">0x0A0B</td><td style="margin: 0px; padding: 0px 10px; border-style: solid; border-color: #dddddd; line-height: 22px; ">0x0C0D</td><td style="margin: 0px; padding: 0px 10px; border-style: solid; border-color: #dddddd; line-height: 22px; ">...</td></tr></tbody></table><span style="font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff; ">最高的16bit单元0x0A0B存储在低位。</span>&nbsp;<img src ="http://www.cppblog.com/biao/aggbug/193012.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-10-08 17:43 <a href="http://www.cppblog.com/biao/archive/2012/10/08/193012.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：IntelliJ Idea添加Java documentation and Source Code</title><link>http://www.cppblog.com/biao/archive/2012/09/23/191707.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sun, 23 Sep 2012 06:31:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/09/23/191707.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/191707.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/09/23/191707.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/191707.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/191707.html</trackback:ping><description><![CDATA[在Mac上的Java默认是没有帮助文档和源代码的。
<div>1. 到官网上下载 JDK Documentation and Source Code</div>
<div>2. 放到</div>
<div>/localhost/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/docs.zip</div>
<div>/localhost/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/src.zip</div>
<div>3. 在IntelliJ Idea的File-&gt;Project Structure...-&gt;SDKs:</div>
<div>&nbsp; &nbsp;把src.zip添加到Sourcepath</div>
<div>&nbsp; &nbsp;把docs.zip添加到Documentation Paths</div><img src ="http://www.cppblog.com/biao/aggbug/191707.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-09-23 14:31 <a href="http://www.cppblog.com/biao/archive/2012/09/23/191707.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：Intellij Idea预览颜色</title><link>http://www.cppblog.com/biao/archive/2012/09/23/191691.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sun, 23 Sep 2012 03:50:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/09/23/191691.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/191691.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/09/23/191691.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/191691.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/191691.html</trackback:ping><description><![CDATA[用16进制字符串定制的颜色，在IntelliJ Idea里把放到这个字符串上，按下Shift键，会显示出颜色的预览，如图
<div><img src="http://www.cppblog.com/images/cppblog_com/biao/idea-preview-color.png" width="442" height="172" alt="" /><br />
</div><img src ="http://www.cppblog.com/biao/aggbug/191691.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-09-23 11:50 <a href="http://www.cppblog.com/biao/archive/2012/09/23/191691.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：文件路径</title><link>http://www.cppblog.com/biao/archive/2012/09/19/191267.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Wed, 19 Sep 2012 09:18:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/09/19/191267.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/191267.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/09/19/191267.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/191267.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/191267.html</trackback:ping><description><![CDATA[<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #efefef; ">From:&nbsp;</span>
<a href="http://www.iteye.com/topic/1126812">http://www.iteye.com/topic/1126812</a>&nbsp;<br /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #efefef; ">1. PropUtil .class.getClassLoader().getResourceAsStream("prop.properties");&nbsp; 说明这个prop.properties和类PropUtil.class是在同一个目录下&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #efefef; ">2. 如果改成PropUtil .class.getClassLoader().getResourceAsStream("/prop.properties"); 注意有个斜杠，说明是在classpath根目录下，eclipse写的话一般如果是bin目录，netbeans的话可能会在build/classes目录下&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #efefef; ">3. FileInputStream("prop.properties");&nbsp; 这种是从System Property 'user.dir'下读prop.properties, 用IDE编写的话默认就是你的工程目录，一般来说user.dir是执行java命令所在的当前目录。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; background-color: #efefef; ">4. 不存在所谓的JAVASE默认根路径的说法，java（无论是J2SE还是，J2EE, Web）中只有classpath，看你的java命令怎么配置classpath</span>&nbsp;<br /><br /><img src ="http://www.cppblog.com/biao/aggbug/191267.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-09-19 17:18 <a href="http://www.cppblog.com/biao/archive/2012/09/19/191267.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：Maven依赖包下载</title><link>http://www.cppblog.com/biao/archive/2012/09/19/191180.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Tue, 18 Sep 2012 16:10:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/09/19/191180.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/191180.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/09/19/191180.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/191180.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/191180.html</trackback:ping><description><![CDATA[Maven依赖的包可以到Maven的中心仓库&nbsp;<a href="http://search.maven.org/#browse" title="http://search.maven.org/#browse">http://search.maven.org/#browse</a>&nbsp;进行查找下载
<div>例如需要MyBatis的依赖包，搜索mybatis，然后选择正确的路径，复制生成的内容到项目的pom.xml，在IDEA中，当保存pom.xml后，IDEA会自动的去下载还没有下载到本地仓库的jar包。</div>
<div><br />
</div>
<div>
<table border="0" cellpadding="0" cellspacing="0" style="margin: 0px !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; width: 348px; border-collapse: collapse; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; text-align: left !important; top: auto !important; vertical-align: baseline !important; box-sizing: content-box !important; font-size: 13px; min-height: inherit !important; color: #222222; white-space: nowrap; ">
    <tbody style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; ">
        <tr style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; ">
            <td class="code" style="margin: 0px !important; font-size: 1em !important; border: 0px !important; padding: 0px !important; width: 348px; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; box-sizing: content-box !important; min-height: inherit !important; ">
            <div class="container" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; ">
            <div class="line number1 index0 alt2" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; background-color: white !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding-right: 1em !important; padding-left: 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; "><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&lt;</code><code class="xml keyword" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; color: #006699 !important; ">dependency</code><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&gt;</code></div>
            <div class="line number2 index1 alt1" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; background-color: white !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding-right: 1em !important; padding-left: 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; "><code class="xml spaces" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; ">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&lt;</code><code class="xml keyword" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; color: #006699 !important; ">groupId</code><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&gt;org.mybatis&lt;/</code><code class="xml keyword" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; color: #006699 !important; ">groupId</code><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&gt;</code></div>
            <div class="line number3 index2 alt2" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; background-color: white !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding-right: 1em !important; padding-left: 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; "><code class="xml spaces" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; ">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&lt;</code><code class="xml keyword" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; color: #006699 !important; ">artifactId</code><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&gt;mybatis&lt;/</code><code class="xml keyword" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; color: #006699 !important; ">artifactId</code><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&gt;</code></div>
            <div class="line number4 index3 alt1" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; background-color: white !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding-right: 1em !important; padding-left: 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; "><code class="xml spaces" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; ">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&lt;</code><code class="xml keyword" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; color: #006699 !important; ">version</code><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&gt;3.1.1&lt;/</code><code class="xml keyword" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; color: #006699 !important; ">version</code><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&gt;</code></div>
            <div class="line number5 index4 alt2" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; background-color: white !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding-right: 1em !important; padding-left: 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; "><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&lt;/</code><code class="xml keyword" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; color: #006699 !important; ">dependency</code><code class="xml plain" style="margin: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; min-height: inherit !important; color: black !important; ">&gt;</code></div>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<br />
</div>
<div><strong>手动下载：</strong></div>
<div><!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<div style="font-family: Arial; font-size: medium; line-height: normal; "><span style="font-size: 12pt; ">分别单独下载 source code 和 javadoc 都没有问题，如果使用第3步一起下载的话，有时候 javadoc 有可能下载不下来.</span><br />
</div>
<div style="font-family: Arial; font-size: medium; line-height: normal; "><hr />
</div>
<div style="font-family: Arial; font-size: medium; line-height: normal; "><font color="#9655FF"><span style="font-size: 12pt; ">1. 下载</span><span style="background-color: #ffffff; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; line-height: 19px; font-size: 12pt; ">所有在POM中的的source code</span></font></div>
<div style="font-family: Arial; font-size: medium; line-height: normal; "><strong style="font-size: 12pt; ">&nbsp; &nbsp; &nbsp;mvn dependency:sources&nbsp;</strong></div>
<div style="font-family: Arial; font-size: medium; line-height: normal; "><br />
</div>
<div style="font-family: Arial; font-size: medium; line-height: normal; "><font color="#9655FF"><span style="font-size: 12pt; ">2. 下载</span><span style="background-color: #ffffff; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; line-height: 19px; font-size: 12pt; ">所有在POM中的的</span><span style="background-color: #ffffff; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; line-height: 19px; font-size: 12pt; ">Javadocs</span></font></div>
<div style="font-family: Arial; font-size: medium; line-height: normal; "><strong style="font-size: 12pt; ">&nbsp; &nbsp; &nbsp;mvn dependency:resolve -Dclassifier=javadoc</strong></div>
<div style="font-family: Arial; font-size: medium; line-height: normal; "><hr />
</div>
<div style="font-family: Arial; font-size: medium; line-height: normal; "><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff;"><font color="#B2B0B0"><span style="font-size: 12pt; ">3. 使用参数下载源码包与doc包：</span></font></span></div>
<div style="font-family: Arial; font-size: medium; line-height: normal; "><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff;"><font color="#B2B0B0"><span style="font-size: 12pt; ">&nbsp; &nbsp; &nbsp;-DdownloadSources=true 下载源代码jar&nbsp;</span></font></span></div>
<div style="font-family: Arial; font-size: medium; line-height: normal; "><font color="#B2B0B0"><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; font-size: 12pt; ">&nbsp; &nbsp; &nbsp;-DdownloadJavadocs=true&nbsp;</span><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; font-size: 12pt; ">下载javadoc包</span></font></div>
<div style="font-family: Arial; font-size: medium; line-height: normal; "><font color="#B2B0B0"><strong style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; font-size: 12pt; ">&nbsp; &nbsp; &nbsp;mvn dependency:sources -DdownloadSources=true -DdownloadJavadocs=true</strong><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; font-size: 12pt; ">&nbsp;</span></font></div>
</div><img src ="http://www.cppblog.com/biao/aggbug/191180.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-09-19 00:10 <a href="http://www.cppblog.com/biao/archive/2012/09/19/191180.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：Maven打包可运行的JAR  </title><link>http://www.cppblog.com/biao/archive/2012/09/18/191172.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Tue, 18 Sep 2012 15:31:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/09/18/191172.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/191172.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/09/18/191172.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/191172.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/191172.html</trackback:ping><description><![CDATA[<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<span  style="border-collapse: separate; font-family: Arial; line-height: normal; border-spacing: 0px; font-size: medium; ">
<div style="color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 12px; text-align: left; background-color: #ccced0; ">
<h3 style="overflow: hidden; word-wrap: break-word; word-break: break-all; font-size: 14px; margin: 30px 0px 20px; padding: 0px; line-height: 24px; "><span style="font-size: 20px; font-family: 微软雅黑, 黑体, Arial, Helvetica, sans-serif; ">maven打包可运行的JAR</span>&nbsp;&nbsp;</h3>
<p style="zoom: 1; margin: 0px 0px 20px; padding: 0px; color: #bbbbbb; line-height: 20px; "><span  style="color: #333333; font-size: 14px; line-height: 25px; ">现在写后端非WEB程序比较多,每次需要手工的拷贝lib里面的jar 包,然后启动脚本里面还要写classpath,特么完全是在坑爹,为了偷懒,我找了一下maven中的配置,发现可以配置可运行包,并且直接拷贝依赖JAR到lib下,还把classpath放在打包好的程序描述文件中,简直是神器,这里留下一笔,免得以后一段时间不写代码了把这个给忘记了,呵呵.</span><br />
</p>
</div>
<div style="color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 12px; text-align: left; background-color: #ccced0; ">
<div style="line-height: 25px; font-size: 14px; word-wrap: break-word; margin: 15px 0px; padding-top: 5px; padding-bottom: 5px; overflow: hidden; ">
<pre style="padding: 2px; border: 1px solid #888888; "><br />
<span style="color: #000088; ">&lt;build&gt;</span><br />
<span style="color: #000000; ">&nbsp; </span><span style="color: #000088; ">&lt;plugins&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;plugin&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;groupId&gt;</span><span style="color: #000000; ">org.apache.maven.plugins</span><span style="color: #000088; ">&lt;/groupId&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;artifactId&gt;</span><span style="color: #000000; ">maven-jar-plugin</span><span style="color: #000088; ">&lt;/artifactId&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;configuration&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;archive&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;manifest&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;addClasspath&gt;</span><span style="color: #000000; ">true</span><span style="color: #000088; ">&lt;/addClasspath&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;classpathPrefix&gt;</span><span style="color: #000000; ">lib/</span><span style="color: #000088; ">&lt;/classpathPrefix&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;mainClass&gt;</span><span style="color: #000000; ">com.coffee.bee.Main</span><span style="color: #000088; ">&lt;/mainClass&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;/manifest&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;/archive&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;/configuration&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;/plugin&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;plugin&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;groupId&gt;</span><span style="color: #000000; ">org.apache.maven.plugins</span><span style="color: #000088; ">&lt;/groupId&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;artifactId&gt;</span><span style="color: #000000; ">maven-dependency-plugin</span><span style="color: #000088; ">&lt;/artifactId&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;executions&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;execution&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;id&gt;</span><span style="color: #000000; ">copy</span><span style="color: #000088; ">&lt;/id&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;phase&gt;</span><span style="color: #000000; ">package</span><span style="color: #000088; ">&lt;/phase&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;goals&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;goal&gt;</span><span style="color: #000000; ">copy-dependencies</span><span style="color: #000088; ">&lt;/goal&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;/goals&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;configuration&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;outputDirectory&gt;</span><span style="color: #000000; ">${project.build.directory}/lib</span><span style="color: #000088; ">&lt;/outputDirectory&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;/configuration&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;/execution&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;/executions&gt;</span><br />
<span style="color: #000000; ">&nbsp;&nbsp; </span><span style="color: #000088; ">&lt;/plugin&gt;</span><br />
<span style="color: #000000; ">&nbsp; </span><span style="color: #000088; ">&lt;/plugins&gt;</span><br />
<span style="color: #000000; "></span><span style="color: #000088; ">&lt;/build&gt;</span></pre>
<pre style="padding: 2px; border: 1px solid #888888; "><span style="color: #000088; ">From: </span><span style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; ">http://blog.163.com/coffee_hc/blog/static/4485331920121274422988/</span></pre>
</div>
</div>
</span>
@import url(http://www.cppblog.com/cutesoft_client/cuteeditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/biao/aggbug/191172.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-09-18 23:31 <a href="http://www.cppblog.com/biao/archive/2012/09/18/191172.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：Ant打包jar文件（有lib目录）</title><link>http://www.cppblog.com/biao/archive/2012/09/17/190920.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sun, 16 Sep 2012 17:25:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/09/17/190920.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/190920.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/09/17/190920.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/190920.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/190920.html</trackback:ping><description><![CDATA[@import url(http://www.cppblog.com/cutesoft_client/cuteeditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<div style="font-size: 14px; font-family: Arial; line-height: normal; "><font face="Menlo"><span style="font-size: 12px; ">使用Ant打包Jar文件</span></font></div>
<div style="font-family: Arial; line-height: normal; font-size: medium; "><font face="Menlo" size="2">主要是lib/*.jar的路径需要注意:&nbsp;</font><span style="font-family: Menlo; font-size: small; ">jar包里的jar包是不能被识别为classpath</span></div>
<div style="font-family: Arial; line-height: normal; font-size: medium; "><font face="Menlo" size="2"><br />
</font></div>
<div style="font-family: Arial; line-height: normal; font-size: medium; "><font face="Menlo" size="2">使用方法：如果代码是如下面的目录结构组织的，不需要修改什么，直接在终端运行ant命令即可在out目录输出对应的jar文件。</font></div>
<div style="font-family: Arial; line-height: normal; font-size: medium; "><font face="Menlo" size="2">
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; "><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000FF; ">&lt;?</span><span style="color: #FF00FF; ">xml&nbsp;version="1.0"&nbsp;</span><span style="color: #0000FF; ">?&gt;</span><span style="color: #000000; "><br />
</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">project&nbsp;</span><span style="color: #FF0000; ">default</span><span style="color: #0000FF; ">="jar"</span><span style="color: #FF0000; ">&nbsp;name</span><span style="color: #0000FF; ">="Acid"</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">&lt;!--</span><span style="color: #008000; ">&nbsp;工程目录结构<br />
&nbsp;&nbsp;&nbsp;&nbsp;project<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|-bin<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|-src<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|-lib<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|-out<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|-build.xml<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">--&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">property&nbsp;</span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="lib.dir"</span><span style="color: #FF0000; ">&nbsp;value</span><span style="color: #0000FF; ">="lib"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">property&nbsp;</span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="src.dir"</span><span style="color: #FF0000; ">&nbsp;value</span><span style="color: #0000FF; ">="src"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">property&nbsp;</span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="classes.dir"</span><span style="color: #FF0000; ">&nbsp;value</span><span style="color: #0000FF; ">="bin"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">property&nbsp;</span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="output.dir"</span><span style="color: #FF0000; ">&nbsp;value</span><span style="color: #0000FF; ">="out"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">property&nbsp;</span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="jarname"</span><span style="color: #FF0000; ">&nbsp;value</span><span style="color: #0000FF; ">="Test.jar"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">property&nbsp;</span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="mainclass"</span><span style="color: #FF0000; ">&nbsp;value</span><span style="color: #0000FF; ">="com.biao.Test"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">&lt;!--</span><span style="color: #008000; ">&nbsp;第三方jar包的路径&nbsp;</span><span style="color: #008000; ">--&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">path&nbsp;</span><span style="color: #FF0000; ">id</span><span style="color: #0000FF; ">="lib-classpath"</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">fileset&nbsp;</span><span style="color: #FF0000; ">dir</span><span style="color: #0000FF; ">="${lib.dir}"</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">include&nbsp;</span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="**/*.jar"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">fileset</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">path</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">&lt;!--</span><span style="color: #008000; ">&nbsp;1.&nbsp;初始化工作，如创建目录等&nbsp;</span><span style="color: #008000; ">--&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">target&nbsp;</span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="init"</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">mkdir&nbsp;</span><span style="color: #FF0000; ">dir</span><span style="color: #0000FF; ">="${classes.dir}"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">mkdir&nbsp;</span><span style="color: #FF0000; ">dir</span><span style="color: #0000FF; ">="${output.dir}"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">target</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">&lt;!--</span><span style="color: #008000; ">&nbsp;2.&nbsp;编译&nbsp;</span><span style="color: #008000; ">--&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">target&nbsp;</span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="compile"</span><span style="color: #FF0000; ">&nbsp;depends</span><span style="color: #0000FF; ">="init"</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">javac&nbsp;</span><span style="color: #FF0000; ">srcdir</span><span style="color: #0000FF; ">="${src.dir}"</span><span style="color: #FF0000; ">&nbsp;destdir</span><span style="color: #0000FF; ">="${classes.dir}"</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">compilerarg&nbsp;</span><span style="color: #FF0000; ">line</span><span style="color: #0000FF; ">="-encoding&nbsp;UTF-8"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">classpath&nbsp;</span><span style="color: #FF0000; ">refid</span><span style="color: #0000FF; ">="lib-classpath"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">javac</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">target</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">&lt;!--</span><span style="color: #008000; ">&nbsp;3.&nbsp;打包jar文件&nbsp;</span><span style="color: #008000; ">--&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">target&nbsp;</span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="jar"</span><span style="color: #FF0000; ">&nbsp;depends</span><span style="color: #0000FF; ">="compile"</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">copy&nbsp;</span><span style="color: #FF0000; ">todir</span><span style="color: #0000FF; ">="${output.dir}/lib"</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">fileset&nbsp;</span><span style="color: #FF0000; ">dir</span><span style="color: #0000FF; ">="${lib.dir}"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">copy</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">&lt;!--</span><span style="color: #008000; ">Create&nbsp;a&nbsp;property&nbsp;containing&nbsp;all&nbsp;.jar&nbsp;files,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prefix&nbsp;lib/,&nbsp;and&nbsp;seperated&nbsp;with&nbsp;a&nbsp;space</span><span style="color: #008000; ">--&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">pathconvert&nbsp;</span><span style="color: #FF0000; ">property</span><span style="color: #0000FF; ">="mf.classpath"</span><span style="color: #FF0000; ">&nbsp;pathsep</span><span style="color: #0000FF; ">="&nbsp;"</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">mapper</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">chainedmapper</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">&lt;!--</span><span style="color: #008000; ">&nbsp;jar包文件只留文件名，去掉目录信息&nbsp;</span><span style="color: #008000; ">--&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">flattenmapper</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">&lt;!--</span><span style="color: #008000; ">&nbsp;add&nbsp;lib/&nbsp;prefix&nbsp;</span><span style="color: #008000; ">--&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">globmapper&nbsp;</span><span style="color: #FF0000; ">from</span><span style="color: #0000FF; ">="*"</span><span style="color: #FF0000; ">&nbsp;to</span><span style="color: #0000FF; ">="lib/*"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">chainedmapper</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">mapper</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">path&nbsp;</span><span style="color: #FF0000; ">refid</span><span style="color: #0000FF; ">="lib-classpath"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">pathconvert</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">&lt;!--</span><span style="color: #008000; ">&nbsp;jar文件的输出路径&nbsp;</span><span style="color: #008000; ">--&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">jar&nbsp;</span><span style="color: #FF0000; ">destfile</span><span style="color: #0000FF; ">="${output.dir}/${jarname}"</span><span style="color: #FF0000; ">&nbsp;basedir</span><span style="color: #0000FF; ">="${classes.dir}"</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">manifest</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">attribute&nbsp;</span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="Main-class"</span><span style="color: #FF0000; ">&nbsp;value</span><span style="color: #0000FF; ">="${mainclass}"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">attribute&nbsp;</span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="Class-Path"</span><span style="color: #FF0000; ">&nbsp;value</span><span style="color: #0000FF; ">="${mf.classpath}"</span><span style="color: #0000FF; ">/&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">manifest</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">jar</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">target</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">project</span><span style="color: #0000FF; ">&gt;</span><span style="color: #000000; "><br />
</span></div>
</font></div><img src ="http://www.cppblog.com/biao/aggbug/190920.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-09-17 01:25 <a href="http://www.cppblog.com/biao/archive/2012/09/17/190920.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java：nio的例子，没心情看，先放着</title><link>http://www.cppblog.com/biao/archive/2012/07/22/184563.html</link><dc:creator>逛奔的蜗牛</dc:creator><author>逛奔的蜗牛</author><pubDate>Sat, 21 Jul 2012 23:00:00 GMT</pubDate><guid>http://www.cppblog.com/biao/archive/2012/07/22/184563.html</guid><wfw:comment>http://www.cppblog.com/biao/comments/184563.html</wfw:comment><comments>http://www.cppblog.com/biao/archive/2012/07/22/184563.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/biao/comments/commentRss/184563.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/biao/services/trackbacks/184563.html</trackback:ping><description><![CDATA[<span  style="font-family: monospace; font-size: 12px; line-height: 23px; white-space: pre; "><span style="line-height: 18px; color: #0000ff; ">import</span><span style="line-height: 18px; color: #000000; "> java.io.ByteArrayOutputStream;
</span><span style="line-height: 18px; color: #0000ff; ">import</span><span style="line-height: 18px; color: #000000; "> java.io.IOException;
</span><span style="line-height: 18px; color: #0000ff; ">import</span><span style="line-height: 18px; color: #000000; "> java.net.InetSocketAddress;
</span><span style="line-height: 18px; color: #0000ff; ">import</span><span style="line-height: 18px; color: #000000; "> java.net.ServerSocket;
</span><span style="line-height: 18px; color: #0000ff; ">import</span><span style="line-height: 18px; color: #000000; "> java.nio.ByteBuffer;
</span><span style="line-height: 18px; color: #0000ff; ">import</span><span style="line-height: 18px; color: #000000; "> java.nio.channels.SelectionKey;
</span><span style="line-height: 18px; color: #0000ff; ">import</span><span style="line-height: 18px; color: #000000; "> java.nio.channels.Selector;
</span><span style="line-height: 18px; color: #0000ff; ">import</span><span style="line-height: 18px; color: #000000; "> java.nio.channels.ServerSocketChannel;
</span><span style="line-height: 18px; color: #0000ff; ">import</span><span style="line-height: 18px; color: #000000; "> java.nio.channels.SocketChannel;
</span><span style="line-height: 18px; color: #0000ff; ">import</span><span style="line-height: 18px; color: #000000; "> java.text.DateFormat;
</span><span style="line-height: 18px; color: #0000ff; ">import</span><span style="line-height: 18px; color: #000000; "> java.text.SimpleDateFormat;
</span><span style="line-height: 18px; color: #0000ff; ">import</span><span style="line-height: 18px; color: #000000; "> java.util.Date;
</span><span style="line-height: 18px; color: #0000ff; ">public</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">class</span><span style="line-height: 18px; color: #000000; "> EchoServer {
</span><span style="line-height: 18px; color: #0000ff; ">private</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">static</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">int</span><span style="line-height: 18px; color: #000000; "> SOCKET_NUM </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">55555</span><span style="line-height: 18px; color: #000000; ">;
</span><span style="line-height: 18px; color: #0000ff; ">private</span><span style="line-height: 18px; color: #000000; "> DateFormat dateFormatter </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">new</span><span style="line-height: 18px; color: #000000; "> SimpleDateFormat(</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; ">yyyyMMdd HH:mm:ss</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; ">);
</span><span style="line-height: 18px; color: #008000; ">/**</span><span style="line-height: 18px; color: #008000; ">
* </span><span style="line-height: 18px; color: #808080; ">@param</span><span style="line-height: 18px; color: #008000; "> args
</span><span style="line-height: 18px; color: #008000; ">*/</span><span style="line-height: 18px; color: #000000; ">
</span><span style="line-height: 18px; color: #0000ff; ">public</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">static</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">void</span><span style="line-height: 18px; color: #000000; "> main(String[] args) {
</span><span style="line-height: 18px; color: #0000ff; ">new</span><span style="line-height: 18px; color: #000000; "> EchoServer().start();
}
</span><span style="line-height: 18px; color: #0000ff; ">public</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">void</span><span style="line-height: 18px; color: #000000; "> start() {
</span><span style="line-height: 18px; color: #0000ff; ">try</span><span style="line-height: 18px; color: #000000; "> {
Selector selector </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> bindServer();  </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 绑定服务端口，并定义一个事件选择器对象记录套接字通道的事件</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
</span><span style="line-height: 18px; color: #008000; ">/*</span><span style="line-height: 18px; color: #008000; "> 通过此循环来遍例事件 </span><span style="line-height: 18px; color: #008000; ">*/</span><span style="line-height: 18px; color: #000000; ">
</span><span style="line-height: 18px; color: #0000ff; ">while</span><span style="line-height: 18px; color: #000000; "> (</span><span style="line-height: 18px; color: #0000ff; ">true</span><span style="line-height: 18px; color: #000000; ">) {
log(</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; ">Waiting events.</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; ">);
</span><span style="line-height: 18px; color: #0000ff; ">int</span><span style="line-height: 18px; color: #000000; "> n </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> selector.select(); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 查询事件如果一个事件都没有，这里就会阻塞</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">                log(</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; ">Got events: </span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">+</span><span style="line-height: 18px; color: #000000; "> n);
ByteBuffer echoBuffer </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> ByteBuffer.allocate(</span><span style="line-height: 18px; color: #000000; ">50</span><span style="line-height: 18px; color: #000000; ">); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 定义一个byte缓冲区来存储收发的数据</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
</span><span style="line-height: 18px; color: #008000; ">/*</span><span style="line-height: 18px; color: #008000; "> 循环遍例所有产生的事件 </span><span style="line-height: 18px; color: #008000; ">*/</span><span style="line-height: 18px; color: #000000; ">
</span><span style="line-height: 18px; color: #0000ff; ">for</span><span style="line-height: 18px; color: #000000; "> (SelectionKey key : selector.selectedKeys()) {
SocketChannel sc;
selector.selectedKeys().remove(key);  </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 将本此事件从迭带器中删除</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
</span><span style="line-height: 18px; color: #008000; ">/*</span><span style="line-height: 18px; color: #008000; "> 如果产生的事件为接受客户端连接(当有客户端连接服务器的时候产生) </span><span style="line-height: 18px; color: #008000; ">*/</span><span style="line-height: 18px; color: #000000; ">
</span><span style="line-height: 18px; color: #0000ff; ">if</span><span style="line-height: 18px; color: #000000; "> ((key.readyOps() </span><span style="line-height: 18px; color: #000000; ">&amp;</span><span style="line-height: 18px; color: #000000; "> SelectionKey.OP_ACCEPT) </span><span style="line-height: 18px; color: #000000; ">==</span><span style="line-height: 18px; color: #000000; "> SelectionKey.OP_ACCEPT) {
ServerSocketChannel subssc </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> (ServerSocketChannel) key.channel(); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 定义一个服务器socket通道</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
sc </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> subssc.accept(); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 将临时socket对象实例化为接收到的客户端的socket</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
sc.configureBlocking(</span><span style="line-height: 18px; color: #0000ff; ">false</span><span style="line-height: 18px; color: #000000; ">); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 将客户端的socket设置为异步</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
sc.register(selector, SelectionKey.OP_READ); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 将客户端的socket的读取事件注册到事件选择器中</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
System.out.println(</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; ">Got new client:</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">+</span><span style="line-height: 18px; color: #000000; "> sc);
}
</span><span style="line-height: 18px; color: #008000; ">/*</span><span style="line-height: 18px; color: #008000; "> 如果产生的事件为读取数据(当已连接的客户端向服务器发送数据的时候产生) </span><span style="line-height: 18px; color: #008000; ">*/</span><span style="line-height: 18px; color: #000000; ">
</span><span style="line-height: 18px; color: #0000ff; ">else</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">if</span><span style="line-height: 18px; color: #000000; "> ((key.readyOps() </span><span style="line-height: 18px; color: #000000; ">&amp;</span><span style="line-height: 18px; color: #000000; "> SelectionKey.OP_READ) </span><span style="line-height: 18px; color: #000000; ">==</span><span style="line-height: 18px; color: #000000; "> SelectionKey.OP_READ) {
sc </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> (SocketChannel) key.channel(); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 临时socket对象实例化为产生本事件的socket</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
ByteArrayOutputStream bos </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">new</span><span style="line-height: 18px; color: #000000; "> ByteArrayOutputStream(); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 定义一个用于存储byte数据的流对象，存储全部信息</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
echoBuffer.clear(); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 先将客户端的数据清空</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
</span><span style="line-height: 18px; color: #0000ff; ">try</span><span style="line-height: 18px; color: #000000; "> {
</span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 循环读取所有客户端数据到byte缓冲区中,当有数据的时候read函数返回数据长度
</span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> NIO会自动的将缓冲区一次容纳不下的自动分段</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">                            </span><span style="line-height: 18px; color: #0000ff; ">int</span><span style="line-height: 18px; color: #000000; "> readInt </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">0</span><span style="line-height: 18px; color: #000000; ">; </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 为读取到数据的长度</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">                            </span><span style="line-height: 18px; color: #0000ff; ">while</span><span style="line-height: 18px; color: #000000; "> ((readInt </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> sc.read(echoBuffer)) </span><span style="line-height: 18px; color: #000000; ">&gt;</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">0</span><span style="line-height: 18px; color: #000000; ">) {
</span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 如果获得数据长度比缓冲区大小小的话</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">                                </span><span style="line-height: 18px; color: #0000ff; ">if</span><span style="line-height: 18px; color: #000000; "> (readInt </span><span style="line-height: 18px; color: #000000; ">&lt;</span><span style="line-height: 18px; color: #000000; "> echoBuffer.capacity()) {
</span><span style="line-height: 18px; color: #0000ff; ">byte</span><span style="line-height: 18px; color: #000000; ">[] readByte </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">new</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">byte</span><span style="line-height: 18px; color: #000000; ">[readInt]; </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 建立一个临时byte数组,将齐长度设为获取的数据的长度
</span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 循环向此临时数组中添加数据</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">                                    </span><span style="line-height: 18px; color: #0000ff; ">for</span><span style="line-height: 18px; color: #000000; "> (</span><span style="line-height: 18px; color: #0000ff; ">int</span><span style="line-height: 18px; color: #000000; "> i </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">0</span><span style="line-height: 18px; color: #000000; ">; i </span><span style="line-height: 18px; color: #000000; ">&lt;</span><span style="line-height: 18px; color: #000000; "> readInt; i</span><span style="line-height: 18px; color: #000000; ">++</span><span style="line-height: 18px; color: #000000; ">) {
readByte[i] </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> echoBuffer.get(i);
}
bos.write(readByte); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 将此数据存入byte流中</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">                                }
</span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 否则就是获得数据长度等于缓冲区大小</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">                                </span><span style="line-height: 18px; color: #0000ff; ">else</span><span style="line-height: 18px; color: #000000; "> {
bos.write(echoBuffer.array()); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 将读取到的数据写入到byte流对象中</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">                                }
}
</span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 当循环结束时byte流中已经存储了客户端发送的所有byte数据</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">                            log(</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; ">Recive msg: </span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">+</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">new</span><span style="line-height: 18px; color: #000000; "> String(bos.toByteArray()));
} </span><span style="line-height: 18px; color: #0000ff; ">catch</span><span style="line-height: 18px; color: #000000; "> (Exception e) {
e.printStackTrace(); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 当客户端在读取数据操作执行之前断开连接会产生异常信息</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
key.cancel(); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 将本socket的事件在选择器中删除</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">                            </span><span style="line-height: 18px; color: #0000ff; ">break</span><span style="line-height: 18px; color: #000000; ">;
}
writeBack(sc, bos.toByteArray()); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 向客户端写入收到的数据</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">                    }
}
}
} </span><span style="line-height: 18px; color: #0000ff; ">catch</span><span style="line-height: 18px; color: #000000; "> (Exception e) {
e.printStackTrace();
}
}
</span><span style="line-height: 18px; color: #008000; ">/**</span><span style="line-height: 18px; color: #008000; ">
* 绑定服务端口，初始化整个服务
* </span><span style="line-height: 18px; color: #808080; ">@throws</span><span style="line-height: 18px; color: #008000; "> IOException
</span><span style="line-height: 18px; color: #008000; ">*/</span><span style="line-height: 18px; color: #000000; ">
</span><span style="line-height: 18px; color: #0000ff; ">private</span><span style="line-height: 18px; color: #000000; "> Selector bindServer() </span><span style="line-height: 18px; color: #0000ff; ">throws</span><span style="line-height: 18px; color: #000000; "> IOException {
log(</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; ">Start binding server socket：</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">+</span><span style="line-height: 18px; color: #000000; "> SOCKET_NUM);
Selector selector </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> Selector.open(); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 定义一个事件选择器对象记录套接字通道的事件</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
ServerSocketChannel ssc </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> ServerSocketChannel.open(); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 定义一个异步服务器socket对象</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
ssc.configureBlocking(</span><span style="line-height: 18px; color: #0000ff; ">false</span><span style="line-height: 18px; color: #000000; ">);</span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 将此socket对象设置为异步</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
ServerSocket ss </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> ssc.socket(); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 定义服务器socket对象-用来指定异步socket的监听端口等信息</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
InetSocketAddress address </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">new</span><span style="line-height: 18px; color: #000000; "> InetSocketAddress(SOCKET_NUM); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 定义存放监听端口的对象</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
ss.bind(address); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 将服务器与这个端口绑定</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
ssc.register(selector, SelectionKey.OP_ACCEPT); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 将异步的服务器socket对象的接受客户端连接事件注册到selector对象内</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
log(</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; ">Binded socket at：</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">+</span><span style="line-height: 18px; color: #000000; "> SOCKET_NUM);
</span><span style="line-height: 18px; color: #0000ff; ">return</span><span style="line-height: 18px; color: #000000; "> selector;
}
</span><span style="line-height: 18px; color: #0000ff; ">private</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">boolean</span><span style="line-height: 18px; color: #000000; "> writeBack(SocketChannel sc, </span><span style="line-height: 18px; color: #0000ff; ">byte</span><span style="line-height: 18px; color: #000000; ">[] b) {
ByteBuffer echoBuffer </span><span style="line-height: 18px; color: #000000; ">=</span><span style="line-height: 18px; color: #000000; "> ByteBuffer.allocate(b.length); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 建立这个byte对象的ByteBuffer</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">        echoBuffer.put(b); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 将数据存入 </span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">
echoBuffer.flip(); </span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 将缓冲区复位以便于进行其他读写操作</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">        </span><span style="line-height: 18px; color: #0000ff; ">try</span><span style="line-height: 18px; color: #000000; "> {
</span><span style="line-height: 18px; color: #008000; ">//</span><span style="line-height: 18px; color: #008000; "> 向客户端写入数据,数据为接受到数据</span><span style="line-height: 18px; color: #008000; ">
</span><span style="line-height: 18px; color: #000000; ">            sc.write(echoBuffer);
} </span><span style="line-height: 18px; color: #0000ff; ">catch</span><span style="line-height: 18px; color: #000000; "> (IOException e) {
e.printStackTrace();
</span><span style="line-height: 18px; color: #0000ff; ">return</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">false</span><span style="line-height: 18px; color: #000000; ">;
}
System.out.println(</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; ">Msg echo back: </span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">+</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">new</span><span style="line-height: 18px; color: #000000; "> String(echoBuffer.array()));
</span><span style="line-height: 18px; color: #0000ff; ">return</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">true</span><span style="line-height: 18px; color: #000000; ">;
}
</span><span style="line-height: 18px; color: #0000ff; ">private</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #0000ff; ">void</span><span style="line-height: 18px; color: #000000; "> log(Object msg) {
System.out.println(</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; ">SERVER [</span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">+</span><span style="line-height: 18px; color: #000000; "> dateFormatter.format(</span><span style="line-height: 18px; color: #0000ff; ">new</span><span style="line-height: 18px; color: #000000; "> Date()) </span><span style="line-height: 18px; color: #000000; ">+</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; ">]: </span><span style="line-height: 18px; color: #000000; ">"</span><span style="line-height: 18px; color: #000000; "> </span><span style="line-height: 18px; color: #000000; ">+</span><span style="line-height: 18px; color: #000000; "> msg);
}
}</span></span>
@import url(http://www.cppblog.com/cutesoft_client/cuteeditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<div><span  style="font-family: monospace; font-size: 12px; line-height: 23px; white-space: pre; "><span style="line-height: 18px; color: #000000; "><br />
</span></span></div>
<div><span  style="font-family: monospace; font-size: 12px; line-height: 23px; white-space: pre; "><span style="line-height: 18px; color: #000000; ">From: http://topic.csdn.net/u/20120719/16/a5d0c2ca-d669-4902-9f3e-d4b8f4ad90b3.html?32104</span></span></div><img src ="http://www.cppblog.com/biao/aggbug/184563.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/biao/" target="_blank">逛奔的蜗牛</a> 2012-07-22 07:00 <a href="http://www.cppblog.com/biao/archive/2012/07/22/184563.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>