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

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

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

    軟件是對質量的不懈追求

    2010年4月26日 #

    linux du 查看文件夾占用空間


    du -sh *

    posted @ 2011-04-15 08:39 BlakeSu 閱讀(280) | 評論 (0)編輯 收藏

    Building Standalone Application with Maven2

    If you are building standalone application in Java, Maven is your friend when packing your application,
    There are two way to let Maven package your application, either as a single jar with all your dependencies jar.


     <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
       <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
       </descriptorRefs>
      </configuration>
     </plugin>



    One advantage if you choose to do this way is if you need to sign your application jar.
    This is needed if you are building a Java Web Start client and you need more access than connecting back to the server.
    To read more about have Maven signing your jar read http://maven.apache.org/plugins/maven-jar-plugin/usage.html.
    But if you choose to go this way, make sure that all license agreement are shipped with your one single jar.

    Another way is to let Maven package your source code only and then referring the dependent jar file from the MANIFEST file.


     <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
       <archive>
        <manifest>
         <addClasspath>true</addClasspath>
         <mainClass>se.msc.adapter.Main</mainClass>
         <classpathPrefix>lib/</classpathPrefix>
        </manifest>
       </archive>
      </configuration>
     </plugin>

    posted @ 2011-02-24 13:03 BlakeSu 閱讀(329) | 評論 (0)編輯 收藏

    eclipse 終于有了列編輯功能

    eclipse 3.5之后終于有了列編輯,快捷鍵是alt+shift+a,再次按此快捷鍵返回常規編輯狀態。


    posted @ 2010-10-15 11:33 BlakeSu 閱讀(1484) | 評論 (0)編輯 收藏

    LineNumberReader 指定文件編碼


    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.LineNumberReader;


    public class Main {
        
        
    public static void main(String[] args) throws IOException {

            InputStreamReader isr 
    = new InputStreamReader(new FileInputStream("15370720.pdf4"), "utf-16");
            LineNumberReader lnr
    =new LineNumberReader(isr);
            String line 
    = null;
            
    while((line=lnr.readLine())!=null){  
               System.out.println(lnr.getLineNumber()
    +"\t"+line);
            }
       }
    }

    posted @ 2010-08-05 09:13 BlakeSu 閱讀(1050) | 評論 (0)編輯 收藏

    Class.getResourceAsStream 和 ClassLoader.getResourceAsStream

    兩個方法的區別是資源的定義不同, 一個主要用于相對與一個object取資源,而另一個用于取相對于classpath的
    資源,用的是絕對路徑。

    在使用Class.getResourceAsStream 時, 資源路徑有兩種方式, 一種以 / 開頭,則這樣的路徑是指定絕對
    路徑, 如果不以 / 開頭, 則路徑是相對與這個class所在的包的。

    在使用ClassLoader.getResourceAsStream時, 路徑直接使用相對于classpath的絕對路徑。

    舉例,下面的三個語句,實際結果是一樣的:
       com.explorers.Test.class.getResourceAsStream("abc.jpg")
    = com.explorers.Test.class.getResourceAsStream("/com/explorers/abc.jpg")
    = ClassLoader.getResourceAsStream("com/explorers/abc.jpg")

    posted @ 2010-07-28 16:31 BlakeSu 閱讀(295) | 評論 (0)編輯 收藏

    Standalone Java CAS Client

    There's a variety of clients for CAS. The Java-based clients (JA-SIG, Yale, see JA-SIG website) typically handle the browser-based client interaction with CAS very well through ServletFilter implementations.

    Now what about programmatic authentication, i.e. achieving authentication through non-browser based applications? There exists a CAS .NET client but I did not manage to find the appropriate Java implementation. So here goes - it is based on the Apache HttpClient.

    In case I missed any existing implementation achieving the same purpose, let's look at the bright side: at least now I understand the CAS protocol :-)

    My CAS client works within any application. It uses the HttpClient and behaves like a browser client as CAS requires cookie support.

    Here's the code:
    import org.apache.commons.httpclient.Header;
    import org.apache.commons.httpclient.HttpClient;
    import org.apache.commons.httpclient.HttpMethod;
    import org.apache.commons.httpclient.HttpStatus;
    import org.apache.commons.httpclient.methods.GetMethod;
    import org.apache.commons.httpclient.methods.PostMethod;
    import org.apache.log4j.Logger;

    /**
    * The CasClient allows users to programmatically login
    * to CAS protected services based on the CAS 2 protocol.
    * This client behaves like a browser-client in terms of
    * cookie handling.<br>
    *
    @author Mathias Richter
    */
    public class CasClient
    {
      
       
    public static Logger LOG = Logger.getLogger( CasClient.class  );

       
    public static final String LOGIN_URL_PART = "login";
       
    public static final String SERVICE_VALIDATE_URL_PART = "serviceValidate";
       
    public static final String TICKET_BEGIN = "ticket=";
       
    private static final String LT_BEGIN = "name="lt" value="";
       public static final String CAS_USER_BEGIN = "<cas:user>";
       
    public static final String CAS_USER_END = "</cas:user>";
      
       
    private HttpClient fClient;
       
    private String fCasUrl;
      
       
    /**
        * Construct a new CasClient.
        *
        * 
    @param casUrl The base URL of the CAS service to be used.
        
    */
       
    public CasClient( String casBaseUrl )
       {
           
    thisnew HttpClient(), casBaseUrl );
       }
      
       
    /**
        * Construct a new CasClient which uses the specified HttpClient
        * for its HTTP calls.
        *
        * 
    @param client
        * 
    @param casBaseUrl
        
    */
       
    public CasClient( HttpClient client, String casBaseUrl )
       {
           fClient 
    = client;
           fCasUrl 
    = casBaseUrl;
       }
      
       
    /**
        * Authenticate the specified username with the specified password.
        * This will not yield any ticket, as no service is authenticated
        * against. This wil just set the CAS cookie in this client upon
        * successful authentication.
        *
        * 
    @param username
        * 
    @param password
        
    */
       
    public void authenticate( String username, String password )
       {
           authenticate( 
    null, username, password );
       }
      
       
    /**
        * Validate the specified service ticket against the specified service.
        * If the ticket is valid, this will yield the clear text user name
        * of the autenticated user.<br>
        * Note that each service ticket issued by CAS can be used exactly once
        * to validate.
        *
        * 
    @param serviceUrl
        * 
    @param serviceTicket
        *
        * 
    @return Clear text username of the authenticated user.
        
    */
       
    public String validate( String serviceUrl, String serviceTicket )
       {
           String result 
    = null;
           PostMethod method 
    = new PostMethod( fCasUrl + SERVICE_VALIDATE_URL_PART );
           method.setParameter( 
    "service", serviceUrl );
           method.setParameter( 
    "ticket", serviceTicket );
           
    try
           {
               
    int statusCode = fClient.executeMethod(method);
               
    if (statusCode != HttpStatus.SC_OK)
               {
                   LOG.error( 
    "Could not validate: " + method.getStatusLine() );
                   method.releaseConnection();
               } 
    else
               {   
                   result 
    = extractUser( new String( method.getResponseBody() ) );
               }
           } 
    catch ( Exception x )
           {
               LOG.error( 
    "Could not validate: " + x.toString () );
               x.printStackTrace();
           }
           method.releaseConnection();
           
    return result;
       }
      
       
    /**
        * Authenticate the specified user with the specified password against the
        * specified service.
        *
        * 
    @param serviceUrl May be null. If a url is specified, the authentication will happen against this service, yielding a service ticket which can be validated.
        * 
    @param username
        * 
    @param password
        * 
    @return A valid service ticket, if and only if the specified service URL is not null.
        
    */
       
    public String authenticate( String serviceUrl, String username, String password )
       {
           String lt 
    = getLt( serviceUrl );
           
    if ( lt == null )
           {
               LOG.error( 
    "Cannot retrieve LT from CAS. Aborting authentication for '" + username + "'" );
               
    return null;
           }
           String result 
    = null;
           PostMethod method 
    = new PostMethod( fCasUrl + LOGIN_URL_PART );
           
    if ( serviceUrl != null ) // optional
               method.setParameter( "service", serviceUrl );
           method.setParameter( 
    "_eventId""submit" );
           method.setParameter(
    "username", username );
           method.setParameter(
    "password", password );
           method.setParameter(
    "lt", lt );
           method.setParameter( 
    "gateway""true" );
           
    try
           {
               fClient.executeMethod(method);
               
    if ( serviceUrl == null )
               {
                   
    if ( extractLt( new String( method.getResponseBody() ) ) != null ) // if CAS does not return a login page with an LT authentication was successful
                   {
                       LOG.error( 
    "Authentication for '" +  username + "' unsuccessful" );
                       
    if ( LOG.isDebugEnabled() )
                           LOG.debug( 
    "Authentication for '" + username + "' unsuccessful." );
                   } 
    else
                   {
                       
    if ( LOG.isDebugEnabled() )
                           LOG.debug( 
    "Authentication for '" + username + "' unsuccessful." );
                   }
               } 
    else
               {
                   Header h 
    = method.getResponseHeader( "Location" );
                   
    if ( h != null )
                       result 
    = extractServiceTicket( h.getValue() );
                   
    if ( result == null )
                       LOG.error( 
    "Authentication for '" + username + "' unsuccessful." );
               }
           } 
    catch ( Exception x )
           {
               LOG.error( 
    "Could not authenticate'" + username + "':" + x.toString () );
           }
           method.releaseConnection();
           
    return result;
       }
      
       
    /**
        * Helper method to extract the user name from a "service validate" call to CAS.
        *
        * 
    @param data Response data.
        * 
    @return The clear text username, if it could be extracted, null otherwise.
        
    */
       
    protected String extractUser( String data )
       {
           String user 
    = null;
           
    int start = data.indexOf( CAS_USER_BEGIN  );
           
    if ( start >= 0 )
           {
               start 
    += CAS_USER_BEGIN.length();
               
    int end = data.indexOf( CAS_USER_END );
               
    if ( end > start )
                   user 
    = data.substring( start, end );
               
    else
                   LOG.warn( 
    "Could not extract username from CAS validation response. Raw data is: '" + data + "'" );
           } 
    else
           {
               LOG.warn( 
    "Could not extract username from CAS validation response. Raw data is: '" + data + "'" );
           }
           
    return user;
       }
      
       
    /**
        * Helper method to extract the service ticket from a login call to CAS.
        *
        * 
    @param data Response data.
        * 
    @return The service ticket, if it could be extracted, null otherwise.
        
    */
       
    protected String extractServiceTicket( String data )
       {
           String serviceTicket 
    = null;
           
    int start = data.indexOf( TICKET_BEGIN  );
           
    if ( start > 0 )
           {
               start 
    += TICKET_BEGIN.length();
               serviceTicket 
    = data.substring( start );
           }
           
    return serviceTicket;
       }
      
       
    /**
        * Helper method to extract the LT from a login form from CAS.
        *
        * 
    @param data Response data.
        * 
    @return The LT, if it could be extracted, null otherwise.
        
    */
       
    protected String extractLt( String data )
       {
           String token 
    = null;
           
    int start = data.indexOf( LT_BEGIN  );
           
    if ( start < 0 )
           {
               LOG.error( 
    "Could not obtain LT token from CAS: LT Token not found in response." );
           } 
    else
           {
               start 
    += LT_BEGIN.length();
               
    int end = data.indexOf( """, start );
               token = data.substring( start, end );
           }       
           
    return token;
       }
      
       
    /**
        * This method requests the original login form from CAS.
        * This form contains an LT, an initial token that must be
        * presented to CAS upon sending it an authentication request
        * with credentials.<br>
        * If a service URL is provided (which is optional), this method
        * will post the URL such that CAS authenticates against the
        * specified service when a subsequent authentication request is
        * sent.
        *
        * 
    @param serviceUrl
        * 
    @return The LT token if it could be extracted from the CAS response.
        
    */
       
    protected String getLt( String serviceUrl )
       {
           String lt 
    = null;
           HttpMethod method 
    = null;
           
    if ( serviceUrl == null )
               method 
    = new GetMethod( fCasUrl + LOGIN_URL_PART );
           
    else
           {
               method 
    = new PostMethod( fCasUrl + LOGIN_URL_PART );
               ( ( PostMethod ) method ).setParameter( 
    "service", serviceUrl );
           }
           
    try
           {
               
    int statusCode = fClient.executeMethod(method);
               
    if (statusCode != HttpStatus.SC_OK)
               {
                   LOG.error( 
    "Could not obtain LT token from CAS: " + method.getStatusLine() );
                   method.releaseConnection();
               } 
    else
               {
                   Object o 
    = method.getResponseHeaders() ;
                   
    return extractLt( new String( method.getResponseBody() ) );
               }
           } 
    catch ( Exception x )
           {
               LOG.error( 
    "Could not obtain LT token from CAS: " + x.toString () );
           }
           method.releaseConnection();
           
    return lt;
       }
      
    }

    posted @ 2010-07-15 17:59 BlakeSu 閱讀(416) | 評論 (0)編輯 收藏

    java取文件換行符

    System.getProperty("line.separator")

    posted @ 2010-06-30 15:45 BlakeSu 閱讀(311) | 評論 (0)編輯 收藏

    禁止瀏覽器緩存

    html
      <meta http-equiv="pragma" content="no-cache">
      
    <meta http-equiv="cache-control" content="no-cache">
      
    <meta http-equiv="expires" content="0">


    servlet
              response.setHeader("pragma","no-cache");
              response.setHeader(
    "cache-control","no-cache");
              response.setDateHeader(
    "expires"0);


    posted @ 2010-06-25 09:06 BlakeSu 閱讀(253) | 評論 (0)編輯 收藏

    frame 中跨域訪問cookie(java)

    response.addHeader("P3P","CP=CAO PSA OUR");

    posted @ 2010-06-25 09:04 BlakeSu 閱讀(415) | 評論 (0)編輯 收藏

    vim的復制粘貼小結

    原文地址 http://lsong17.spaces.live.com/blog/cns!556C21919D77FB59!603.trak


    用vim這么久 了,始終也不知道怎么在vim中使用系統粘貼板,通常要在網上復制一段代碼都是先gedit打開文件,中鍵粘貼后關閉,然后再用vim打開編輯,真的不 爽;上次論壇上有人問到了怎么在vim中使用系統粘貼板,印象里回復很多,有好幾頁的回復卻沒有解決問題,今天實在受不了了又在網上找辦法,竟意外地找到 了,貼出來分享一下。

    如果只是想使用系統粘貼板的話直接在輸入模式按Shift+Inset就可以了,下面講一下vim的粘貼板的基礎知識,有興趣的可以看看, 應該會有所收獲的。
    vim幫助文檔里與粘貼板有關的內容如下:

    1. vim有12個粘貼板,分別是0、1、2、...、9、a、“、+;用:reg命令可以查看各個粘貼板里的內容。在vim中簡單用y只是復制到 “(雙引號)粘貼板里,同樣用p粘貼的也是這個粘貼板里的內容;

    2. 要將vim的內容復制到某個粘貼板,需要退出編輯模式,進入正常模式后,選擇要復制的內容,然后按"Ny完成復制,其中N為粘 貼板號(注意是按一下雙引號然后按粘貼板號最后按y),例如要把內容復制到粘貼板a,選中內容后按"ay就可以了,有兩點需要說明一下:
      • “號粘貼板(臨時粘貼板)比較特殊,直接按y就復制到這個粘貼板中了,直接按p就粘貼這個粘貼板中的內容;
      • +號粘貼板是系統粘貼板,用"+y將內容復制到該粘貼板后可以使用Ctrl+V將其粘貼到其他文檔(如firefox、gedit) 中,同理,要把在其他地方用Ctrl+C或右鍵復制的內容復制到vim中,需要在正常模式下按"+p;

    3. 要將vim某個粘貼板里的內容粘貼進來,需要退出編輯模式,在正常模式按"Np,其中N為粘貼板號,如上所述,可以按"5p將 5號粘貼板里的內容粘貼進來,也可以按"+p將系統全局粘貼板里的內容粘貼進來。

    注意:在我這里,只有vim.gtk或vim.gnome才能使用系統全局粘貼板,默認的 vim.basic看不到+號寄存器。

    posted @ 2010-06-18 14:21 BlakeSu 閱讀(264) | 評論 (0)編輯 收藏

    Linux下mail使用技巧

    登錄LINUX系統后,經常會看到"you have mail",卻苦于不知道如何查看,相信菜鳥們都遇到過,偶在網上用“linux mail"找了很久,但大都是介紹mail服務器的,黃天總算沒負有心人,在洪恩在找到一篇介紹基礎的文章,不敢獨享。
     
    系統提供了用戶 之間通信的郵件系統,當用戶打開終端注冊登錄時發現系統給出如下信息:
        you have mail.

        這時用戶可通過鍵入mail命令讀取信件:

        $ mail

        mail程序將逐個顯示用戶的信件,并依照時間順序,顯示最新的信件。每顯示一段信件,mail都詢問用戶是否要對該信件作些處理。若用戶回答d,則表示 刪除信件;若僅按回車鍵,表示對信件不作任何改動(信件仍舊保存,下次還可讀這一信件);若回答p,則要求重復顯示信件;s filename表示要把信件存入所命名的文件;若回答q,表示要從mail退出。

        我們在本章的第一個例子中演示了如何寫一封信,作為練習,你可送信件給自己,然后鍵入mail讀取自己發的信件,看看會有什么效果。(發信給自己是一種設 置備忘錄的方法)。

        $mail frank 給自己寫信

        subject: test

        This is a mail test

        CRL-d

        EOT

        $

        $mail 查看信件

        “/var/spool/mail/frank:”1 message 1 new

        >Nfrank@xteam.xteamlinux.comThu Mar 25 11:00 13/403 “test”

        &

        Message 1:

        From frank Thu Mar 25 11:00:25 1999/3/25

        Received: (fromfrank@localhost)

        by xteam.xteamlinux.com(8.8.4/8.8.4)

        id LAA05170 for frank;Thu 25 Mar 1999 11:00:25 GMT

        Date: Thu,25 Mar 1999 11:00:25 GMT

        From:RHS Linux User <frank@xteam.xteamlinux.com>

        Message-Id:<199903251142.LAA05170@xteam.xteamlinux.com>

        To:frank@xteam.xteamlinux.com

        Subject:test

        Status:R

        This is a mail test

        &

        mail命令還有很多其它用法,例如發送事先準備好的信件,或一次送信給若干人。還可以用其它方法送信件。

    posted @ 2010-06-18 11:05 BlakeSu 閱讀(190) | 評論 (0)編輯 收藏

    Mysql中limit的用法詳解

        Mysql中limit的用法:在我們使用查詢語句的時候,經常要返回前幾條或者中間某幾行數據,這個時候怎么辦呢?
      不用擔心,mysql已經為我們提供了這樣一個功能。

      SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset

    LIMIT 子句可以被用于強制 SELECT 語句返回指定的記錄數。LIMIT 接受一個或兩個數字參數。參數必須是一個整數常量。
      如果給定兩個參數,第一個參數指定第一個返回記錄行的偏移量,第二個參數指定返回記錄行的最大數目。初始記錄行的偏移量是 0(而不是 1):
      為了與 PostgreSQL 兼容,MySQL 也支持句法: LIMIT # OFFSET #。

    mysql> SELECT * FROM table LIMIT 5,10; // 檢索記錄行 6-15

    //為了檢索從某一個偏移量到記錄集的結束所有的記錄行,可以指定第二個參數為 -1:

    mysql> SELECT * FROM table LIMIT 95,-1; // 檢索記錄行 96-last.

    //如果只給定一個參數,它表示返回最大的記錄行數目:

    mysql> SELECT * FROM table LIMIT 5; //檢索前 5 個記錄行

    //換句話說,LIMIT n 等價于 LIMIT 0,n。

    注意limit 10和limit 9,1的不同:

    例如:

    1.Select * From cyclopedia Where ID>=(
        Select Max(ID) From (
          Select ID From cyclopedia Order By ID limit 90001
        ) As tmp
      ) limit 100;

    2.Select * From cyclopedia Where ID>=(
        Select Max(ID) From (
          Select ID From cyclopedia Order By ID limit 90000,1
        ) As tmp
      ) limit 100;

     

        第1句是先取了前90001條記錄,取其中最大一個ID值作為起始標識,然后利用它可以快速定位下100條記錄

    第2句擇是僅僅取90000條記錄后1條,然后取ID值作起始標識定位下100條記錄

    第1句執行結果.100 rows in set (0.23) sec

    第2句執行結果.100 rows in set (0.19) sec

    其實第2句完全可以簡化成:
        Select * From cyclopedia Where ID>=(
       Select ID From cyclopedia limit 90000,1
    )limit 100;

    直接利用第90000條記錄的ID,不用經過Max運算,這樣做理論上效率因該高一些,但在實際使用中幾乎看不到效果,
       因為本身定位ID返回的就是1條記錄,Max幾乎不用運作就能得到結果,但這樣寫更清淅明朗,省去了畫蛇那一足.


    Select Top 100 * From cyclopedia Where ID>=(
    Select Top 90001 Max(ID) From (
    Select ID From cyclopedia Order By ID
    ) As tmp
    )

    但不管是實現方式是存貯過程還是直接代碼中,瓶頸始終在于MS-SQL的TOP總是要返回前N個記錄,這種情況在數據量不大時感受不深,
       但如果成百上千萬,效率肯定會低下的.相比之下MySQL的limit就有優勢的多,執行:


    Select ID From cyclopedia limit 90000
    Select ID From cyclopedia limit 90000,1

    的結果分別是:


    90000 rows in set (0.36) sec
    1 row in set (0.06) sec

    而MS-SQL只能用Select Top 90000 ID From cyclopedia 執行時間是390ms,執行同樣的操作時間也不及MySQL的360ms.

    limit的offset(偏移量)用于記錄較多的時候,記錄較少時,偏移offset較小,直接使用limit較優。offset越大,后者越優。
     

    1、offset比較小的時候。

    select * from yanxue8_visit limit 10,10

    多次運行,時間保持在0.0004-0.0005之間


    Select * From yanxue8_visit Where vid >=(
      Select vid From yanxue8_visit Order By vid limit 10,1
    ) limit 10

    多次運行,時間保持在0.0005-0.0006之間,主要是0.0006

    結論:偏移offset較小的時候,直接使用limit較優。這個顯示是子查詢的原因。

    2、offset大的時候。

    select * from yanxue8_visit limit 10000,10

    多次運行,時間保持在0.0187左右

    Select * From yanxue8_visit Where vid >=(
      Select vid From yanxue8_visit Order By vid limit 10000,1
    ) limit 10

    多次運行,時間保持在0.0061左右,只有前者的1/3。可以預先offset越大,后者越優。

    mysql> SELECT * FROM table LIMIT 95,-1; // 檢索記錄行 96-last.

    //如果只給定一個參數,它表示返回最大的記錄行數目.

    posted @ 2010-06-02 14:43 BlakeSu 閱讀(451) | 評論 (0)編輯 收藏

    枚舉類型enum示例




    public enum OrderStatus {
        A(
    1), B(2), C(3), D(4), F(5), INCOMPLETE(6);
        
        
    private final int value;
        
    /**
         * Constructor.
         
    */
        
    private OrderStatus(int value) {
            
    this.value = value;
        }
        
        
    /**
         * Get the value.
         * 
    @return the value
         
    */
        
    public int getValue() {
            
    return value;
        }

    }


    posted @ 2010-06-02 13:33 BlakeSu 閱讀(147) | 評論 (0)編輯 收藏

    JS try.....catch的使用

    <script language="javascript">
    try
    {
    throw new Error(10,"asdasdasd")
    }
    catch (e)
    {
    alert(e.message);
    alert(e.description)
    alert(e.number)
    alert(e.name)
    throw new Error(10,"asdasdasd")
    }

    </script>  

    在JavaScript可以使用try...catch來進行異常處理。例如:  

     

    try {
    foo.bar();
    } catch (e) {
    alert(e.name + ": " + e.message);
    }

    目前我們可能得到的系統異常主要包含以下6種:

    • EvalError: raised when an error occurs executing code in eval()  
    • RangeError: raised when a numeric variable or parameter is outside of its valid range  
    • ReferenceError: raised when de-referencing an invalid reference  
    • SyntaxError: raised when a syntax error occurs while parsing code in eval()  
    • TypeError: raised when a variable or parameter is not a valid type  
    • URIError: raised when encodeURI() or decodeURI() are passed invalid parameters  

    上面的六種異常對象都繼承自Error對象。他們都支持以下兩種構造方法:

     

    new Error();
    new Error("異常信息");

    手工拋出異常的方法如下:

     

    try {
    throw new Error("Whoops!");
    } catch (e) {
    alert(e.name + ": " + e.message);
    }

    如要判斷異常信息的類型,可在catch中進行判斷:

     

    try {
    foo.bar();
    } catch (e) {
    if (e instanceof EvalError) {
       alert(e.name + ":" + e.message);
    }
    else if (e instanceof RangeError) {
       alert(e.name + ": " + e.message);
    }
    // etc
    }

    Error具有下面一些主要屬性:

    • description: 錯誤描述 (僅IE可用).  
    • fileName: 出錯的文件名 (僅Mozilla可用).  
    • lineNumber: 出錯的行數 (僅Mozilla可用).  
    • message: 錯誤信息 (在IE下同description)  
    • name: 錯誤類型.  
    • number: 錯誤代碼 (僅IE可用).  
    • stack: 像Java中的Stack Trace一樣的錯誤堆棧信息 (僅Mozilla可用).  

    因此為了更好的了解錯誤信息我們可以將catch部分改為如下形式:  

     

    try {
    foo.bar();
    } catch (e) {
    if (browserType != BROWSER_IE) {                            
       alert("name: " + e.name +
        "message: " + e.message +
        "lineNumber: " + e.lineNumber +
        "fileName: " + e.fileName +
        "stack: " + e.stack);        
    }
    else {                    
       alert("name: " + e.name +     
        "errorNumber: " + (e.number & 0xFFFF ) +
        "message: " + e.message");        
    }
    }

    JavaScript中的throw命令事實上可以拋出任何對象,并且我們可以在catch接受到此對象。例 如:

     

    try {
    throw new Date(); // 拋出當前時間對象
    } catch (e) {
    alert(e.toLocaleString()); // 使用本地格式顯示當前時間
    }

    posted @ 2010-06-02 10:38 BlakeSu 閱讀(330) | 評論 (0)編輯 收藏

    深拷貝

    import java.io.*;

    public class ObjectCloner
    {
       
    // so that nobody can accidentally create an ObjectCloner object
       private ObjectCloner(){}
       
    // returns a deep copy of an object
       static public Object deepCopy(Object oldObj) throws Exception
       {
          ObjectOutputStream oos 
    = null;
          ObjectInputStream ois 
    = null;
          
    try
          {
             ByteArrayOutputStream bos 
    = new ByteArrayOutputStream(); 
             oos 
    = new ObjectOutputStream(bos); 
             
    // serialize and pass the object
             oos.writeObject(oldObj);   
             oos.flush();               
             ByteArrayInputStream bin 
    = new ByteArrayInputStream(bos.toByteArray()); 
             ois 
    = new ObjectInputStream(bin);
             
    // return the new object
             return ois.readObject();
          }
          
    catch(Exception e)
          {
             System.out.println(
    "Exception in ObjectCloner = " + e);
             
    throw(e);
          }
          
    finally
          {
             oos.close();
             ois.close();
          }
       }
       
    }

    posted @ 2010-05-25 09:30 BlakeSu 閱讀(176) | 評論 (0)編輯 收藏

    mysql convert int to char/varchar

    select cast(1 as char)

    char 不能換成varchar,否則會報錯。

    posted @ 2010-05-12 17:12 BlakeSu 閱讀(2894) | 評論 (0)編輯 收藏

    How to check Linux distribution and version?

    If u are on an unknown server and keen to know it’s linux distribution info, you can check the linux distribution info by just a single command (eg. version, codename, etc). Just tested this command in UBuntu and CentOS, both return as what i expected. :)

    To check linux distribution and version, follow the steps below:-

    • Start your terminal and enter the command below to show your the linux distribution info:-
      $ cat /etc/*-release
    • Here’s my result in one of my my Ubuntu box:-
      $ cat /etc/*-release
      DISTRIB_ID=Ubuntu
      DISTRIB_RELEASE=9.10
      DISTRIB_CODENAME=karmic
      DISTRIB_DESCRIPTION="Ubuntu 9.10"

      Cool right!

    posted @ 2010-05-08 13:29 BlakeSu 閱讀(684) | 評論 (0)編輯 收藏

    Eclipse集成windows資源管理器簡單方法

    Run-->External Tools-->External tools configurations
    new 一個 program
    location 里面填 :C:\WINDOWS\explorer.exe
    Arguments 里面填: ${container_loc}
    點擊 Run

    posted @ 2010-05-08 08:40 BlakeSu 閱讀(262) | 評論 (0)編輯 收藏

    commons lang 比較有用的類

    ArrayUtils                 //簡化數組的操作
    LocaleUtils
    SerializationUtils
    StringEscapeUtils
    StringUtils
    SystemUtils
    Validate                   //輸入參數驗證
    NestableException
    NestableRuntimeException
    StopWatch          //秒表類

    posted @ 2010-04-26 10:16 BlakeSu 閱讀(207) | 評論 (0)編輯 收藏

    主站蜘蛛池模板: 国产亚洲美女精品久久久| 日韩一级片免费观看| 亚洲午夜久久久影院伊人| 全免费a级毛片免费看无码| 免费观看男人吊女人视频| 无码天堂亚洲国产AV| 亚洲国产成人综合| 亚洲av日韩av不卡在线观看| 亚洲成网777777国产精品| 性盈盈影院免费视频观看在线一区| 免费在线观看污网站| 国产精品99精品久久免费| 美女免费视频一区二区三区| 亚洲精品午夜国产va久久| 亚洲视频一区二区在线观看| 亚洲AV无码一区二区三区DV| 亚洲无码精品浪潮| 无码国产亚洲日韩国精品视频一区二区三区| 国产92成人精品视频免费| 一级特黄a大片免费| 亚洲av无码av在线播放| 亚洲一区二区三区深夜天堂| 少妇中文字幕乱码亚洲影视| 亚洲国产美女精品久久久久∴| 成人无码a级毛片免费| 国产亚洲精品免费| 亚洲成a人无码亚洲成www牛牛| 亚洲国产精品一区二区第四页 | 国产真实伦在线视频免费观看| 人成电影网在线观看免费| 精品久久久久亚洲| 在线观看亚洲免费视频| 亚洲国产aⅴ成人精品无吗| 亚洲欧美中文日韩视频| 亚洲成aⅴ人片久青草影院按摩| 久久91亚洲人成电影网站| 亚洲女同成av人片在线观看| 亚洲成a人片77777kkkk| 亚洲精品无码久久久久去q | 亚洲欧洲日产国码久在线观看 | 国产99久久亚洲综合精品|