<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-153  評論-235  文章-19  trackbacks-0
     
        用String.substring方法,不小心會有越界異常。現實現一個沒拋出越界異常,越界就返回null,不過直接返回的再用其它方法,可能有Null異常。現還實現可以負index的,可能逆向的。
    package com.chenlb.util;   
      
    public class StringUtil {   
           
        
    /**  
         * start與end均可負數<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 流浪汗 閱讀(552) | 評論 (0)編輯 收藏

    Windows網絡命令行程序 

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

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

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

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

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

       來看下簡單的使用:

    1.查看響應的頭
    curl -I http://chenlb.javaeye.com 
    現在正如robbin說的可以看下X-Runtime: 0.47101

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

    3.把返回的內容保存下來,用-o filename參數
    curl -o chenlb.html http://chenlb.javaeye.com  

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

    我常用的就是以上四個。

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

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

    如:

    java -Djava.ext.dirs=lib MyClass  
    posted @ 2008-06-22 23:58 流浪汗 閱讀(5096) | 評論 (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 流浪汗 閱讀(801) | 評論 (1)編輯 收藏
         摘要: 自己實現的優先隊列 PriorityQueue  閱讀全文
    posted @ 2008-05-08 23:08 流浪汗 閱讀(1011) | 評論 (0)編輯 收藏
        想到局域網上建一個dns服務器,昨天晚上搞了好久都不成,包括今天也發了好多時間也不能通過.最后找到

    水小筑之Blog

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

    我安裝的centos是單CD的服務版本.安裝后已經有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";

        只要添加一個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/目錄里建個chenlb.com.zone(上面的file),內容如下:
    $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服務地址
    # vi /etc/resolv.conf

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

    現在本機下可以ping  www.chenlb.com了

    要在加的機上可以使用DNS服務,要在防火墻里允許

    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,現在在win里添加dns地址192.168.0.60就在ping  www.chenlb.com了. 呵呵


    posted @ 2008-05-02 20:46 流浪汗 閱讀(1016) | 評論 (0)編輯 收藏
        昨天安裝好了lighttpd,現在想試下與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 流浪汗 閱讀(2286) | 評論 (0)編輯 收藏
        近幾日都想玩下服務器。此文是在linux下的lighttpd安裝php。參考瘋狂的鼠標 的博客: http://blog.csdn.net/shined_zhang/archive/2007/10/28/1852349.aspx

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

    2.安裝mysql看http://www.tkk7.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 流浪汗 閱讀(1179) | 評論 (0)編輯 收藏
    僅列出標題
    共16頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 Last 
    主站蜘蛛池模板: 精品免费tv久久久久久久| 亚洲精品国偷自产在线| 久久成人国产精品免费软件| 免费国产a理论片| 在线观看亚洲AV每日更新无码| 亚洲成在人天堂在线| 国产精品亚洲不卡一区二区三区| 免费黄色app网站| 国产成人精品免费视频大| 国色精品va在线观看免费视频 | 中文字幕成人免费高清在线| 亚洲AV永久无码天堂影院| 91亚洲视频在线观看| 亚洲国产精品第一区二区| 在线观看亚洲精品国产| 亚洲国产精品一区二区第一页免| 日韩高清在线高清免费| 免费无码黄十八禁网站在线观看| 亚洲视频免费在线播放| 99国产精品免费观看视频| 在线观看片免费人成视频无码 | 美腿丝袜亚洲综合| 亚洲精品动漫人成3d在线| 四虎永久成人免费影院域名| 全免费a级毛片免费看不卡| 免费看国产成年无码AV片| 100000免费啪啪18免进| 国产91免费在线观看| 69av免费视频| 免费H网站在线观看的| 国产精品成人免费一区二区| 精品成在人线AV无码免费看| 亚洲一级毛片免费看| 99视频全部免费精品全部四虎| xxxx日本免费| 一二三四在线观看免费高清中文在线观看| 色老头永久免费网站| 国产免费av片在线看| 国产免费观看黄AV片| 亚洲成A人片在线观看无码3D| 亚洲国产电影av在线网址|