/**
  * invokes a service call to get the header information for a single survey
  *
  * @param serverBase
  * @param surveyId
  * @return
  */
 private ArrayList<Survey> getSurveyHeader(String serverBase, String surveyId, String deviceId) {
   String response = null;
   ArrayList<Survey> surveys = new ArrayList<Survey>();
   try {
     response =
         HttpUtil.httpGet(
             serverBase
                 + SURVEY_HEADER_SERVICE_PATH
                 + surveyId
                 + "&devicePhoneNumber="
                 + StatusUtil.getPhoneNumber(this)
                 + (deviceId != null
                     ? (DEV_ID_PARAM + URLEncoder.encode(deviceId, "UTF-8"))
                     : ""));
     if (response != null) {
       StringTokenizer strTok = new StringTokenizer(response, "\n");
       while (strTok.hasMoreTokens()) {
         String currentLine = strTok.nextToken();
         String[] touple = currentLine.split(",");
         if (touple.length < 4) {
           Log.e(TAG, "Survey list response is in an unrecognized format");
         } else {
           Survey temp = new Survey();
           temp.setId(touple[0]);
           temp.setName(touple[1]);
           temp.setLanguage(touple[2]);
           temp.setVersion(Double.parseDouble(touple[3]));
           temp.setType(ConstantUtil.FILE_SURVEY_LOCATION_TYPE);
           surveys.add(temp);
         }
       }
     }
   } catch (HttpException e) {
     Log.e(TAG, "Server returned an unexpected response", e);
     PersistentUncaughtExceptionHandler.recordException(e);
   } catch (Exception e) {
     Log.e(TAG, "Could not get survey headers", e);
     PersistentUncaughtExceptionHandler.recordException(e);
   }
   return surveys;
 }
  /**
   * Downloads the survey based on the ID and then updates the survey object with the filename and
   * location
   */
  private boolean downloadSurvey(String serverBase, Survey survey) {
    boolean success = false;
    try {
      HttpUtil.httpDownload(
          props.getProperty(ConstantUtil.SURVEY_S3_URL)
              + survey.getId()
              + ConstantUtil.ARCHIVE_SUFFIX,
          FileUtil.getFileOutputStream(
              survey.getId() + ConstantUtil.ARCHIVE_SUFFIX,
              ConstantUtil.DATA_DIR,
              props.getProperty(ConstantUtil.USE_INTERNAL_STORAGE),
              this));
      extractAndSave(
          FileUtil.getFileInputStream(
              survey.getId() + ConstantUtil.ARCHIVE_SUFFIX,
              ConstantUtil.DATA_DIR,
              props.getProperty(ConstantUtil.USE_INTERNAL_STORAGE),
              this));

      survey.setFileName(survey.getId() + ConstantUtil.XML_SUFFIX);
      survey.setType(DEFAULT_TYPE);
      survey.setLocation(SD_LOC);
      success = true;
    } catch (IOException e) {
      Log.e(TAG, "Could write survey file " + survey.getFileName(), e);
      String text = getResources().getString(R.string.cannotupdate);
      ViewUtil.fireNotification(text, text, this, FAIL_ID, null);
      PersistentUncaughtExceptionHandler.recordException(
          new TransferException(survey.getId(), null, e));

    } catch (Exception e) {
      Log.e(TAG, "Could not download survey " + survey.getId(), e);

      String text = getResources().getString(R.string.cannotupdate);
      ViewUtil.fireNotification(text, text, this, FAIL_ID, null);

      PersistentUncaughtExceptionHandler.recordException(
          new TransferException(survey.getId(), null, e));
    }
    return success;
  }