Exemplo n.º 1
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);
  }
Exemplo n.º 2
0
 /**
  * replace and encode variables in a string object;
  *
  * @param src the source string containing variables to be replaced and encoded;
  * @param d the BizData object containing values;
  * @return
  * @throws UnsupportedEncodingException
  */
 public static final String replaceAndEncode(String src, BizData d)
     throws UnsupportedEncodingException {
   String temp = StringConvertor.replace(src, d);
   return StringConvertor.encode(temp);
 }