protected void writeRecon(StringBuffer sb, Cell cell) {
    Recon recon = cell.recon;
    if (serializedRecons.contains(recon.id)) {
      sb.append(Long.toString(recon.id));
    } else {
      serializedRecons.add(recon.id);

      String s = cell.value instanceof String ? (String) cell.value : cell.value.toString();

      sb.append("{ ");
      sb.append("\"id\" : ");
      sb.append(Long.toString(recon.id));
      sb.append(", \"history_entry\" : ");
      sb.append(Long.toString(recon.judgmentHistoryEntry));
      sb.append(", \"text\" : ");
      sb.append(JSONObject.quote(s));
      sb.append(", \"service\" : ");
      sb.append(JSONObject.quote(recon.service));
      sb.append(", \"action\" : ");
      sb.append(JSONObject.quote(recon.judgmentAction));
      sb.append(", \"batch\" : ");
      sb.append(Integer.toString(recon.judgmentBatchSize));
      sb.append(", \"matchRank\" : ");
      sb.append(Integer.toString(recon.matchRank));
      sb.append(" }");
    }
  }
 /**
  * Get the enum value associated with an index.
  *
  * @param clazz The type of enum to retrieve.
  * @param index The index must be between 0 and length() - 1.
  * @return The enum value at the index location
  * @throws JSONException if the key is not found or if the value cannot be converted to an enum.
  */
 public <E extends Enum<E>> E getEnum(Class<E> clazz, int index) throws JSONException {
   E val = optEnum(clazz, index);
   if (val == null) {
     // JSONException should really take a throwable argument.
     // If it did, I would re-implement this with the Enum.valueOf
     // method and place any thrown exception in the JSONException
     throw new JSONException(
         "JSONObject["
             + JSONObject.quote(Integer.toString(index))
             + "] is not an enum of type "
             + JSONObject.quote(clazz.getSimpleName())
             + ".");
   }
   return val;
 }
Example #3
0
  /**
   * Write the contents of the JSONObject as JSON text to a writer. For compactness, no whitespace
   * is added.
   *
   * <p>Warning: This method assumes that the data structure is acyclical.
   *
   * @return The writer.
   * @throws JSONException
   */
  public Writer write(Writer writer) throws JSONException {
    try {
      boolean commanate = false;
      final Iterator keys = this.keys();
      writer.write('{');

      while (keys.hasNext()) {
        if (commanate) {
          writer.write(',');
        }
        final Object key = keys.next();
        writer.write(JSONObject.quote(key.toString()));
        writer.write(':');
        final Object value = this.map.get(key);
        if (value instanceof JSONObject) {
          ((JSONObject) value).write(writer);
        } else if (value instanceof JSONArray) {
          ((JSONArray) value).write(writer);
        } else {
          writer.write(JSONObject.valueToString(value));
        }
        commanate = true;
      }
      writer.write('}');
      return writer;
    } catch (final IOException exception) {
      throw new JSONException(exception);
    }
  }
Example #4
0
 static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent)
     throws JSONException, IOException {
   if (value == null || value.equals(null)) {
     writer.write("null");
   } else if (value instanceof JSONObject) {
     ((JSONObject) value).write(writer, indentFactor, indent);
   } else if (value instanceof JSONArray) {
     ((JSONArray) value).write(writer, indentFactor, indent);
   } else if (value instanceof Map) {
     new JSONObject((Map) value).write(writer, indentFactor, indent);
   } else if (value instanceof Collection) {
     new JSONArray((Collection) value).write(writer, indentFactor, indent);
   } else if (value.getClass().isArray()) {
     new JSONArray(value).write(writer, indentFactor, indent);
   } else if (value instanceof Number) {
     writer.write(numberToString((Number) value));
   } else if (value instanceof Boolean) {
     writer.write(value.toString());
   } else if (value instanceof JSONString) {
     Object o;
     try {
       o = ((JSONString) value).toJSONString();
     } catch (Exception e) {
       throw new JSONException(e);
     }
     writer.write(o != null ? o.toString() : quote(value.toString()));
   } else {
     quote(value.toString(), writer);
   }
   return writer;
 }
