Rev 255 | 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 | |||
382 | ligi | 22 | public final static String[] combine_str_arr(String[] arr1 , String[] arr2) |
23 | { |
||
24 | String[] res=new String[arr1.length+arr2.length]; |
||
25 | for (int pos=0;pos<res.length;pos++) |
||
26 | if (pos<arr1.length) |
||
27 | res[pos]=arr1[pos]; |
||
28 | else |
||
29 | res[pos]=arr2[pos-arr1.length]; |
||
30 | return res; |
||
31 | } |
||
32 | |||
252 | ligi | 33 | public final static String pound_progress(int val,int max) |
34 | { |
||
35 | String res="" + (val+1) + "/" + max + " |"; |
||
36 | for (int i=0;i<max;i++) |
||
37 | res+=(i<(val+1))?"#":"_"; |
||
38 | res+="|"; |
||
39 | return res; |
||
40 | } |
||
41 | |||
42 | |||
43 | |||
223 | ligi | 44 | public final static String ip_str(int[] ip,boolean with_zeroes) |
206 | ligi | 45 | { |
46 | if(with_zeroes) |
||
47 | 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]) ; |
||
48 | else |
||
49 | return ip[0]+"."+ip[1]+"."+ip[2]+"."+ip[3]+":"+ip[4]; |
||
50 | |||
51 | } |
||
52 | |||
255 | ligi | 53 | |
54 | |||
55 | |||
56 | |||
57 | public final static String get_http_string(String url) |
||
58 | { |
||
59 | |||
60 | try { |
||
61 | |||
62 | InputStream stream = null; |
||
63 | StringBuffer buff = new StringBuffer(); |
||
64 | StreamConnection conn=null; |
||
65 | |||
66 | System.out.println("starting conn"); |
||
67 | conn = (StreamConnection)Connector.open(url); |
||
68 | stream = conn.openInputStream(); |
||
69 | int ch; |
||
70 | |||
71 | while((ch = stream.read()) != -1) |
||
72 | buff.append((char) ch); |
||
73 | |||
74 | if(stream != null) |
||
75 | stream.close(); |
||
76 | |||
77 | if(conn != null) |
||
78 | conn.close(); |
||
79 | |||
80 | |||
81 | return buff.toString(); |
||
82 | |||
83 | } |
||
84 | catch ( Exception e) |
||
85 | { |
||
86 | return "err"; |
||
87 | } |
||
88 | |||
89 | } |
||
90 | |||
91 | |||
92 | |||
93 | |||
94 | |||
223 | ligi | 95 | public final static int pow(int val,int pow) |
206 | ligi | 96 | { |
97 | int res=1; |
||
98 | |||
99 | for (int p=0;p<pow;p++) |
||
100 | res*=val; |
||
101 | |||
102 | return res; |
||
103 | } |
||
104 | |||
105 | |||
255 | ligi | 106 | |
107 | |||
108 | |||
242 | ligi | 109 | public final static String[] split_str(String str,String sep) |
110 | { |
||
111 | |||
112 | Vector nodes = new Vector(); |
||
113 | |||
114 | // Parse nodes into vector |
||
115 | int index = str.indexOf(sep); |
||
116 | while(index>=0) { |
||
117 | nodes.addElement( str.substring(0, index) ); |
||
118 | str = str.substring(index+sep.length()); |
||
119 | index = str.indexOf(sep); |
||
120 | } |
||
121 | // add last element |
||
122 | nodes.addElement( str ); |
||
123 | |||
124 | // Create splitted string array |
||
125 | String[] result = new String[ nodes.size() ]; |
||
126 | if( nodes.size()>0 ) { |
||
127 | for(int loop=0; loop<nodes.size(); loop++) |
||
128 | { |
||
129 | result[loop] = (String)nodes.elementAt(loop); |
||
130 | System.out.println(result[loop]); |
||
131 | } |
||
132 | |||
133 | } |
||
134 | |||
135 | return result; |
||
136 | } |
||
137 | |||
138 | |||
139 | |||
223 | ligi | 140 | public final static int mod_decimal(int val,int mod_power,int modder,int setter,int clipper) |
206 | ligi | 141 | { |
142 | |||
143 | int res=0; |
||
144 | |||
145 | for (int power=0;power<4;power++) |
||
146 | { |
||
147 | |||
148 | int act_digit=(val/pow(10,power))%10; |
||
149 | |||
150 | int new_digit=act_digit; |
||
151 | if (power==mod_power) |
||
152 | { |
||
153 | if (setter!=-1) |
||
154 | new_digit=setter; |
||
155 | |||
156 | new_digit+=modder; |
||
157 | |||
158 | if(new_digit<0) |
||
159 | new_digit=0; |
||
160 | |||
161 | if(new_digit>clipper) |
||
162 | new_digit=clipper; |
||
163 | |||
164 | } |
||
165 | |||
166 | // new_digit=1; |
||
167 | res+=new_digit*pow(10,power); |
||
168 | } |
||
169 | |||
170 | |||
171 | return res; |
||
172 | |||
173 | |||
174 | } |
||
175 | |||
176 | } |