Ejemplo n.º 1
0
  private Image getImage(String str) throws IOException {
    String url = "http://" + controller.selectedCity.URL + "/cameras/images/" + str + ".jpg";
    System.out.println(url);
    InputStream iStrm = (InputStream) Connector.openInputStream(url);
    Image im = null;

    try {
      ByteArrayOutputStream bStrm = new ByteArrayOutputStream();

      int ch;
      while ((ch = iStrm.read()) != -1) bStrm.write(ch);

      // Place into image array
      byte imageData[] = bStrm.toByteArray();

      // Create the image from the byte array
      im = Image.createImage(imageData, 0, imageData.length);

    } finally {
      // Clean up
      if (iStrm != null) iStrm.close();
    }

    return (im == null ? null : im);
  }
Ejemplo n.º 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;
  }
Ejemplo n.º 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);
  }