Example #5
0
 /**
  * Get the JSONObject value associated with a key.
  *
  * @param key A key string.
  * @return A JSONObject which is the value.
  * @throws JSONException if the key is not found or if the value is not a JSONObject.
  */
 public JSONObject getJSONObject(String key) throws JSONException {
   final Object object = this.get(key);
   if (object instanceof JSONObject) {
     return (JSONObject) object;
   }
   throw new JSONException("JSONObject[" + JSONObject.quote(key) + "] is not a JSONObject.");
 }
    public Object write(String subject, String predicate, Cell subjectCell) {
      if (children.size() == 0 || subject == null) {
        return null;
      }

      StringBuffer sb = new StringBuffer();
      sb.append("{ ");

      boolean first = true;
      for (int i = 0; i < children.size(); i++) {
        Object c = children.get(i).write(null, null, null);
        if (c != null) {
          if (first) {
            first = false;
          } else {
            sb.append(", ");
          }
          sb.append("\"" + properties.get(i).id + "\": ");
          sb.append(c instanceof String ? JSONObject.quote((String) c) : c.toString());
        }
      }
      sb.append(" }");

      writeLine(subject, predicate, sb, subjectCell, null);

      return null;
    }
  protected void writeLine(
      String subject, String predicate, Object object, String lang, Cell subjectCell) {
    if (subject != null && object != null) {
      String s = object instanceof String ? JSONObject.quote((String) object) : object.toString();

      StringBuffer sb = new StringBuffer();
      sb.append("{ \"s\" : \"");
      sb.append(subject);
      sb.append('"');
      sb.append(", \"p\" : \"");
      sb.append(predicate);
      sb.append('"');
      sb.append(", \"o\" : ");
      sb.append(s);
      sb.append(", \"lang\" : ");
      sb.append(lang);

      if (subjectCell != null) {
        sb.append(", \"meta\" : { ");
        sb.append("\"srecon\" : ");
        writeRecon(sb, subjectCell);
        sb.append(" }");
      }
      sb.append(" }");

      writeLine(sb.toString());
    }
  }
