??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲天堂免费视频,国产精品一区二区在线观看 ,日韩美女免费视频http://www.aygfsteel.com/sinpo/x(chng)开源,参与开源!zh-cnTue, 17 Jun 2025 10:27:38 GMTTue, 17 Jun 2025 10:27:38 GMT60软g开发,我们q需要什?/title><link>http://www.aygfsteel.com/sinpo/archive/2008/11/17/241049.html</link><dc:creator>徐辛?/dc:creator><author>徐辛?/author><pubDate>Mon, 17 Nov 2008 15:09:00 GMT</pubDate><guid>http://www.aygfsteel.com/sinpo/archive/2008/11/17/241049.html</guid><wfw:comment>http://www.aygfsteel.com/sinpo/comments/241049.html</wfw:comment><comments>http://www.aygfsteel.com/sinpo/archive/2008/11/17/241049.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sinpo/comments/commentRss/241049.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sinpo/services/trackbacks/241049.html</trackback:ping><description><![CDATA[<p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style=" font-size:10.5000pt; font-family:'?hu)?; "><font face="?hu)?>不止一ơ我们的目在靠开发h员硬扛着Qbug来不?qing)修改,文档q在猛补Q项目经理又在催着出版本,每修改一个bug都要在代码的泥沼中摸爬滚打半天,却又在制造着另外的bugQؓ(f)?jin)文档而制造着Ҏ(gu)没有参考h(hun)值的文档。每发布一个版本都要瞻前顾后ƈ且总要无休止的加班Q似乎开发h员永q有q不完的zR?/font></span></p> <p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style=" font-size:10.5000pt; font-family:'?hu)?; "><font face="?hu)?>我们不禁问自己,Z么会(x)有那么多p|的YӞ软g开发我们到底还需要什么? </font></span></p> <p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style=" font-size:10.5000pt; font-family:'?hu)?; "><font face="?hu)?>工具Q我们不乏伟大的工具QIDE我们有eclipse、intelliJ、VC++{等Q徏模我们有Rose、together、Visio{等Q配|管理我们Subversion、CVS、ClearCase{等Qbug理我们有ClearQuest、bugzilla{等Q文档我们word、wps{,q有集成、测试甚至生成代码等{我们都有伟大的工具Q工h们不~。流E?瀑布模型、P代模型、UP、XP我们不缺程理的理论。知识?软g开发算是一知识型的工作,我们的开发h员(sh)般都是本U硕士毕业,况且搜烦(ch)引擎如此发达的今天,知识Ҏ(gu)不是问题Q况且我们的软g开发需要多么高q知识?</font></span></p> <p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style=" font-size:10.5000pt; font-family:'?hu)?; "> <font face="?hu)?>优秀的理论支持、有能力的h员、先q的工具Q这些我们都具备Q我们所~的只是一UY件开发的理念Q缺Y件开发的情商。我们一开始学?fn)编E知识接触到的就是C语言和数据结构,慢慢的一些结构化的思想扎根于大脑Q其实在商业软g中数据结构、算法很涉?qing),我们所需要的仅仅是一U设计、开发的理念。比如用面向对象本来是一U简单的思想Q目的是Z(jin)降低软g的复杂性而出现的Q可是让熟?zhn)了(jin)结构化~程的hL反而觉得很难。一些好的实늻验我们也l常提到Q比如模块化、松散耦合、面向接口编E、类应只x(chng)本职工作{等开发设计理念以?qing)规范命名、详用的注释、清晰的l构{代码规范以?qing)每日构建、有效沟通、配|管理、bug理{一些管理理念,q些做v来都非常Ҏ(gu)Q关键是懒惰是h的本性,不知不觉中我们就?x)犯着大家都在重复的错误。如果在目开工之初就充分贯彻q些优秀的理念,在项目进行中无论旉多紧都持之以恒,q且目q行中不断的反思代码中的坏味道Q一l发现立即重构,怿我们的开发过E会(x)q入一个良性的循环中去Q我们的开发h员将?x)体会(x)到什么是快乐开发?/font></span></p> <img src ="http://www.aygfsteel.com/sinpo/aggbug/241049.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sinpo/" target="_blank">徐辛?/a> 2008-11-17 23:09 <a href="http://www.aygfsteel.com/sinpo/archive/2008/11/17/241049.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>诚心(j)l识有志于研I、开发开源Y件的志同道合之士l徏开源团?/title><link>http://www.aygfsteel.com/sinpo/archive/2008/10/31/237895.html</link><dc:creator>徐辛?/dc:creator><author>徐辛?/author><pubDate>Fri, 31 Oct 2008 13:00:00 GMT</pubDate><guid>http://www.aygfsteel.com/sinpo/archive/2008/10/31/237895.html</guid><wfw:comment>http://www.aygfsteel.com/sinpo/comments/237895.html</wfw:comment><comments>http://www.aygfsteel.com/sinpo/archive/2008/10/31/237895.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sinpo/comments/commentRss/237895.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sinpo/services/trackbacks/237895.html</trackback:ping><description><![CDATA[徐辛波,西安Q从事Y件开发设计工作,熟?zhn)Java语言Q爱好开发工作,特别是java相关的编E,业余x(chng)开源项目,诚心(j)l识志同道合之士l徏开源团队,共同学习(fn)、进步、协作、ؓ(f)中国开源事业A(ch)献微薄之力? <div>徐辛?sinpo.xu@gmail.com</div> <img src ="http://www.aygfsteel.com/sinpo/aggbug/237895.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sinpo/" target="_blank">徐辛?/a> 2008-10-31 21:00 <a href="http://www.aygfsteel.com/sinpo/archive/2008/10/31/237895.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JDOM常用cMl及(qing)CZ代码http://www.aygfsteel.com/sinpo/archive/2008/10/25/236589.html徐辛?/dc:creator>徐辛?/author>Sat, 25 Oct 2008 13:02:00 GMThttp://www.aygfsteel.com/sinpo/archive/2008/10/25/236589.htmlhttp://www.aygfsteel.com/sinpo/comments/236589.htmlhttp://www.aygfsteel.com/sinpo/archive/2008/10/25/236589.html#Feedback0http://www.aygfsteel.com/sinpo/comments/commentRss/236589.htmlhttp://www.aygfsteel.com/sinpo/services/trackbacks/236589.html

