private Image getAvatar() { HttpConnection httemp = null; InputStream istemp = null; Image avatar = null; try { httemp = (HttpConnection) Connector.open(url); if (HttpConnection.HTTP_OK != httemp.getResponseCode()) { throw new IOException(); } istemp = httemp.openInputStream(); byte[] avatarBytes = read(istemp, (int) httemp.getLength()); // #sijapp cond.if modules_TRAFFIC is "true" # Traffic.getInstance().addInTraffic(avatarBytes.length); // #sijapp cond.end# avatar = javax.microedition.lcdui.Image.createImage(avatarBytes, 0, avatarBytes.length); avatarBytes = null; } catch (Exception e) { } try { httemp.close(); istemp.close(); } catch (Exception e) { } return avatar; }
private String getContent(String url) { HttpConnection httemp = null; InputStream istemp = null; String content = ""; try { httemp = (HttpConnection) Connector.open(url); httemp.setRequestProperty("Connection", "cl" + "ose"); if (HttpConnection.HTTP_OK != httemp.getResponseCode()) { throw new IOException(); } istemp = httemp.openInputStream(); int length = (int) httemp.getLength(); if (-1 != length) { byte[] bytes = new byte[length]; istemp.read(bytes); content = new String(bytes); } else { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); while (true) { int ch = istemp.read(); if (-1 == ch) break; bytes.write(ch); } content = new String(bytes.toByteArray()); bytes.close(); } } catch (Exception e) { content = "Error: " + e.getMessage(); } try { httemp.close(); istemp.close(); } catch (Exception e) { } return StringConvertor.removeCr(content); }
private void shadowConnection() { // Make the shadow connection for Nokia 6230 or other devices // if needed if (shadowConnectionActive) { return; } ContentConnection ctemp = null; DataInputStream istemp = null; try { shadowConnectionActive = true; ctemp = (ContentConnection) Connector.open("http://http.proxy.icq.com/hello"); istemp = ctemp.openDataInputStream(); } catch (Exception e) { } try { if (null != shadowConnection) { shadowConnection.close(); } } catch (Exception e) { } shadowConnection = ctemp; shadowConnectionActive = false; }