Example #8
0
 /**
  * Make a JSON text of an Object value. If the object has an value.toJSONString() method, then
  * that method will be used to produce the JSON text. The method is required to produce a strictly
  * conforming text. If the object does not contain a toJSONString method (which is the most common
  * case), then a text will be produced by other means. If the value is an array or Collection,
  * then a JSONArray will be made from it and its toJSONString method will be called. If the value
  * is a MAP, then a JSONObject will be made from it and its toJSONString method will be called.
  * Otherwise, the value's toString method will be called, and the result will be quoted.
  *
  * <p>Warning: This method assumes that the data structure is acyclical.
  *
  * @param value The value to be serialized.
  * @return a printable, displayable, transmittable representation of the object, beginning with
  *     <code>{</code>&nbsp;<small>(left brace)</small> and ending with <code>}</code>
  *     &nbsp;<small>(right brace)</small>.
  * @throws JSONException If the value is or contains an invalid number.
  */
 public static String valueToString(Object value) throws JSONException {
   if ((value == null) || value.equals(null)) {
     return "null";
   }
   if (value instanceof JSONString) {
     Object object;
     try {
       object = ((JSONString) value).toJSONString();
     } catch (final Exception e) {
       throw new JSONException(e);
     }
     if (object instanceof String) {
       return (String) object;
     }
     throw new JSONException("Bad value from toJSONString: " + object);
   }
   if (value instanceof Number) {
     return JSONObject.numberToString((Number) value);
   }
   if ((value instanceof Boolean)
       || (value instanceof JSONObject)
       || (value instanceof JSONArray)) {
     return value.toString();
   }
   if (value instanceof Map) {
     return new JSONObject((Map) value).toString();
   }
   if (value instanceof Collection) {
     return new JSONArray((Collection) value).toString();
   }
   if (value.getClass().isArray()) {
     return new JSONArray(value).toString();
   }
   return JSONObject.quote(value.toString());
 }
  /*
   * Use case: return the Java object back to JS after invokeNativeMethod
   * 1. quote string in proper way
   * 2. serialize the normal Java object
   */
  public static String objToJSON(Object obj) {
    // We expect the object is JSONObject or primive type.
    if (obj == null) return "null";

    Object sObj = toSerializableObject(obj);
    return (sObj instanceof String) ? JSONObject.quote(sObj.toString()) : sObj.toString();
  }
 private static void writeJSONValue(Appendable sb, Object o, int indentFactor, int indent)
     throws Exception {
   if (o == null) sb.append("null");
   else if (o instanceof String) sb.append(JSONObject.quote((String) o));
   else if (o instanceof JSONObject) writeJSON(sb, (JSONObject) o, indentFactor, indent);
   else if (o instanceof JSONArray) writeJSON(sb, (JSONArray) o, indentFactor, indent);
   else sb.append(o.toString());
 }
 static void writeJSON(Appendable sb, JSONObject jo, int indentFactor, int indent)
     throws Exception {
   int i;
   int length = jo.length();
   if (length == 0) {
     sb.append("{}");
     return;
   }
   @SuppressWarnings("unchecked")
   Iterator<String> keys = jo.keys();
   int newindent = indent + indentFactor;
   String object;
   sb.append("{");
   boolean addComma = false;
   if (length == 1) {
     object = keys.next();
     sb.append(JSONObject.quote(object.toString()));
     sb.append(": ");
     writeJSONValue(sb, jo.get(object), indentFactor, indent);
     // sb.append(valueToString(jo.get(object), indentFactor, indent));
     addComma = true;
   } else {
     while (keys.hasNext()) {
       object = keys.next();
       if (addComma) sb.append(",");
       sb.append('\n');
       addComma = true;
       for (i = 0; i < newindent; i += 1) {
         sb.append(' ');
       }
       sb.append(JSONObject.quote(object.toString()));
       sb.append(": ");
       writeJSONValue(sb, jo.get(object), indentFactor, indent);
       // sb.append(valueToString(jo.get(object), indentFactor, newindent));
     }
     if (addComma) {
       sb.append('\n');
       for (i = 0; i < indent; i += 1) {
         sb.append(' ');
       }
     }
   }
   sb.append('}');
 }
Example #12
0
 /**
  * Get the value object associated with a key.
  *
  * @param key A key string.
  * @return The object associated with the key.
  * @throws JSONException if the key is not found.
  */
 public Object get(String key) throws JSONException {
   if (key == null) {
     throw new JSONException("Null key.");
   }
   final Object object = this.opt(key);
   if (object == null) {
     throw new JSONException("JSONObject[" + JSONObject.quote(key) + "] not found.");
   }
   return object;
 }
Example #13
0
 /**
  * Get the double value associated with a key.
  *
  * @param key A key string.
  * @return The numeric value.
  * @throws JSONException if the key is not found or if the value is not a Number object and cannot
  *     be converted to a number.
  */
 public double getDouble(String key) throws JSONException {
   final Object object = this.get(key);
   try {
     return object instanceof Number
         ? ((Number) object).doubleValue()
         : Double.parseDouble((String) object);
   } catch (final Exception e) {
     throw new JSONException("JSONObject[" + JSONObject.quote(key) + "] is not a number.");
   }
 }
Example #14
0
 /**
  * Get the int value associated with a key.
  *
  * @param key A key string.
  * @return The integer value.
  * @throws JSONException if the key is not found or if the value cannot be converted to an
  *     integer.
  */
 public int getInt(String key) throws JSONException {
   final Object object = this.get(key);
   try {
     return object instanceof Number
         ? ((Number) object).intValue()
         : Integer.parseInt((String) object);
   } catch (final Exception e) {
     throw new JSONException("JSONObject[" + JSONObject.quote(key) + "] is not an int.");
   }
 }
