Rev 252 | Rev 382 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
255 | ligi | 1 | /*************************************************************** |
2 | * |
||
3 | * Helper functions for DUBwise |
||
4 | * |
||
5 | * Author: Marcus -LiGi- Bueschleb |
||
6 | * Mailto: LiGi @at@ LiGi DOTT de |
||
7 | * |
||
8 | ***************************************************************/ |
||
9 | |||
242 | ligi | 10 | import java.util.Vector; |
255 | ligi | 11 | import java.io.*; |
12 | import javax.microedition.io.*; |
||
242 | ligi | 13 | |
255 | ligi | 14 | |
15 | |||
223 | ligi | 16 | public final class DUBwiseHelper |
206 | ligi | 17 | { |
223 | ligi | 18 | public final static String ip_digit_zeroes(int digit) |
206 | ligi | 19 | { return "" + digit/100 + "" + (digit/10)%10 + "" + (digit)%10; } |
20 | |||
21 | |||
252 | ligi | 22 | public final static String pound_progress(int val,int max) |
23 | { |
||
24 | String res="" + (val+1) + "/" + max + " |"; |
||
25 | for (int i=0;i<max;i++) |
||
26 | res+=(i<(val+1))?"#":"_"; |
||
27 | res+="|"; |
||
28 | return res; |
||
29 | } |
||
30 | |||
31 | |||
32 | |||
223 | ligi | 33 | public final static String ip_str(int[] ip,boolean with_zeroes) |
206 | ligi | 34 | { |
35 | if(with_zeroes) |
||
36 | return ip_digit_zeroes(ip[0]) + "." +ip_digit_zeroes(ip[1]) + "."+ip_digit_zeroes(ip[2]) + "."+ip_digit_zeroes(ip[3]) + ":"+ip_digit_zeroes(ip[4]) ; |
||
37 | else |
||
38 | return ip[0]+"."+ip[1]+"."+ip[2]+"."+ip[3]+":"+ip[4]; |
||
39 | |||
40 | } |
||
41 | |||
255 | ligi | 42 | |
43 | |||
44 | |||
45 | |||
46 | public final static String get_http_string(String url) |
||
47 | { |
||
48 | |||
49 | try { |
||
50 | |||
51 | InputStream stream = null; |
||
52 | StringBuffer buff = new StringBuffer(); |
||
53 | StreamConnection conn=null; |
||
54 | |||
55 | System.out.println("starting conn"); |
||
56 | conn = (StreamConnection)Connector.open(url); |
||
57 | stream = conn.openInputStream(); |
||
58 | int ch; |
||
59 | |||
60 | while((ch = stream.read()) != -1) |
||
61 | buff.append((char) ch); |
||
62 | |||
63 | if(stream != null) |
||
64 | stream.close(); |
||
65 | |||
66 | if(conn != null) |
||
67 | conn.close(); |
||
68 | |||
69 | |||
70 | return buff.toString(); |
||
71 | |||
72 | } |
||
73 | catch ( Exception e) |
||
74 | { |
||
75 | return "err"; |
||
76 | } |
||
77 | |||
78 | } |
||
79 | |||
80 | |||
81 | |||
82 | |||
83 | |||
223 | ligi | 84 | public final static int pow(int val,int pow) |
206 | ligi | 85 | { |
86 | int res=1; |
||
87 | |||
88 | for (int p=0;p<pow;p++) |
||
89 | res*=val; |
||
90 | |||
91 | return res; |
||
92 | } |
||
93 | |||
94 | |||
255 | ligi | 95 | |
96 | |||
97 | |||
242 | ligi | 98 | public final static String[] split_str(String str,String sep) |
99 | { |
||
100 | |||
101 | Vector nodes = new Vector(); |
||
102 | |||
103 | // Parse nodes into vector |
||
104 | int index = str.indexOf(sep); |
||
105 | while(index>=0) { |
||
106 | nodes.addElement( str.substring(0, index) ); |
||
107 | str = str.substring(index+sep.length()); |
||
108 | index = str.indexOf(sep); |
||
109 | } |
||
110 | // add last element |
||
111 | nodes.addElement( str ); |
||
112 | |||
113 | // Create splitted string array |
||
114 | String[] result = new String[ nodes.size() ]; |
||
115 | if( nodes.size()>0 ) { |
||
116 | for(int loop=0; loop<nodes.size(); loop++) |
||
117 | { |
||
118 | result[loop] = (String)nodes.elementAt(loop); |
||
119 | System.out.println(result[loop]); |
||
120 | } |
||
121 | |||
122 | } |
||
123 | |||
124 | return result; |
||
125 | } |
||
126 | |||
127 | |||
128 | |||
223 | ligi | 129 | public final static int mod_decimal(int val,int mod_power,int modder,int setter,int clipper) |
206 | ligi | 130 | { |
131 | |||
132 | int res=0; |
||
133 | |||
134 | for (int power=0;power<4;power++) |
||
135 | { |
||
136 | |||
137 | int act_digit=(val/pow(10,power))%10; |
||
138 | |||
139 | int new_digit=act_digit; |
||
140 | if (power==mod_power) |
||
141 | { |
||
142 | if (setter!=-1) |
||
143 | new_digit=setter; |
||
144 | |||
145 | new_digit+=modder; |
||
146 | |||
147 | if(new_digit<0) |
||
148 | new_digit=0; |
||
149 | |||
150 | if(new_digit>clipper) |
||
151 | new_digit=clipper; |
||
152 | |||
153 | } |
||
154 | |||
155 | // new_digit=1; |
||
156 | res+=new_digit*pow(10,power); |
||
157 | } |
||
158 | |||
159 | |||
160 | return res; |
||
161 | |||
162 | |||
163 | } |
||
164 | |||
165 | } |