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