Example #15
0
 /**
  * Get the long value associated with a key.
  *
  * @param key A key string.
  * @return The long value.
  * @throws JSONException if the key is not found or if the value cannot be converted to a long.
  */
 public long getLong(String key) throws JSONException {
   final Object object = this.get(key);
   try {
     return object instanceof Number
         ? ((Number) object).longValue()
         : Long.parseLong((String) object);
   } catch (final Exception e) {
     throw new JSONException("JSONObject[" + JSONObject.quote(key) + "] is not a long.");
   }
 }
Example #16
0
 /**
  * Get the boolean value associated with a key.
  *
  * @param key A key string.
  * @return The truth.
  * @throws JSONException if the value is not a Boolean or the String "true" or "false".
  */
 public boolean getBoolean(String key) throws JSONException {
   final Object object = this.get(key);
   if (object.equals(Boolean.FALSE)
       || ((object instanceof String) && ((String) object).equalsIgnoreCase("false"))) {
     return false;
   } else if (object.equals(Boolean.TRUE)
       || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) {
     return true;
   }
   throw new JSONException("JSONObject[" + JSONObject.quote(key) + "] is not a Boolean.");
 }
Example #17
0
 /**
  * Make a prettyprinted JSON text of this JSONObject.
  *
  * <p>Warning: This method assumes that the data structure is acyclical.
  *
  * @param indentFactor The number of spaces to add to each level of indentation.
  * @param indent The indentation of the top level.
  * @return a printable, displayable, transmittable representation of the object, beginning with
  *     <code>{</code>&nbsp;<small>(left brace)</small> and ending with <code>}</code>
  *     &nbsp;<small>(right brace)</small>.
  * @throws JSONException If the object contains an invalid number.
  */
 String toString(int indentFactor, int indent) throws JSONException {
   int i;
   final int length = this.length();
   if (length == 0) {
     return "{}";
   }
   final Iterator keys = this.keys();
   final int newindent = indent + indentFactor;
   Object object;
   final StringBuffer sb = new StringBuffer("{");
   if (length == 1) {
     object = keys.next();
     sb.append(JSONObject.quote(object.toString()));
     sb.append(": ");
     sb.append(JSONObject.valueToString(this.map.get(object), indentFactor, indent));
   } else {
     while (keys.hasNext()) {
       object = keys.next();
       if (sb.length() > 1) {
         sb.append(",\n");
       } else {
         sb.append('\n');
       }
       for (i = 0; i < newindent; i += 1) {
         sb.append(' ');
       }
       sb.append(JSONObject.quote(object.toString()));
       sb.append(": ");
       sb.append(JSONObject.valueToString(this.map.get(object), indentFactor, newindent));
     }
     if (sb.length() > 1) {
       sb.append('\n');
       for (i = 0; i < indent; i += 1) {
         sb.append(' ');
       }
     }
   }
   sb.append('}');
   return sb.toString();
 }
 public static String getJsonRepresentation(Object value) throws JSONException {
   if (value == null || value.equals(null)) {
     return "null";
   }
   if (value instanceof FString) {
     return JSONObject.quote(value.toString());
   }
   if (value instanceof YailList) {
     return ((YailList) value).toJSONString();
   }
   // The Json tokener used in getOnjectFromJson cannot handle
   // fractions.  So we Json encode fractions by first converting
   // them to doubles. This is an example of value with Kawa type any
   // being exposed to the rest of App Inventor by the value being
   // passed to a compoent method, in this case TinyDB or TinyWebDB
   // StoreValue.  See the "warning" comment in runtime.scm at
   // call-component-method.
   if (value instanceof IntFraction) {
     return JSONObject.numberToString((Number) ((IntFraction) value).doubleValue());
   }
   if (value instanceof Number) {
     return JSONObject.numberToString((Number) value);
   }
   if (value instanceof Boolean) {
     return value.toString();
   }
   if (value.getClass().isArray()) {
     StringBuilder sb = new StringBuilder();
     sb.append("[");
     String separator = "";
     for (Object o : (Object[]) value) {
       sb.append(separator).append(getJsonRepresentation(o));
       separator = ",";
     }
     sb.append("]");
     return sb.toString();
   }
   return JSONObject.quote(value.toString());
 }
