Android Open Source - spotastop Jarvis Dyn Dns Service






From Project

Back to project page spotastop.

License

The source code is released under:

MIT License

If you think the Android project spotastop listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cipciop.spotastop.services;
//ww  w  . ja v a  2 s  . c o m
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.util.ArrayList;

import requests.Criteria;
import resources.Resource;
import responses.beContentResponse;
import rest.RestApi;
import settings.Settings;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import com.cipciop.spotastop.StopSpotApp;
import com.cipciop.spotastop.domain.User;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.nicfix.gsoncompatibility.GsonConfigurator;

public class JarvisDynDnsService extends Service {

  private String realUrl = "";

  @Override
  public IBinder onBind(Intent arg0) {
    return null;
  }

  public int onStartCommand(Intent intent, int flags, int startid) {
    new Thread(new Runnable() {
      public void run() {
        String responseString = "";
        String urlString = Settings.getJarvisProxyServerUrl();

        HttpURLConnection urlConnection = null;
        URL url = null;

        try {
          url = new URL(urlString.toString());
          Gson parser = GsonConfigurator.getInstance().build();

          urlConnection = (HttpURLConnection) url.openConnection();
          urlConnection.setRequestMethod("GET");
          urlConnection.setDoOutput(true);
          urlConnection.setDoInput(true);

          urlConnection.connect();

          InputStream inStream = urlConnection.getInputStream();

          // ///PERFORMANCE CRITICAL
          BufferedInputStream bis = new BufferedInputStream(inStream);
          ByteArrayOutputStream buf = new ByteArrayOutputStream();
          int result = bis.read();
          while (result != -1) {
            byte b = (byte) result;
            buf.write(b);
            result = bis.read();
          }
          responseString = buf.toString();
          // ///PERFORMANCE CRITICAL

          inStream.close();
          urlConnection.disconnect();

          JsonObject response = parser.fromJson(responseString,
              JsonObject.class);
          JarvisDynDnsService.this.realUrl = response.get("address")
              .getAsString();
          if (Settings.isJarvisMode())
            Settings.setServerUrl(JarvisDynDnsService.this.realUrl
                + ":" + Settings.getJarvisProxyServerPort());
        } catch (MalformedURLException e) {
        } catch (ProtocolException e) {
        } catch (IOException e) {
        }

      }
    }).start();
    return 0;
  }
}




Java Source Code List

.LoaderTester.java
com.cipciop.spotastop.ErrorActivity.java
com.cipciop.spotastop.LoginActivity.java
com.cipciop.spotastop.RegisterActivity.java
com.cipciop.spotastop.SelectBusLine.java
com.cipciop.spotastop.SpotActivity.java
com.cipciop.spotastop.StopSpotApp.java
com.cipciop.spotastop.domain.BusStop.java
com.cipciop.spotastop.domain.GeoPos.java
com.cipciop.spotastop.domain.Line.java
com.cipciop.spotastop.domain.User.java
com.cipciop.spotastop.presentation.BusLineItem.java
com.cipciop.spotastop.services.JarvisDynDnsService.java
com.cipciop.spotastop.services.LoginService.java
com.cipciop.spotastop.services.RegistrationService.java
com.cipciop.spotastop.services.RetrieveLinesListService.java
com.cipciop.spotastop.services.SpotBusStopService.java
com.nicfix.gsoncompatibility.GsonConfigurator.java
requests.CreatorRequest.java
requests.Criteria.java
requests.Data.java
requests.EditorRequest.java
requests.Link.java
requests.LinkerRequest.java
requests.LoaderRequest.java
requests.StorerRequest.java
requests.Unlink.java
requests.beContentRequest.java
resources.Resource.java
resources.ResourcesCache.java
resources.ResourcesMapper.java
responses.AsyncCallback.java
responses.beContentResponse.java
rest.RestApi.java
settings.Settings.java