Subversion Repositories Projects

Rev

Rev 252 | Rev 382 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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