Example #19
0
 /**
  * Increment a property of a JSONObject. If there is no such property, create one with a value of
  * 1. If there is such a property, and if it is an Integer, Long, Double, or Float, then add one
  * to it.
  *
  * @param key A key string.
  * @return this.
  * @throws JSONException If there is already a property with this name that is not an Integer,
  *     Long, Double, or Float.
  */
 public JSONObject increment(String key) throws JSONException {
   final Object value = this.opt(key);
   if (value == null) {
     this.put(key, 1);
   } else if (value instanceof Integer) {
     this.put(key, ((Integer) value).intValue() + 1);
   } else if (value instanceof Long) {
     this.put(key, ((Long) value).longValue() + 1);
   } else if (value instanceof Double) {
     this.put(key, ((Double) value).doubleValue() + 1);
   } else if (value instanceof Float) {
     this.put(key, ((Float) value).floatValue() + 1);
   } else {
     throw new JSONException("Unable to increment [" + JSONObject.quote(key) + "].");
   }
   return this;
 }
 /**
  * Append a key. The key will be associated with the next value. In an object, every value must be
  * preceded by a key.
  *
  * @param s A key string.
  * @return this
  * @throws JSONException If the key is out of place. For example, keys do not belong in arrays or
  *     if the key is null.
  */
 public JSONWriter key(String s) throws JSONException {
   if (s == null) {
     throw new JSONException("Null key.");
   }
   if (this.mode == 'k') {
     try {
       if (this.comma) {
         this.writer.write(',');
       }
       this.writer.write(JSONObject.quote(s));
       this.writer.write(':');
       this.comma = false;
       this.mode = 'o';
       return this;
     } catch (IOException e) {
       throw new JSONException(e);
     }
   }
   throw new JSONException("Misplaced key.");
 }
Example #21
0
 /**
  * Append a key. The key will be associated with the next value. In an object, every value must be
  * preceded by a key.
  *
  * @param string A key string.
  * @return this
  * @throws JSONException If the key is out of place. For example, keys do not belong in arrays or
  *     if the key is null.
  */
 public JSONWriter key(String string) throws JSONException {
   if (string == null) {
     throw new JSONException("Null key.");
   }
   if (this.mode == 'k') {
     try {
       this.stack[this.top - 1].putOnce(string, Boolean.TRUE);
       if (this.comma) {
         this.writer.write(',');
       }
       this.writer.write(JSONObject.quote(string));
       this.writer.write(':');
       this.comma = false;
       this.mode = 'o';
       return this;
     } catch (IOException e) {
       throw new JSONException(e);
     }
   }
   throw new JSONException("Misplaced key.");
 }
Example #22
0
  /**
   * Make a JSON text of this JSONObject. For compactness, no whitespace is added. If this would not
   * result in a syntactically correct JSON text, then null will be returned instead.
   *
   * <p>Warning: This method assumes that the data structure is acyclical.
   *
   * @return a printable, displayable, portable, transmittable representation of the object,
   *     beginning with <code>{</code>&nbsp;<small>(left brace)</small> and ending with <code>}
   *     </code>&nbsp;<small>(right brace)</small>.
   */
  @Override
  public String toString() {
    try {
      final Iterator keys = this.keys();
      final StringBuffer sb = new StringBuffer("{");

      while (keys.hasNext()) {
        if (sb.length() > 1) {
          sb.append(',');
        }
        final Object o = keys.next();
        sb.append(JSONObject.quote(o.toString()));
        sb.append(':');
        sb.append(JSONObject.valueToString(this.map.get(o)));
      }
      sb.append('}');
      return sb.toString();
    } catch (final Exception e) {
      return null;
    }
  }
