Exemple #1
0
 private static void pp(String name, JSONObject jsonObj) {
   try {
     String pp = jsonObj == null ? "null" : jsonObj.toString(2);
     Log.d(TAG, String.format("%s: %s", name, pp));
     FileUtils.writeToDebugDir(name + "-pp.json", pp);
   } catch (JSONException e) {
     Log.w(TAG, "Error printing JSON: " + e.getMessage(), e);
   }
 }
  private static boolean isValidFile(String accountName, InputStream in, List<String> packageNames)
      throws ServiceException {

    if (packageNames.isEmpty()) {
      return true;
    }

    CSVReader reader = null;
    try {
      reader = new CSVReader(new InputStreamReader(in));

      String[] firstLine = reader.readNext();
      if (firstLine != null) {
        if (HEADER_LIST.length >= firstLine.length) {
          for (int i = 0; i < firstLine.length - 1; i++) {
            if (!HEADER_LIST[i].equals(firstLine[i])) {
              return false;
            }
          }

          // validate package name
          String[] secondLine = reader.readNext();
          String packageName = secondLine[0];
          if (secondLine != null) {
            return packageNames.contains(packageName);
          }
        }
      }
    } catch (FileNotFoundException e) {
      throw new ServiceException(e);
    } catch (IOException e) {
      throw new ServiceException(e);
    } finally {
      FileUtils.closeSilently(reader);
    }

    return false;
  }