DEADSOFTWARE

Fix string constants in modules
[mp3cc.git] / mps / src / S.java
1 import java.io.*;
2 import javax.microedition.lcdui.*;
3
4 public class S
5 {
6 public static int parseInt(String s)
7 {
8 try
9 {
10 return Integer.parseInt(s);
11 }
12 catch (Exception e)
13 {
14 return 0;
15 }
16 };
17
18 // getChar
19 public static int gc(String s, int pos)
20 {
21 try
22 {
23 return s.charAt(pos);
24 }
25 catch (Exception e)
26 {
27 return '\000';
28 }
29 }
30
31 // setChar
32 public static String gc(String s, int c, int pos)
33 {
34 try
35 {
36 StringBuffer sb = new StringBuffer(s);
37 sb.setCharAt(pos, (char)c);
38 return sb.toString();
39 }
40 catch (Exception e)
41 {
42 return s;
43 }
44 }
45
46 // openResource
47 public static InputStream r(String resourceName)
48 {
49 try
50 {
51 return FW.fw.getClass().getResourceAsStream(resourceName);
52 } catch(Exception e)
53 {
54 return null;
55 }
56 }
57
58 // closeResource
59 public static void r(InputStream is)
60 {
61 try
62 {
63 is.close();
64 } catch (Exception e)
65 {
66 return;
67 }
68 }
69
70 // readNextByte
71 public static int rb(InputStream is)
72 {
73 try
74 {
75 byte []b = new byte[2];
76 // is.read(b, 0, 1);
77 //
78 // return b[0];
79 // j-a-s-d: fix
80 if (is.read(b, 0, 1) == -1)
81 return 1000;
82 else
83 return b[0];
84 } catch (Exception e)
85 {
86 return 1000; //ERROR konstanta
87 }
88 }
89
90 // readNextLine
91 public static String nl(InputStream is)
92 {
93 StringBuffer retVal = new StringBuffer();
94 try
95 {
96 byte []b = new byte[2];
97 boolean lineStarted = false;
98
99 do
100 {
101 is.read(b, 0, 1);
102
103 if ((b[0] != '\n') && (b[0] != '\r'))
104 {
105 retVal.append((char)b[0]);
106 lineStarted = true;
107 }
108 else
109 {
110 if (lineStarted)
111 break;
112 }
113 } while(true);
114
115 }
116 catch(Exception e)
117 {
118 return retVal.toString();
119 }
120
121 return retVal.toString();
122 }
123
124 public static Image InternalImageFromImage(Image img, int x, int y, int cx, int cy)
125 {
126 Image newImage = Image.createImage(cx, cy);
127 newImage.getGraphics().drawImage(img, -x, -y, Graphics.TOP|Graphics.LEFT);
128 return newImage;
129 }
130 /* imageFromImage */
131 public static Image ii(Image img, int x, int y, int cx, int cy)
132 {
133 try
134 { // j-a-s-d: this is to avoid AV false alarms
135 return InternalImageFromImage(img, x, y, cx, cy);
136 }
137 catch (Exception e)
138 {
139 return Image.createImage(1, 1);
140 }
141 }
142
143 /* imageFromCanvas */
144 public static Image ii(int x, int y, int cx, int cy)
145 {
146 return ii(M.I, x, y, cx, cy);
147 }
148
149 /* imageFromBuffer*/
150 public static Image ii(String buf, int length)
151 {
152 try
153 {
154 return Image.createImage(buf.getBytes(), 0, length);
155 }
156 catch (Exception e)
157 {
158 return Image.createImage(1,1);
159 }
160 }
161
162 };