Example #23
0
  // Copy the content of reader to ping;
  // copying stops when endPattern is found in the input stream
  private static int fillPingBlock(OutputStream ping, Reader reader, String endPattern)
      throws IOException {

    int total = 0;
    int endIndex = 0;
    char[] block = new char[TRACES_BLOCK_SIZE];
    for (int size = reader.read(block); size >= 0; size = reader.read(block)) {
      String stringBlock = new String(block, 0, size);
      endIndex = getEndPatternIndex(stringBlock, endPattern, endIndex);
      if (endIndex > 0) {
        // Found end pattern; clip the string
        stringBlock = stringBlock.substring(0, endIndex);
      }
      String quoted = JSONObject.quote(stringBlock);
      total += writePingPayload(ping, quoted.substring(1, quoted.length() - 1));
      if (endIndex > 0) {
        // End pattern already found; return now
        break;
      }
    }
    return total;
  }
Example #24
0
 /**
  * Make a prettyprinted JSON text of an object value.
  *
  * <p>Warning: This method assumes that the data structure is acyclical.
  *
  * @param value The value to be serialized.
  * @param indentFactor The number of spaces to add to each level of indentation.
  * @param indent The indentation of the top level.
  * @return a printable, displayable, transmittable representation of the object, beginning with
  *     <code>{</code>&nbsp;<small>(left brace)</small> and ending with <code>}</code>
  *     &nbsp;<small>(right brace)</small>.
  * @throws JSONException If the object contains an invalid number.
  */
 static String valueToString(Object value, int indentFactor, int indent) throws JSONException {
   if ((value == null) || value.equals(null)) {
     return "null";
   }
   try {
     if (value instanceof JSONString) {
       final Object o = ((JSONString) value).toJSONString();
       if (o instanceof String) {
         return (String) o;
       }
     }
   } catch (final Exception ignore) {
   }
   if (value instanceof Number) {
     return JSONObject.numberToString((Number) value);
   }
   if (value instanceof Boolean) {
     return value.toString();
   }
   if (value instanceof JSONObject) {
     return ((JSONObject) value).toString(indentFactor, indent);
   }
   if (value instanceof JSONArray) {
     return ((JSONArray) value).toString(indentFactor, indent);
   }
   if (value instanceof Map) {
     return new JSONObject((Map) value).toString(indentFactor, indent);
   }
   if (value instanceof Collection) {
     return new JSONArray((Collection) value).toString(indentFactor, indent);
   }
   if (value.getClass().isArray()) {
     return new JSONArray(value).toString(indentFactor, indent);
   }
   return JSONObject.quote(value.toString());
 }
 public String getJsonUri() {
   return JSONObject.quote(uri);
 }
  @Override
  public void save(Writer writer, Properties options) throws IOException {
    writer.write("baseColumnName=");
    writer.write(_baseColumnName);
    writer.write('\n');
    writer.write("columnInsertIndex=");
    writer.write(Integer.toString(_columnInsertIndex));
    writer.write('\n');
    writer.write("columnNameCount=");
    writer.write(Integer.toString(_columnNames.size()));
    writer.write('\n');
    for (String name : _columnNames) {
      writer.write(name);
      writer.write('\n');
    }
    writer.write("columnTypeCount=");
    writer.write(Integer.toString(_columnTypes.size()));
    writer.write('\n');
    for (DBpediaType type : _columnTypes) {
      try {
        JSONWriter jsonWriter = new JSONWriter(writer);

        type.write(jsonWriter, options);
      } catch (JSONException e) {
        // ???
      }
      writer.write('\n');
    }
    writer.write("rowIndexCount=");
    writer.write(Integer.toString(_rowIndices.size()));
    writer.write('\n');
    for (Integer rowIndex : _rowIndices) {
      writer.write(rowIndex.toString());
      writer.write('\n');
    }
    writer.write("dataExtensionCount=");
    writer.write(Integer.toString(_dataExtensions.size()));
    writer.write('\n');
    for (DataExtension dataExtension : _dataExtensions) {
      if (dataExtension == null) {
        writer.write('\n');
        continue;
      }

      writer.write(Integer.toString(dataExtension.data.length));
      writer.write('\n');

      for (Object[] values : dataExtension.data) {
        for (Object value : values) {
          if (value == null) {
            writer.write("null");
          } else if (value instanceof ReconCandidate) {
            try {
              JSONWriter jsonWriter = new JSONWriter(writer);
              ((ReconCandidate) value).write(jsonWriter, options);
            } catch (JSONException e) {
              // ???
            }
          } else if (value instanceof String) {
            writer.write(JSONObject.quote((String) value));
          } else {
            writer.write(value.toString());
          }
          writer.write('\n');
        }
      }
    }

    writer.write("firstNewCellIndex=");
    writer.write(Integer.toString(_firstNewCellIndex));
    writer.write('\n');

    writer.write("newRowCount=");
    writer.write(Integer.toString(_newRows.size()));
    writer.write('\n');
    for (Row row : _newRows) {
      row.save(writer, options);
      writer.write('\n');
    }
    writer.write("oldRowCount=");
    writer.write(Integer.toString(_oldRows.size()));
    writer.write('\n');
    for (Row row : _oldRows) {
      row.save(writer, options);
      writer.write('\n');
    }
    writer.write("/ec/\n"); // end of change marker
  }
