KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > exceptions > CheckIssue


1 /*
2  * CheckIssue.java
3  *
4  * Created on January 16, 2007, 1:10 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.exceptions;
11
12 import java.io.DataInputStream JavaDoc;
13 import java.io.DataOutputStream JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.net.HttpURLConnection JavaDoc;
16 import org.netbeans.modules.exceptions.settings.ExceptionsRepos;
17
18 /**
19  *
20  * @author jindra
21  */

22 public class CheckIssue {
23     private static final String JavaDoc uri = ExceptionsRepos.uri_server + "CheckingServlet"; // NOI18N
24
/** Creates a new instance of CheckIssue */
25     public CheckIssue() {
26     }
27     
28     /**
29      * @return -1 if an issue was not found otherwise it returns issueId
30      */

31     public int exists(Throwable JavaDoc thrown) throws IOException JavaDoc{
32         HttpURLConnection JavaDoc conn = Sender.getHttpConnection(uri);
33         int result=-1;
34         if (conn != null){
35             DataOutputStream JavaDoc outStr = new DataOutputStream JavaDoc(conn.getOutputStream());
36             outStr.writeInt(countHash(thrown.getStackTrace()));
37             outStr.close();
38             DataInputStream JavaDoc inputStr = new DataInputStream JavaDoc(conn.getInputStream());
39             result = inputStr.readInt();
40             inputStr.close();
41             conn.disconnect();
42         }
43         return result;
44     }
45     
46     public int countHash(StackTraceElement JavaDoc[] throwable){
47         String JavaDoc str = throwable[0].toString();
48         for (int i = 1; i < throwable.length; i++) {
49             str = str.concat(throwable[i].toString());
50         }
51         int result = str.hashCode();
52         return result;
53     }
54     
55 }
56
57
58
Popular Tags