Example #1
0
 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;
 }
Example #2
0
  // #sijapp cond.if (protocols_MRIM is "true") or (protocols_VK is "true") or (protocols_ICQ is
  // "true") #
  private byte[] read(InputStream in, int length) throws IOException {
    if (0 == length) {
      return null;
    }
    if (0 < length) {
      byte[] bytes = new byte[length];
      int readCount = 0;
      while (readCount < bytes.length) {
        int c = in.read(bytes, readCount, bytes.length - readCount);
        if (-1 == c) break;
        readCount += c;
      }
      return bytes;
    }

    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    for (int i = 0; i < 100 * 1024; ++i) {
      int ch = in.read();
      if (-1 == ch) break;
      bytes.write(ch);
    }
    byte[] content = bytes.toByteArray();
    bytes.close();
    return content;
  }
Example #3
0
  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);
  }