Example #27
0
 public String getMessage() {
   if (encodedMessage == null) {
     encodedMessage = JSONObject.quote(strMessage);
   }
   return encodedMessage;
 }
 public PluginResult(Status status, String message) {
   this.status = status.ordinal();
   this.message = JSONObject.quote(message);
 }
Example #29
0
  private static void fillPingHeader(OutputStream ping, String slug) throws IOException {

    // ping file header
    byte[] data =
        ("{"
                + "\"reason\":\"android-anr-report\","
                + "\"slug\":"
                + JSONObject.quote(slug)
                + ","
                + "\"payload\":")
            .getBytes(PING_CHARSET);
    ping.write(data);
    if (DEBUG) {
      Log.d(LOGTAG, "wrote ping header, size = " + String.valueOf(data.length));
    }

    // payload start
    int size =
        writePingPayload(
            ping,
            ("{"
                + "\"ver\":1,"
                + "\"simpleMeasurements\":{"
                + "\"uptime\":"
                + String.valueOf(getUptimeMins())
                + "},"
                + "\"info\":{"
                + "\"reason\":\"android-anr-report\","
                + "\"OS\":"
                + JSONObject.quote(SysInfo.getName())
                + ","
                + "\"version\":\""
                + String.valueOf(SysInfo.getVersion())
                + "\","
                + "\"appID\":"
                + JSONObject.quote(AppConstants.MOZ_APP_ID)
                + ","
                + "\"appVersion\":"
                + JSONObject.quote(AppConstants.MOZ_APP_VERSION)
                + ","
                + "\"appName\":"
                + JSONObject.quote(AppConstants.MOZ_APP_BASENAME)
                + ","
                + "\"appBuildID\":"
                + JSONObject.quote(AppConstants.MOZ_APP_BUILDID)
                + ","
                + "\"appUpdateChannel\":"
                + JSONObject.quote(AppConstants.MOZ_UPDATE_CHANNEL)
                + ","
                +
                // Technically the platform build ID may be different, but we'll never know
                "\"platformBuildID\":"
                + JSONObject.quote(AppConstants.MOZ_APP_BUILDID)
                + ","
                + "\"locale\":"
                + JSONObject.quote(Locales.getLanguageTag(Locale.getDefault()))
                + ","
                + "\"cpucount\":"
                + String.valueOf(SysInfo.getCPUCount())
                + ","
                + "\"memsize\":"
                + String.valueOf(SysInfo.getMemSize())
                + ","
                + "\"arch\":"
                + JSONObject.quote(SysInfo.getArchABI())
                + ","
                + "\"kernel_version\":"
                + JSONObject.quote(SysInfo.getKernelVersion())
                + ","
                + "\"device\":"
                + JSONObject.quote(SysInfo.getDevice())
                + ","
                + "\"manufacturer\":"
                + JSONObject.quote(SysInfo.getManufacturer())
                + ","
                + "\"hardware\":"
                + JSONObject.quote(SysInfo.getHardware())
                + "},"
                + "\"androidANR\":\""));
    if (DEBUG) {
      Log.d(LOGTAG, "wrote metadata, size = " + String.valueOf(size));
    }

    // We are at the start of ANR data
  }
 public void snapshots(UIThreadSet<Activity> paramUIThreadSet, OutputStream paramOutputStream)
     throws IOException {
   this.mRootViewFinder.findInActivities(paramUIThreadSet);
   paramUIThreadSet = new FutureTask(this.mRootViewFinder);
   this.mMainThreadHandler.post(paramUIThreadSet);
   OutputStreamWriter localOutputStreamWriter = new OutputStreamWriter(paramOutputStream);
   Object localObject = Collections.emptyList();
   localOutputStreamWriter.write("[");
   try {
     paramUIThreadSet = (List) paramUIThreadSet.get(1L, TimeUnit.SECONDS);
     int j = paramUIThreadSet.size();
     int i = 0;
     while (i < j) {
       if (i > 0) {
         localOutputStreamWriter.write(",");
       }
       localObject = (RootViewInfo) paramUIThreadSet.get(i);
       localOutputStreamWriter.write("{");
       localOutputStreamWriter.write("\"activity\":");
       localOutputStreamWriter.write(JSONObject.quote(((RootViewInfo) localObject).activityName));
       localOutputStreamWriter.write(",");
       localOutputStreamWriter.write("\"scale\":");
       localOutputStreamWriter.write(
           String.format("%s", new Object[] {Float.valueOf(((RootViewInfo) localObject).scale)}));
       localOutputStreamWriter.write(",");
       localOutputStreamWriter.write("\"serialized_objects\":");
       JsonWriter localJsonWriter = new JsonWriter(localOutputStreamWriter);
       localJsonWriter.beginObject();
       localJsonWriter.name("rootObject").value(((RootViewInfo) localObject).rootView.hashCode());
       localJsonWriter.name("objects");
       snapshotViewHierarchy(localJsonWriter, ((RootViewInfo) localObject).rootView);
       localJsonWriter.endObject();
       localJsonWriter.flush();
       localOutputStreamWriter.write(",");
       localOutputStreamWriter.write("\"screenshot\":");
       localOutputStreamWriter.flush();
       ((RootViewInfo) localObject)
           .screenshot.writeBitmapJSON(Bitmap.CompressFormat.PNG, 100, paramOutputStream);
       localOutputStreamWriter.write("}");
       i += 1;
     }
   } catch (InterruptedException localInterruptedException) {
     for (; ; ) {
       paramUIThreadSet = (UIThreadSet<Activity>) localObject;
       if (MPConfig.DEBUG) {
         Log.d(
             "MixpanelAPI.Snapshot",
             "Screenshot interrupted, no screenshot will be sent.",
             localInterruptedException);
         paramUIThreadSet = (UIThreadSet<Activity>) localObject;
       }
     }
   } catch (TimeoutException localTimeoutException) {
     for (; ; ) {
       paramUIThreadSet = (UIThreadSet<Activity>) localObject;
       if (MPConfig.DEBUG) {
         Log.i(
             "MixpanelAPI.Snapshot",
             "Screenshot took more than 1 second to be scheduled and executed. No screenshot will be sent.",
             localTimeoutException);
         paramUIThreadSet = (UIThreadSet<Activity>) localObject;
       }
     }
   } catch (ExecutionException localExecutionException) {
     for (; ; ) {
       paramUIThreadSet = (UIThreadSet<Activity>) localObject;
       if (MPConfig.DEBUG) {
         Log.e(
             "MixpanelAPI.Snapshot",
             "Exception thrown during screenshot attempt",
             localExecutionException);
         paramUIThreadSet = (UIThreadSet<Activity>) localObject;
       }
     }
     localOutputStreamWriter.write("]");
     localOutputStreamWriter.flush();
   }
 }