Exemple #1
0
  public InputStream AsyncDownloadDoc(String url, String action) {
    InputStream is = null;

    try {
      ConnectionFactory cf = new ConnectionFactory();
      cf.setConnectionTimeout(3333);
      cf.setTimeLimit(33000);
      ConnectionDescriptor cd = cf.getConnection(url);
      HttpConnection httpConn;
      httpConn = (HttpConnection) cd.getConnection();
      int response = httpConn.getResponseCode();
      if (response == HttpConnection.HTTP_OK) {
        is = httpConn.openInputStream();
        // httpConn.close();
      }
      // httpConn.close();
      // DebugLabel("RES: "+response,tsmanager);

    } catch (IOException e1) {
      // DebugLabel(error_code("unknown"), j.gparent);
    } catch (Exception e) {
      // c.DebugLabel(c.error_code("unknown"), j.gparent);
    }

    return is;
  }
  public static StreamConnection getConnectionForRequest(String url) {
    final ConnectionFactory connectionFactory = new ConnectionFactory();

    // Remove any transports that are not currently available.
    if (isTransportManaged == false) {
      for (int i = 0; i < availableTransportTypes.length; i++) {
        int transport = availableTransportTypes[i];
        if (!TransportInfo.isTransportTypeAvailable(transport)
            || !TransportInfo.hasSufficientCoverage(transport)) {
          Arrays.removeAt(availableTransportTypes, i);
        }
      }
      isTransportManaged = true;
    }

    connectionFactory.setPreferredTransportTypes(availableTransportTypes);

    final ConnectionDescriptor connectionDescriptor = connectionFactory.getConnection(url);
    StreamConnection connection = null;
    if (connectionDescriptor != null) {
      // connection suceeded
      int transportUsed = connectionDescriptor.getTransportDescriptor().getTransportType();
      System.out.println("Transport type used: " + Integer.toString(transportUsed));
      connection = (StreamConnection) connectionDescriptor.getConnection();
    }
    return connection;
  }
Exemple #3
0
  public static EncodedImage getImage(String url, Manager parent) throws IOException {
    url += ";deviceside=true";
    HttpConnection connection = null;
    InputStream inputStream = null;
    try {
      ConnectionFactory cf = new ConnectionFactory();
      cf.setConnectionTimeout(2500);
      ConnectionDescriptor cd = cf.getConnection(url);
      HttpConnection httpConn;
      httpConn = (HttpConnection) cd.getConnection();
      inputStream = httpConn.openInputStream();
      StringBuffer rawResponse = new StringBuffer();
      byte[] responseData = new byte[10000];
      int length = 0;
      while (-1 != (length = inputStream.read(responseData))) {
        rawResponse.append(new String(responseData, 0, length));
      }
      String result = rawResponse.toString();
      byte[] dataArray = result.getBytes();
      // Image.createImage(InputStream);
      httpConn.close();
      return EncodedImage.createEncodedImage(dataArray, 0, dataArray.length);

    } catch (IOException e1) {
      //
    }

    return null;
  }