DEADSOFTWARE

Fix memory corruption when load library
[mp3cc.git] / mps / src / H.java
1 // The HTTP class for the MIDletPascal
2 import javax.microedition.io.*;
3 import java.io.*;
5 public class H
6 {
7 public HttpConnection c = null;
8 public OutputStream o = null;
9 public InputStream i = null;
11 // open a http connection
12 public int L(String url)
13 {
14 try
15 {
16 c = (HttpConnection)Connector.open(url);
17 o = c.openOutputStream();
18 return -1;
19 }
20 catch(Exception e)
21 {
22 c = null;
23 return 0;
24 }
25 }
27 // return true if the connection is open
28 public int L()
29 {
30 if (c != null)
31 return -1;
32 return 0;
33 }
35 // close the connection
36 public void c()
37 {
38 try
39 {
40 if (i != null)
41 {
42 i.close();
43 i = null;
44 }
45 if (o != null)
46 {
47 o.close();
48 o = null;
49 }
50 c.close();
51 c = null;
52 }
53 catch(Exception e)
54 {
55 c = null;
56 }
57 }
59 // add http header
60 public void L(String header, String value)
61 {
62 try
63 {
64 c.setRequestProperty(header, value);
65 }
66 catch(Exception e)
67 {}
68 }
70 // setRequestMethod :
71 // HEAD, POST, GET bi trebalo rijesiti kao string konstante
72 public void c(String method)
73 {
74 try
75 {
76 c.setRequestMethod(method);
77 }
78 catch(Exception e)
79 {}
80 }
82 // get header field
83 public String i(String header)
84 {
85 try
86 {
87 String value;
88 value = c.getHeaderField(header);
90 if (value == null)
91 value = "";
93 return value;
94 }
95 catch(Exception e)
96 {
97 return "";
98 }
99 }
101 // set message text
102 public int o(String message)
104 try
106 o.write(message.getBytes());
108 return -1;
110 catch(Exception e)
112 o = null;
113 return 0;
117 // getresponse code
118 // ovaj takodjer otvara konekciju i ceka dok se ne odgovori
119 public int o()
121 try
123 int code;
124 code = c.getResponseCode();
125 i = c.openInputStream();
126 return code;
128 catch(Exception e)
130 return -1;
134 // read the input data from the connection
135 public String j()
137 try
139 StringBuffer retval = new StringBuffer();
140 int c;
142 while ((c=i.read()) != -1)
144 retval.append((char)(char)c);
147 return retval.toString();
149 catch(Exception e)
151 return "";
155 };