JDOM

Document<?xml version="1.0" encoding="UTF-8"?>

<customers>

<customer>

<name><occupation>developer</occupation>

<!-- comment:following is contact info -->

<contact>

<email>sinpo.xu@hotmail.com</email>

<mobile>15029357227</mobile>

<fix-phone>02985457683</fix-phone>

</contact>

</customer>

</customers>

<mobile>15029357227</mobile>Element element = new Element("name");

Text text = new Text("AAA.<

element.addContent(text);

org.w3c.dom.Document

          package sinpo.usagedemo;

          import java.io.File;
          import java.io.FileOutputStream;
          import java.io.IOException;
          import java.io.InputStream;
          import java.io.OutputStream;
          import java.net.URL;
          import java.util.List;

          import org.jdom.Document;
          import org.jdom.Element;
          import org.jdom.input.SAXBuilder;
          import org.jdom.output.Format;
          import org.jdom.output.XMLOutputter;

          /**
           * d配置文gQƈ且修改后?qing)时同步到磁?/font>
           @author 徐辛?sinpo.xu@hotmail.com) 
           * Oct 23, 2008
           */
          public class Configuration {

              private Element root = null;

              private Document dom = null;

              private static final String resourceName = "/config.xml";

              private static Configuration _INSTANCE = null;

              public static synchronized Configuration getInstance() {
                  if (_INSTANCE == null) {
                      _INSTANCE = new Configuration();
                  }

                  return _INSTANCE;
              }

              private Configuration() {
                  load();
              }

              public String getConfig(String configName) {
                  String configValue = null;
                  Element found = findRecursively(configName, root);
                  if (found != null) {
                      configValue = found.getText();
                  }
                  return configValue;
              }

              public void updateConfig(String configName, String newValue)
                      throws IOException {
                  Element found = findRecursively(configName, root);
                  if (found != null) {
                      found.setText(newValue);
                  else {
                      Element configNode = new Element(configName);
                      configNode.addContent(newValue);
                      // also: configNode.setText(newValue);
                      root.addContent(configNode);
                  }
                  sync();
              }

              public void deleteConfig(String configNamethrows IOException {
                  Element found = findRecursively(configName, root);
                  if (found != null) {
                      found.detach();
                  }
                  sync();
              }
              
              private void load() {
                  SAXBuilder builder = new SAXBuilder();
                  InputStream source = getClass().getResourceAsStream(resourceName);
                  try {
                      dom = builder.build(source);
                      root = dom.getRootElement();
                  catch (Exception e) {
                      e.printStackTrace();
                  }
              }

              // 递归查找. 在指定的父节点下查找叶子元素
              private Element findRecursively(String name, Element parent) {
                  Element found = null;
                  List<Element> children = parent.getChildren();
                  if (children != null) {
                      for (int i = 0; i < children.size(); i++) {
                          Element element = children.get(i);
                          String tmpName = element.getName();
                          if ((name.equals(tmpName)) && (!hasChild(element))) {
                              return element;
                          }
                      }

                      for (int i = 0; i < children.size(); i++) {
                          Element element = children.get(i);
                          if (hasChild(element)) {
                              found = findRecursively(name, element);
                              if (found != null) {
                                  return found;
                              }
                          }
                      }
                  }

                  return found;
              }

              private boolean hasChild(Element element) {
                  boolean hasChild = false;
                  List children = element.getChildren();
                  if ((children != null&& (children.size() 0)) {
                      hasChild = true;
                  }

                  return hasChild;
              }

              private void sync() throws IOException {
                  Format format = Format.getPrettyFormat();
                  XMLOutputter outputter = new XMLOutputter(format);
                  File file = null;
                  URL url = getClass().getResource(resourceName);
                  if (url == null) {
                      file = new File(resourceName);
                  else {
                      file = new File(url.getPath());

                      OutputStream out = null;
                      try {
                          out = new FileOutputStream(file);
                          outputter.output(dom, out);
                          out.close();
                          out = null;
                      catch (Exception e) {
                          e.printStackTrace();
                          if (out != null) {
                              out.close();
                          }
                      }
                  }
              }
          }
          վ֩ģ壺 | | | | ɽʡ| Ͽ| | °Ͷ| ٰ| ʡ| | | | | Ϫ| Ͻ| | ˿| | ΢| Ӣɳ| | ζ| | ƺ| | | ɽ| Ϫ| | ̷| | Ϸ| | | | | | | | |

          ]]>
          也谈U程的休眠与{待http://www.aygfsteel.com/sinpo/archive/2008/10/22/236061.html徐辛?/dc:creator>徐辛?/author>Wed, 22 Oct 2008 15:26:00 GMThttp://www.aygfsteel.com/sinpo/archive/2008/10/22/236061.htmlhttp://www.aygfsteel.com/sinpo/comments/236061.htmlhttp://www.aygfsteel.com/sinpo/archive/2008/10/22/236061.html#Feedback0http://www.aygfsteel.com/sinpo/comments/commentRss/236061.htmlhttp://www.aygfsteel.com/sinpo/services/trackbacks/236061.html

          synchronized

          package  sinpo.usagedemo;

          /**
            * 该例子说明线E休眠与{待以及(qing)注意事项?/font>
           
            @author  徐辛?sinpo.xu@hotmail.com) 
            * Oct 22, 2008
            */
          public class  PendingThreadDemo  {
               public  Console console =  new  Console () ;
               private  void  writeToConsole1 () {
                   synchronized ( console ){
                       try  {
                           Thread.sleep ( 1000 ) ; //NOTE:sleep时ƈ未释放console别的U程是不能锁定console?/font>
                           //TODO do things
                       catch  ( InterruptedException e ) {
                           e.printStackTrace () ;
                       }
                   }
               }
              
               private  void  writeToConsole2 () {
                   synchronized ( console ){
                       try  {
                           console.wait ( 1 * 1000 ) ; //NOTE:wait时别的线E是可以锁定console?/font>
                           //TODO do things
                       catch  ( InterruptedException e ) {
                           e.printStackTrace () ;
                       }
                   }
               }
          }
          //控制台类
          class  Console  {
               //TODO implements me
          }


          ]]>
          求助Q怎么贴代码才能保持代码的格式呀http://www.aygfsteel.com/sinpo/archive/2008/10/20/235554.html徐辛?/dc:creator>徐辛?/author>Mon, 20 Oct 2008 14:42:00 GMThttp://www.aygfsteel.com/sinpo/archive/2008/10/20/235554.htmlhttp://www.aygfsteel.com/sinpo/comments/235554.htmlhttp://www.aygfsteel.com/sinpo/archive/2008/10/20/235554.html#Feedback2http://www.aygfsteel.com/sinpo/comments/commentRss/235554.htmlhttp://www.aygfsteel.com/sinpo/services/trackbacks/235554.html ȝ(ch)有谁知道的告知一下。。?/span>
          今天l于扑ֈ一个不错的工具Q能用eclipse{编辑的java代码做成一样风格的html格式Q试用了(jin)挺好用的Q谢?a >Java2Html团队?

          ]]>Java NIO学习(fn)-UDP的例?/title><link>http://www.aygfsteel.com/sinpo/archive/2008/10/20/235553.html</link><dc:creator>徐辛?/dc:creator><author>徐辛?/author><pubDate>Mon, 20 Oct 2008 14:38:00 GMT</pubDate><guid>http://www.aygfsteel.com/sinpo/archive/2008/10/20/235553.html</guid><wfw:comment>http://www.aygfsteel.com/sinpo/comments/235553.html</wfw:comment><comments>http://www.aygfsteel.com/sinpo/archive/2008/10/20/235553.html#Feedback</comments><slash:comments>11</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sinpo/comments/commentRss/235553.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sinpo/services/trackbacks/235553.html</trackback:ping><description><![CDATA[<div id="wmqeeuq" class="Section0" style="layout-grid:15.6000pt;"> <p class="p0" style="margin-bottom:0pt; margin-top:0pt; "> <span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'?hu)?; "> <font face="?hu)?>q几天需要实C个底层基于UDP的协议,该协议底层用UDP传输但是h拥塞控制、超旉发、数据确认等功能又比TCP?QRUDPQReliable UDPQ。在实现协议底层的UDP服务时准备用Java的NIOQ在|上查资料都是以TCPZ讲的Q于是自qI了(jin)一下基于UDP的NIO?/font> </span> <span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'?hu)?; "> <o:p> </o:p> </span> </p> <p class="p0" style="margin-bottom:0pt; margin-top:0pt; "> <span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'?hu)?; ">NIO<font face="?hu)?>的思\是基于多路选择的,即由原来的每个连接都׃个线E来{待消息Q改为每个连接都在选择器上注册Q由选择器来{待。当然NIO引入?jin)很多新的概念,如ChannelQBuffer、Charset、Selector{,使得~程更简z、更面向对象化?/font></span> <span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'?hu)?; "> <o:p> </o:p> </span> </p> <p class="p0" style="margin-bottom:0pt; margin-top:0pt; "> <span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'?hu)?; "> <font face="?hu)?>下面贴出用NIO API攚w成UDPCZ代码Q注意其中用Charset来编码解码的q程Q当然Charsetq支持很多其他编码不仅局限于默认~码Q以?qing)Buffer的用?/font> </span> <span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'?hu)?; "> <o:p> </o:p> </span> </p> </div> <!-- ======================================================== --> <!-- = Java Sourcecode to HTML automatically converted code = --> <!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = --> <!-- = Further information: http://www.java2html.de = --> <div align="left" class="java"> <table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff"> <tbody> <tr> <!-- start source code --> <td nowrap="nowrap" valign="top" align="left"> <code> <font color="#7f0055"> <strong>package </strong> </font> <font color="#000000">sinpo.usagedemo;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.net.DatagramSocket;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.net.InetSocketAddress;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.net.SocketAddress;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.ByteBuffer;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.CharBuffer;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.channels.DatagramChannel;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.channels.SelectionKey;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.channels.Selector;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.charset.Charset;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.util.Iterator;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.util.Set;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#3f5fbf">/**</font> <br /> <font color="#ffffff"> </font> <font color="#3f5fbf">* </font> <font color="#7f9fbf">@author </font> <font color="#3f5fbf">徐辛?sinpo.xu@hotmail.com) Oct 19, 2008</font> <br /> <font color="#ffffff"> </font> <font color="#3f5fbf">*/</font> <br /> <font color="#7f0055"> <strong>public class </strong> </font> <font color="#000000">UDPServer </font> <font color="#7f0055"> <strong>extends </strong> </font> <font color="#000000">Thread </font> <font color="#000000">{</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>public </strong> </font> <font color="#7f0055"> <strong>void </strong> </font> <font color="#000000">run</font> <font color="#000000">() {</font> <br /> <font color="#ffffff"> </font> <font color="#000000">Selector selector = </font> <font color="#7f0055"> <strong>null</strong> </font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>try </strong> </font> <font color="#000000">{</font> <br /> <font color="#ffffff"> </font> <font color="#000000">DatagramChannel channel = DatagramChannel.open</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">DatagramSocket socket = channel.socket</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">channel.configureBlocking</font> <font color="#000000">(</font> <font color="#7f0055"> <strong>false</strong> </font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">socket.bind</font> <font color="#000000">(</font> <font color="#7f0055"> <strong>new </strong> </font> <font color="#000000">InetSocketAddress</font> <font color="#000000">(</font> <font color="#990000">5057</font> <font color="#000000">))</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff"> </font> <font color="#000000">selector = Selector.open</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">channel.register</font> <font color="#000000">(</font> <font color="#000000">selector, SelectionKey.OP_READ</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">} </font> <font color="#7f0055"> <strong>catch </strong> </font> <font color="#000000">(</font> <font color="#000000">Exception e</font> <font color="#000000">) {</font> <br /> <font color="#ffffff"> </font> <font color="#000000">e.printStackTrace</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff"> </font> <font color="#000000">ByteBuffer byteBuffer = ByteBuffer.allocate</font> <font color="#000000">(</font> <font color="#990000">65536</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>while </strong> </font> <font color="#000000">(</font> <font color="#7f0055"> <strong>true</strong> </font> <font color="#000000">) {</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>try </strong> </font> <font color="#000000">{</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>int </strong> </font> <font color="#000000">eventsCount = selector.select</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>if </strong> </font> <font color="#000000">(</font> <font color="#000000">eventsCount > </font> <font color="#990000">0</font> <font color="#000000">) {</font> <br /> <font color="#ffffff"> </font> <font color="#000000">Set selectedKeys = selector.selectedKeys</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">Iterator iterator = selectedKeys.iterator</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>while </strong> </font> <font color="#000000">(</font> <font color="#000000">iterator.hasNext</font> <font color="#000000">()) {</font> <br /> <font color="#ffffff"> </font> <font color="#000000">SelectionKey sk = </font> <font color="#000000">(</font> <font color="#000000">SelectionKey</font> <font color="#000000">) </font> <font color="#000000">iterator.next</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">iterator.remove</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>if </strong> </font> <font color="#000000">(</font> <font color="#000000">sk.isReadable</font> <font color="#000000">()) {</font> <br /> <font color="#ffffff"> </font> <font color="#000000">DatagramChannel datagramChannel = </font> <font color="#000000">(</font> <font color="#000000">DatagramChannel</font> <font color="#000000">) </font> <font color="#000000">sk</font> <br /> <font color="#ffffff"> </font> <font color="#000000">.channel</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">SocketAddress sa = datagramChannel</font> <br /> <font color="#ffffff"> </font> <font color="#000000">.receive</font> <font color="#000000">(</font> <font color="#000000">byteBuffer</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">byteBuffer.flip</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff"> </font> <font color="#3f7f5f">// 试Q通过收到的ByteBuffer首先通过~省的编码解码成CharBuffer 再输?/font> <br /> <font color="#ffffff"> </font> <font color="#000000">CharBuffer charBuffer = Charset.defaultCharset</font> <font color="#000000">()</font> <br /> <font color="#ffffff"> </font> <font color="#000000">.decode</font> <font color="#000000">(</font> <font color="#000000">byteBuffer</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">System.out.println</font> <font color="#000000">(</font> <font color="#2a00ff">"receive message:"</font> <br /> <font color="#ffffff"> </font> <font color="#000000">+ charBuffer.toString</font> <font color="#000000">())</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">byteBuffer.clear</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff"> </font> <font color="#000000">String echo = </font> <font color="#2a00ff">"This is the reply message from 服务器?</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">ByteBuffer buffer = Charset.defaultCharset</font> <font color="#000000">()</font> <br /> <font color="#ffffff"> </font> <font color="#000000">.encode</font> <font color="#000000">(</font> <font color="#000000">echo</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">datagramChannel.write</font> <font color="#000000">(</font> <font color="#000000">buffer</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <font color="#000000">} </font> <font color="#7f0055"> <strong>catch </strong> </font> <font color="#000000">(</font> <font color="#000000">Exception e</font> <font color="#000000">) {</font> <br /> <font color="#ffffff"> </font> <font color="#000000">e.printStackTrace</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>public static </strong> </font> <font color="#7f0055"> <strong>void </strong> </font> <font color="#000000">main</font> <font color="#000000">(</font> <font color="#000000">String</font> <font color="#000000">[] </font> <font color="#000000">args</font> <font color="#000000">) {</font> <br /> <font color="#ffffff"> </font> <font color="#7f0055"> <strong>new </strong> </font> <font color="#000000">UDPServer</font> <font color="#000000">()</font> <font color="#000000">.start</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff"> </font> <font color="#000000">}</font> <br /> <font color="#000000">}</font> </code> </td> <!-- end source code --> </tr> </tbody> </table> </div> <!-- = END of automatically generated HTML code = --> <!-- ======================================================== --> Client <br /> <!-- ======================================================== --> <!-- = Java Sourcecode to HTML automatically converted code = --> <!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = --> <!-- = Further information: http://www.java2html.de = --> <div align="left" class="java"> <table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff"> <tbody> <tr> <!-- start source code --> <td nowrap="nowrap" valign="top" align="left"> <code> <font color="#7f0055"> <strong>package </strong> </font> <font color="#000000">sinpo.usagedemo;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.net.InetSocketAddress;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.net.SocketAddress;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.ByteBuffer;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.channels.DatagramChannel;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.channels.SelectionKey;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.channels.Selector;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.nio.charset.Charset;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.util.Iterator;</font> <br /> <font color="#7f0055"> <strong>import </strong> </font> <font color="#000000">java.util.Set;</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#3f5fbf">/**</font> <br /> <font color="#ffffff"> </font> <font color="#3f5fbf">* </font> <font color="#7f9fbf">@author </font> <font color="#3f5fbf">徐辛?sinpo.xu@hotmail.com)</font> <br /> <font color="#ffffff"> </font> <font color="#3f5fbf">* Oct 19, 2008</font> <br /> <font color="#ffffff"> </font> <font color="#3f5fbf">*/</font> <br /> <font color="#7f0055"> <strong>public class </strong> </font> <font color="#000000">UDPClient </font> <font color="#7f0055"> <strong>extends </strong> </font> <font color="#000000">Thread </font> <font color="#000000">{</font> <br /> <font color="#ffffff">    </font> <font color="#7f0055"> <strong>public </strong> </font> <font color="#7f0055"> <strong>void </strong> </font> <font color="#000000">run</font> <font color="#000000">() {</font> <br /> <font color="#ffffff">        </font> <font color="#000000">DatagramChannel channel = </font> <font color="#7f0055"> <strong>null</strong> </font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#000000">Selector selector = </font> <font color="#7f0055"> <strong>null</strong> </font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#7f0055"> <strong>try </strong> </font> <font color="#000000">{</font> <br /> <font color="#ffffff">            </font> <font color="#000000">channel = DatagramChannel.open</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">            </font> <font color="#000000">channel.configureBlocking</font> <font color="#000000">(</font> <font color="#7f0055"> <strong>false</strong> </font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff">            </font> <font color="#000000">SocketAddress sa = </font> <font color="#7f0055"> <strong>new </strong> </font> <font color="#000000">InetSocketAddress</font> <font color="#000000">(</font> <font color="#2a00ff">"localhost"</font> <font color="#000000">, </font> <font color="#990000">5057</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff">            </font> <font color="#000000">channel.connect</font> <font color="#000000">(</font> <font color="#000000">sa</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#000000">} </font> <font color="#7f0055"> <strong>catch </strong> </font> <font color="#000000">(</font> <font color="#000000">Exception e</font> <font color="#000000">) {</font> <br /> <font color="#ffffff">            </font> <font color="#000000">e.printStackTrace</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff">        </font> <font color="#7f0055"> <strong>try </strong> </font> <font color="#000000">{</font> <br /> <font color="#ffffff">            </font> <font color="#000000">selector = Selector.open</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">            </font> <font color="#000000">channel.register</font> <font color="#000000">(</font> <font color="#000000">selector, SelectionKey.OP_READ</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff">            </font> <font color="#000000">channel.write</font> <font color="#000000">(</font> <font color="#000000">Charset.defaultCharset</font> <font color="#000000">()</font> <font color="#000000">.encode</font> <font color="#000000">(</font> <font color="#2a00ff">"Tell me your time"</font> <font color="#000000">))</font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#000000">} </font> <font color="#7f0055"> <strong>catch </strong> </font> <font color="#000000">(</font> <font color="#000000">Exception e</font> <font color="#000000">) {</font> <br /> <font color="#ffffff">            </font> <font color="#000000">e.printStackTrace</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#000000">}</font> <br /> <font color="#ffffff">        </font> <br /> <font color="#ffffff">        </font> <font color="#000000">ByteBuffer byteBuffer = ByteBuffer.allocate</font> <font color="#000000">(</font> <font color="#990000">100</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff">        </font> <font color="#7f0055"> <strong>while </strong> </font> <font color="#000000">(</font> <font color="#7f0055"> <strong>true</strong> </font> <font color="#000000">) {</font> <br /> <font color="#ffffff">            </font> <font color="#7f0055"> <strong>try </strong> </font> <font color="#000000">{</font> <br /> <font color="#ffffff">                </font> <font color="#7f0055"> <strong>int </strong> </font> <font color="#000000">eventsCount = selector.select</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                </font> <font color="#7f0055"> <strong>if </strong> </font> <font color="#000000">(</font> <font color="#000000">eventsCount > </font> <font color="#990000">0</font> <font color="#000000">) {</font> <br /> <font color="#ffffff">                    </font> <font color="#000000">Set selectedKeys = selector.selectedKeys</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                    </font> <font color="#000000">Iterator iterator = selectedKeys.iterator</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                    </font> <font color="#7f0055"> <strong>while </strong> </font> <font color="#000000">(</font> <font color="#000000">iterator.hasNext</font> <font color="#000000">()) {</font> <br /> <font color="#ffffff">                        </font> <font color="#000000">SelectionKey sk = </font> <font color="#000000">(</font> <font color="#000000">SelectionKey</font> <font color="#000000">) </font> <font color="#000000">iterator.next</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                        </font> <font color="#000000">iterator.remove</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                        </font> <font color="#7f0055"> <strong>if </strong> </font> <font color="#000000">(</font> <font color="#000000">sk.isReadable</font> <font color="#000000">()) {</font> <br /> <font color="#ffffff">                            </font> <font color="#000000">DatagramChannel datagramChannel = </font> <font color="#000000">(</font> <font color="#000000">DatagramChannel</font> <font color="#000000">) </font> <font color="#000000">sk</font> <br /> <font color="#ffffff">                                    </font> <font color="#000000">.channel</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                            </font> <font color="#000000">datagramChannel.read</font> <font color="#000000">(</font> <font color="#000000">byteBuffer</font> <font color="#000000">)</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                            </font> <font color="#000000">byteBuffer.flip</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                            </font> <br /> <font color="#ffffff">                            </font> <font color="#3f7f5f">//TODO 报文{化ؓ(f)RUDP消息q调用RUDP协议处理器来处理</font> <br /> <font color="#ffffff">                            </font> <br /> <font color="#ffffff">                            </font> <font color="#000000">System.out.println</font> <font color="#000000">(</font> <font color="#000000">Charset.defaultCharset</font> <font color="#000000">()</font> <font color="#000000">.decode</font> <font color="#000000">(</font> <br /> <font color="#ffffff">                                    </font> <font color="#000000">byteBuffer</font> <font color="#000000">)</font> <font color="#000000">.toString</font> <font color="#000000">())</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                            </font> <font color="#000000">byteBuffer.clear</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                            </font> <font color="#000000">datagramChannel.write</font> <font color="#000000">(</font> <font color="#000000">Charset.defaultCharset</font> <font color="#000000">()</font> <br /> <font color="#ffffff">                                    </font> <font color="#000000">.encode</font> <font color="#000000">(</font> <font color="#2a00ff">"Tell me your time"</font> <font color="#000000">))</font> <font color="#000000">;</font> <br /> <font color="#ffffff">                        </font> <font color="#000000">}</font> <br /> <font color="#ffffff">                    </font> <font color="#000000">}</font> <br /> <font color="#ffffff">                </font> <font color="#000000">}</font> <br /> <font color="#ffffff">            </font> <font color="#000000">} </font> <font color="#7f0055"> <strong>catch </strong> </font> <font color="#000000">(</font> <font color="#000000">Exception e</font> <font color="#000000">) {</font> <br /> <font color="#ffffff">                </font> <font color="#000000">e.printStackTrace</font> <font color="#000000">()</font> <font color="#000000">;</font> <br /> <font color="#ffffff">            </font> <font color="#000000">}</font> <br /> <font color="#ffffff">        </font> <font color="#000000">}</font> <br /> <font color="#ffffff"> </font> <br /> <font color="#ffffff">    </font> <font color="#000000">}</font> <br /> <font color="#000000">}</font> </code> </td> <!-- end source code --> </tr> </tbody> </table> </div> <!-- = END of automatically generated HTML code = --> <!-- ======================================================== --> <img src ="http://www.aygfsteel.com/sinpo/aggbug/235553.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sinpo/" target="_blank">徐辛?/a> 2008-10-20 22:38 <a href="http://www.aygfsteel.com/sinpo/archive/2008/10/20/235553.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式学习(fn)-Z接口的模?/title><link>http://www.aygfsteel.com/sinpo/archive/2008/10/20/235541.html</link><dc:creator>徐辛?/dc:creator><author>徐辛?/author><pubDate>Mon, 20 Oct 2008 13:48:00 GMT</pubDate><guid>http://www.aygfsteel.com/sinpo/archive/2008/10/20/235541.html</guid><wfw:comment>http://www.aygfsteel.com/sinpo/comments/235541.html</wfw:comment><comments>http://www.aygfsteel.com/sinpo/archive/2008/10/20/235541.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sinpo/comments/commentRss/235541.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sinpo/services/trackbacks/235541.html</trackback:ping><description><![CDATA[     摘要:   <a href='http://www.aygfsteel.com/sinpo/archive/2008/10/20/235541.html'>阅读全文</a><img src ="http://www.aygfsteel.com/sinpo/aggbug/235541.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sinpo/" target="_blank">徐辛?/a> 2008-10-20 21:48 <a href="http://www.aygfsteel.com/sinpo/archive/2008/10/20/235541.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用ClassLoaderd资源文ghttp://www.aygfsteel.com/sinpo/archive/2008/10/19/235328.html徐辛?/dc:creator>徐辛?/author>Sun, 19 Oct 2008 12:36:00 GMThttp://www.aygfsteel.com/sinpo/archive/2008/10/19/235328.htmlhttp://www.aygfsteel.com/sinpo/comments/235328.htmlhttp://www.aygfsteel.com/sinpo/archive/2008/10/19/235328.html#Feedback0http://www.aygfsteel.com/sinpo/comments/commentRss/235328.htmlhttp://www.aygfsteel.com/sinpo/services/trackbacks/235328.htmlClasscȝgetResourceAsStream(String resourcePath);
          ClassLoadercȝgetResourceAsStream(String resourcePath)
          Classcȝ该方法最l还是委zC(j)lassLoader的getResourceAsStreamҎ(gu)Q但是用中发现Class#getResourceAsStream()使用的是l对路径Q以/开_(d)(j)Q而ClassLoader#getResourceAsStream()使用的相对\径?
          propterty文gl常攑֜c\径的根\径下Q最层包的上层目录Q如classesQ,q样加蝲property文g时就可以先用Class#getResourceAsStreamҎ(gu)获取输入源,再从该输入源load各entry?/div> code piece:
          package sinpo.usagedemo;

          import java.io.BufferedReader;
          import java.io.InputStream;
          import java.io.InputStreamReader;
          import java.util.Properties;

          import junit.framework.TestCase;

          /**
           @author 徐辛?sinpo.xu@hotmail.com)
           * Oct 19, 2008
           */
          public class LoadResource extends TestCase {
              public void test() throws Exception {
                  //usage 1Q?#160;use absolute path (mostly used)
                  InputStream in1 = this.getClass().getResourceAsStream("/sinpo/test2.properties");
                  //usage 2: use relative path
                  InputStream in2 = this.getClass().getClassLoader().getResourceAsStream("sinpo/test2.properties");
                  //usage 3: use system class path
                  InputStream in3 = ClassLoader.getSystemResourceAsStream("system.properties");
                  
                  //读取的资源作ؓ(f)Properties的输入源
                  Properties props = new Properties();
                  props.load(in1);
                  String propValue = props.getProperty("propKey");
                  System.out.println(propValue);
                  
                  //读取的资源作ؓ(f)文本输出
                  InputStreamReader reader = new InputStreamReader(in1);
                  BufferedReader bReader = new BufferedReader(reader);
                  String content = bReader.readLine();
                  //输出W一行内?/font>
                  System.out.println(content);
                  
                  //TODO close them
              }
          }


          ]]>