隨筆-153  評論-235  文章-19  trackbacks-0
           
              用String.substring方法,不小心會有越界異?!,F(xiàn)實(shí)現(xiàn)一個(gè)沒拋出越界異常,越界就返回null,不過直接返回的再用其它方法,可能有Null異?!,F(xiàn)還實(shí)現(xiàn)可以負(fù)index的,可能逆向的。
          package com.chenlb.util;   
            
          public class StringUtil {   
                 
              
          /**  
               * start與end均可負(fù)數(shù)<br/>  
               * start < end正向取, start > end逆向取<br/>  
               * 示例:str="I am chenlb"<br/>  
               * StringUtil.substring(str, 0, 12) -> null<br/>  
               * StringUtil.substring(str, 12, 12) -> null<br/>  
               * StringUtil.substring(str, 12, 13) -> null<br/>  
               * StringUtil.substring(str, 4, 4) -> ""<br/>  
               * StringUtil.substring(str, 0, 4) -> "I am"<br/>  
               * StringUtil.substring(str, -4, -1) -> "enl"<br/>  
               * StringUtil.substring(str, -2, 4) -> "lbI am"<br/>  
               * StringUtil.substring(str, 4, 0) -> "ma I"<br/>  
               * StringUtil.substring(str, -1, -4) -> "lne"<br/>  
               * StringUtil.substring(str, 1, -4) -> "Iblne"<br/>  
               * StringUtil.substring(str, 0, -4) -> "blne"<br/>  
               * StringUtil.substring(str, -4, 0) -> "enlb"<br/>  
               * 
          @return 越界返回null, start==end返回空  
               * 
          @author chenlb 2008-6-18 下午12:39:51  
               
          */  
              
          public static String substring(String str, int start, int end) {   
                  
          if(str == null) {   
                      
          return null;   
                  }   
                  
          int len = str.length();   
                  
          if(Math.abs(start) >= len) {   
                      
          return null;   
                  }   
                  
          if(Math.abs(end) > len) {   
                      
          return null;   
                  }   
                  StringBuilder sb 
          = new StringBuilder();   
                  
          if(end > start) {    //正向   
                      substring(sb, str, start, end);   
                  } 
          else if(end == start) {   
                      
          return "";   
                  } 
          else {    //逆向 end < start   
                      substring(sb, str, end, start);   
                      sb.reverse();   
                  }   
                  
          return sb.toString();   
              }   
                 
              
          private static void substring(StringBuilder sb, String str, int start, int end) {   
                  
          int len = str.length();   
                  
          if(start < 0) {   
                      
          if(end < 0) {   
                          sb.append(str.substring(len
          +start, len+end));   
                      } 
          else {   
                          sb.append(str.substring(len
          +start, len));   
                          sb.append(str.substring(
          0, end));   
                      }   
                  } 
          else {   
                      sb.append(str.substring(start, end));   
                  }   
              }   
          }  

          測試代碼:
          public void testSubstring() {   
                  String str 
          = "I am chenlb";   
                     
                  assertEquals(
          null, StringUtil.substring(str, 012));   
                  assertEquals(
          null, StringUtil.substring(str, 1212));   
                  assertEquals(
          null, StringUtil.substring(str, 1213));   
                     
                  assertEquals(
          "", StringUtil.substring(str, 44));   
                     
                  assertEquals(
          "I am", StringUtil.substring(str, 04));   
                  assertEquals(
          "am", StringUtil.substring(str, 24));   
                  assertEquals(
          "I am chenlb", StringUtil.substring(str, 011));   
                     
                  assertEquals(
          "enl", StringUtil.substring(str, -4-1));   
                  assertEquals(
          "lbI am", StringUtil.substring(str, -24));   
                     
                  assertEquals(
          "ma I", StringUtil.substring(str, 40));   
                  assertEquals(
          "lne", StringUtil.substring(str, -1-4));   
                  assertEquals(
          "Iblne", StringUtil.substring(str, 1-4));   
                     
                  assertEquals(
          "blne", StringUtil.substring(str, 0-4));   
                  assertEquals(
          "enlb", StringUtil.substring(str, -40));   
          }  
          posted @ 2008-06-24 13:53 流浪汗 閱讀(556) | 評論 (0)編輯 收藏

          Windows網(wǎng)絡(luò)命令行程序 

           
          ipconfig /all 查看配置 
          ipconfig /renew 刷新配置 
          ipconfig 管理 DNS 和 DHCP 類別 ID
          Ping 測試連接
          Arp 解決硬件地址問題
          nbtstat 解決 NetBIOS 名稱問題
          netstat 顯示連接統(tǒng)計(jì)
          tracert 跟蹤網(wǎng)絡(luò)連接
          pathping 測試路由器

          posted @ 2008-06-24 13:51 流浪汗 閱讀(273) | 評論 (0)編輯 收藏

              今天運(yùn)行下程序,報(bào)錯說“內(nèi)存不夠”。在Tomcat可以擴(kuò)大JVM的內(nèi)存棧呢?然后看那bin目錄下啟動文件,找到catalina.bat文件的JAVA_OPTS(大概在103行,5.5.X),在再添加一個(gè)set JAVA_OPTS參數(shù)即可如:

          set JAVA_OPTS=%JAVA_OPTS% -Xms100m -Xmx512m 
          posted @ 2008-06-24 13:49 流浪汗 閱讀(375) | 評論 (0)編輯 收藏
              前段時(shí)間學(xué)習(xí)Linux命令,偶然發(fā)現(xiàn)curl命令很有用。這里簡單介紹下。網(wǎng)絡(luò)上部分解析是:curl是一個(gè)利用URL語法在命令行方式下工作的文件傳輸工具。

             它可以取得有規(guī)律的url的內(nèi)容。比如:http://www.example.com/001.html 到 http://www.example.com/100.html ,它有一種表達(dá)式可以這些內(nèi)容下載下來,這功能絕對比迅雷強(qiáng),迅雷只支持一個(gè)變量,curl只你喜歡可任意多。它可繼點(diǎn)續(xù)傳,提交表單……

             來看下簡單的使用:

          1.查看響應(yīng)的頭
          curl -I http://chenlb.javaeye.com 
          現(xiàn)在正如robbin說的可以看下X-Runtime: 0.47101

          2.在學(xué)校要代理才可以上javaeye.com。用-x設(shè)代理
          curl -x proxy.gdut.edu.cn:8080 -I http://chenlb.javaeye.com 

          3.把返回的內(nèi)容保存下來,用-o filename參數(shù)
          curl -o chenlb.html http://chenlb.javaeye.com  

          4.保存內(nèi)容時(shí)要filename很煩,用一個(gè)-O參數(shù)來指定用服務(wù)器的文件名,這個(gè)批量下載很有用。
          curl -O http://baike.baidu.com/view/[1-2].htm
          批量下載百科的1.htm 2.htm兩個(gè)頁面,這功能夠強(qiáng)。

          我常用的就是以上四個(gè)。

          5.很多要referer的,有-e參數(shù)可以設(shè)置
          curl -o me.html -e http://www.javaeye.com http://chenlb.javaeye.com  

          還有很多很多參數(shù),留給大家去發(fā)現(xiàn),比如:發(fā)送數(shù)據(jù),提交表單,設(shè)置用戶與密碼,用什么協(xié)議啊……
          posted @ 2008-06-24 13:47 流浪汗 閱讀(1511) | 評論 (0)編輯 收藏
                java命令引入jar時(shí)可以-cp參數(shù),但時(shí)-cp不能用通配符(多個(gè)jar時(shí)什么煩要一個(gè)個(gè)寫,不能*.jar),面通常的jar都在同一目錄,且多于1個(gè)。前些日子找到(發(fā)現(xiàn))-Djava.ext.dirs太好。

          如:

          java -Djava.ext.dirs=lib MyClass  
          posted @ 2008-06-22 23:58 流浪汗 閱讀(5102) | 評論 (0)編輯 收藏
              javascript xslt 處理xml備忘錄。支持firefox。
          參考:
          w3school XSLT - 客戶端 http://www.w3school.com.cn/xsl/xsl_client.asp
          如何使用Javascript XSLT 處理XML文件 http://java.chinaitlab.com/advance/533787.html

          1.xml文件,cdcatalog.xml
          <?xml version="1.0" encoding="ISO-8859-1"?>
          <!-- Edited with XML Spy v2007 (http://www.altova.com) -->
          <catalog>
              
          <cd>
                  
          <title>Empire Burlesque</title>
                  
          <artist>Bob Dylan</artist>
                  
          <country>USA</country>
                  
          <company>Columbia</company>
                  
          <price>10.90</price>
                  
          <year>1985</year>
              
          </cd>
              
          <cd>
                  
          <title>Hide your heart</title>
                  
          <artist>Bonnie Tyler</artist>
                  
          <country>UK</country>
                  
          <company>CBS Records</company>
                  
          <price>9.90</price>
                  
          <year>1988</year>
              
          </cd>
          </catalog>

          2.xsl文件,cdcatalog.xsl
          <?xml version="1.0" encoding="ISO-8859-1"?>
          <!-- Edited with XML Spy v2007 (http://www.altova.com) -->
          <xsl:stylesheet version="1.0"
          xmlns:xsl
          ="http://www.w3.org/1999/XSL/Transform">
          <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>

          <xsl:template match="/">
            
          <html>
            
          <body>
            
          <h2>My CD Collection</h2>
              
          <table border="1">
                
          <tr bgcolor="#9acd32">
                  
          <th align="left">Title</th>
                  
          <th align="left">Artist</th>
                
          </tr>
                
          <xsl:for-each select="catalog/cd">
                
          <tr>
                  
          <td><xsl:value-of select="title"/></td>
                  
          <td><xsl:value-of select="artist"/></td>
                
          </tr>
                
          </xsl:for-each>
              
          </table>
            
          </body>
            
          </html>
          </xsl:template>
          </xsl:stylesheet>


          3.html文件,index.html
          <html>
          <body>

          <script type="text/javascript">
          var xml;
          var xsl;
          if(typeof window.ActiveXObject != 'undefined') {
              xml 
          = new ActiveXObject("Microsoft.XMLDOM");
              xsl 
          = new ActiveXObject("Microsoft.XMLDOM");
          else if(document.implementation && document.implementation.createDocument) {    //mozilla
              xml = document.implementation.createDocument(""""null);
              xsl 
          = document.implementation.createDocument(""""null);
          }
          // Load XML 

          xml.async 
          = false;
          xml.load(
          "cdcatalog.xml");

          // Load XSL

          xsl.async 
          = false;
          xsl.load(
          "cdcatalog.xsl");

          // Transform

          if(typeof window.ActiveXObject != 'undefined') {
              document.write(xml.transformNode(xsl));
          else if(document.implementation && document.implementation.createDocument) {    //mozilla
              var xsltProcessor = new XSLTProcessor();
              xsltProcessor.importStylesheet(xsl);
              
          // transformToDocument方式
              var result = xsltProcessor.transformToDocument(xml);
              
          var xmls = new XMLSerializer();
              document.write(xmls.serializeToString(result));
          }

          </script>

          </body>
          </html>


          posted @ 2008-05-18 19:02 流浪汗 閱讀(808) | 評論 (1)編輯 收藏
               摘要: 自己實(shí)現(xiàn)的優(yōu)先隊(duì)列 PriorityQueue  閱讀全文
          posted @ 2008-05-08 23:08 流浪汗 閱讀(1014) | 評論 (0)編輯 收藏
              想到局域網(wǎng)上建一個(gè)dns服務(wù)器,昨天晚上搞了好久都不成,包括今天也發(fā)了好多時(shí)間也不能通過.最后找到

          水小筑之Blog

          http://blog.chinaunix.net/u/5302/showart_238337.html
          的博客, 幫了大忙,網(wǎng)上的很多文章都試過了都沒有很好的結(jié)果.

          我安裝的centos是單CD的服務(wù)版本.安裝后已經(jīng)有bind了

          1.配置文件在/etc/named.conf
          //
          // named.conf for Red Hat caching-nameserver 
          //

          options {
              directory 
          "/var/named";
              dump
          -file "/var/named/data/cache_dump.db";
                  statistics
          -file "/var/named/data/named_stats.txt";
              
          /*
               
          * If there is a firewall between you and nameservers you want
               
          * to talk to, you might need to uncomment the query-source
               
          * directive below.  Previous versions of BIND always asked
               
          * questions using port 53, but BIND 8.1 uses an unprivileged
               
          * port by default.
               
          */
               
          // query-source address * port 53;
          };

          // 
          // a caching only nameserver config
          // 
          controls {
              inet 
          127.0.0.1 allow { localhost; } keys { rndckey; };
          };

          zone 
          "." IN {
              type hint;
              file 
          "named.ca";
          };

          zone 
          "localdomain" IN {
              type master;
              file 
          "localdomain.zone";
              allow
          -update { none; };
          };

          zone 
          "localhost" IN {
              type master;
              file 
          "localhost.zone";
              allow
          -update { none; };
          };

          zone 
          "chenlb.com" IN {
              type master;
              file 
          "chenlb.com.zone";
              allow
          -query { any; };
              allow
          -transfer { any; };
              allow
          -update { none; };
          };

          zone 
          "0.0.127.in-addr.arpa" IN {
              type master;
              file 
          "named.local";
              allow
          -update { none; };
          };

          zone 
          "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
                  type master;
              file 
          "named.ip6.local";
              allow
          -update { none; };
          };

          zone 
          "255.in-addr.arpa" IN {
              type master;
              file 
          "named.broadcast";
              allow
          -update { none; };
          };

          zone 
          "0.in-addr.arpa" IN {
              type master;
              file 
          "named.zero";
              allow
          -update { none; };
          };

          include 
          "/etc/rndc.key";

              只要添加一個(gè)zone就行,看上面
          zone "chenlb.com" IN {
              type master;
              file 
          "chenlb.com.zone";
              allow
          -query { any; };
              allow
          -transfer { any; };
              allow
          -update { none; };
          };

          2.在/var/named/chroot/var/named/目錄里建個(gè)chenlb.com.zone(上面的file),內(nèi)容如下:
          $TTL    86400
          @       IN      SOA    chenlb.com.  root.chenlb.com.(
                                                
          2008050201 ; Serial
                                                
          28800      ; Refresh
                                                
          14400      ; Retry
                                                
          3600000    ; Expire
                                                
          86400 )    ; Minimum
                  IN NS    chenlb.com.
                  IN MX 
          10 mail.chenlb.com.
          @       IN A     
          192.168.0.60
          www     IN A     
          192.168.0.60
          ftp     IN A     
          192.168.0.60
          mail    IN A     
          192.168.0.60

          3.在/var/named目錄下建鏈接
          # ch /var/named
          #
           ln -s /var/named/chroot/var/named/chenlb.com.zone chenlb.com.zone

          4.啟動named
          # /etc/init.d/named start

          5.測試前添加nds服務(wù)地址
          # vi /etc/resolv.conf

          在加
          nameserver 192.168.0.60
          search chenlb.com
          說明:192.168.0.60是我本機(jī)地址

          現(xiàn)在本機(jī)下可以ping  www.chenlb.com了

          要在加的機(jī)上可以使用DNS服務(wù),要在防火墻里允許

          6.修改/etc/sysconfig/iptables添加下面的
          -A RH-Firewall-1-INPUT -p udp -m udp --dport 53 -j ACCEPT
          -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT

              OK,現(xiàn)在在win里添加dns地址192.168.0.60就在ping  www.chenlb.com了. 呵呵


          posted @ 2008-05-02 20:46 流浪汗 閱讀(1020) | 評論 (0)編輯 收藏
              昨天安裝好了lighttpd,現(xiàn)在想試下與tomcat的一起工作。把所有的*.jsp讓tomcat去處理。用到lighttpd的代理,lighttpd與tomcat比apache與tomcat要簡單多。開始喜歡上了lighttpd。

          修改lighttpd的配置
          # vi /usr/local/lighttpd-1.4.19/lighttpd.conf

          去掉mod_proxy注釋
          server.modules              = (
          #...
          #                               
          "mod_proxy",
          #...
                                        )

          去掉proxy.server注釋
          proxy.server               = ( ".jsp" =>
                                         ( 
          "localhost" =>
                                           (
                                             
          "host" ="192.168.0.60",
                                             
          "port" =8080
                                           )
                                         )
                                       )



          重啟lighttpd,然后http://192.168.0.60/index.jsp就可以看到tomcat的頁面了。
          posted @ 2008-05-02 00:03 流浪汗 閱讀(2298) | 評論 (0)編輯 收藏
              近幾日都想玩下服務(wù)器。此文是在linux下的lighttpd安裝php。參考瘋狂的鼠標(biāo) 的博客: http://blog.csdn.net/shined_zhang/archive/2007/10/28/1852349.aspx

          1.安裝lighttpd看http://www.aygfsteel.com/chenlb/archive/2008/04/30/197617.html

          2.安裝mysql看http://www.aygfsteel.com/chenlb/archive/2007/03/20/105114.html

          3.安裝php,先到http://www.php.net 下載,我下載的是php-5.2.5
          # tar -zxvf php-5.2.5.tar.gz
          # cd php-
          5.2.5
          #./configure --prefix
          =/usr/local/php-5.2.5 --enable-fastcgi --with-mysql=/usr/local/mysql --enable-zend-multibyte --with-config-file-path=/usr/local/php-5.2.5/conf --enable-discard-path --enable-force-cgi-redirect
          # make
          # make install
          #mkdir /usr/local/php-
          5.2.5/conf
          #cp php.ini-dist /usr/local/php-
          5.2.5/conf/php.ini

              我在安裝過程中也出過問題,說我沒有找到xml2。要yum install libxml2*一下。

          4.修改lighttpd的配置。  把mod_fastcgi去掉注釋。
          # vi /usr/local/lighttpd-1.4.19/lighttpd.conf

          server.modules              = (
          #
          #                               
          "mod_fastcgi",
          #
                                        )

            

              找到fastcgi.server去掉注釋,修改后看起來像。
          fastcgi.server             = ( ".php" =>
                                         ( 
          "localhost" =>
                                           (
                                             
          "socket" ="/usr/local/lighttpd-1.4.19/php-fastcgi.socket",
                                             
          "bin-path" ="/usr/local/php-5.2.5/bin/php-cgi"
                                           )
                                         )
                                      )


          5.php測試頁面phpinfo.php放到你的www目錄下。
          <?php
          echo phpinfo();
          ?>


          最后啟動或重啟lighttpd即可。

          posted @ 2008-05-01 16:48 流浪汗 閱讀(1184) | 評論 (0)編輯 收藏
          僅列出標(biāo)題
          共16頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 Last 
          主站蜘蛛池模板: 桦甸市| 小金县| 河东区| 察隅县| 天峨县| 理塘县| 龙口市| 敖汉旗| 昌都县| 富宁县| 洪泽县| 高要市| 临猗县| 类乌齐县| 德令哈市| 乌海市| 湘乡市| 茶陵县| 尉犁县| 弥渡县| 沅陵县| 新民市| 淮北市| 化德县| 南涧| 和顺县| 遵化市| 通化县| 三原县| 昌邑市| 花莲县| 千阳县| 苍南县| 白银市| 中牟县| 双柏县| 墨江| 延吉市| 叙永县| 克什克腾旗| 施秉县|