Java 类android.util.JsonWriter 实例源码

项目:BTNotifierAndroid    文件:Message.java   
public String toJSON(Context context) {
    StringWriter out = new StringWriter();
    JsonWriter writer = new JsonWriter(out);

    try {
        writer.beginObject();
        writer.name("event").value(event);

        writer.name("eventItems");
        writer.beginArray();

        if (type == SendType.SMS) {
            toJsonSMessage(context, writer, sMessage);
        } else if (type == SendType.NOTI) {
            for (StatusBarNotification sbn : notifications) {
                toJsonNotification(context, writer, sbn);
            }
        }
        writer.endArray();
        writer.endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return out.toString();
}
项目:BTNotifierAndroid    文件:Message.java   
@TargetApi(Build.VERSION_CODES.KITKAT)
private void writeActions(JsonWriter writer, Notification notification) throws IOException {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }

    if (notification.actions != null) {
        Log.d(TAG, "writing action");
        writer.name("actions");
        writer.beginArray();
        for (Notification.Action a : notification.actions) {
            Log.d(TAG, "writing action : " + a.title.toString());
            writer.beginObject();
            writer.name("title").value(a.title.toString());
            writer.endObject();
        }
        writer.endArray();
    }
}
项目:RNLearn_Project1    文件:JSDebuggerWebSocketClient.java   
public void prepareJSRuntime(JSDebuggerCallback callback) {
  int requestID = mRequestID.getAndIncrement();
  mCallbacks.put(requestID, callback);

  try {
    StringWriter sw = new StringWriter();
    JsonWriter js = new JsonWriter(sw);
    js.beginObject()
      .name("id").value(requestID)
      .name("method").value("prepareJSRuntime")
      .endObject()
      .close();
    sendMessage(requestID, sw.toString());
  } catch (IOException e) {
    triggerRequestFailure(requestID, e);
  }
}
项目:RNLearn_Project1    文件:JSDebuggerWebSocketClient.java   
public void loadApplicationScript(
    String sourceURL,
    HashMap<String, String> injectedObjects,
    JSDebuggerCallback callback) {
  int requestID = mRequestID.getAndIncrement();
  mCallbacks.put(requestID, callback);

  try {
    StringWriter sw = new StringWriter();
    JsonWriter js = new JsonWriter(sw)
       .beginObject()
       .name("id").value(requestID)
       .name("method").value("executeApplicationScript")
       .name("url").value(sourceURL)
       .name("inject").beginObject();
    for (String key : injectedObjects.keySet()) {
      js.name(key).value(injectedObjects.get(key));
    }
    js.endObject().endObject().close();
    sendMessage(requestID, sw.toString());
  } catch (IOException e) {
    triggerRequestFailure(requestID, e);
  }
}
项目:RNLearn_Project1    文件:JSDebuggerWebSocketClient.java   
public void executeJSCall(
    String methodName,
    String jsonArgsArray,
    JSDebuggerCallback callback) {
  int requestID = mRequestID.getAndIncrement();
  mCallbacks.put(requestID, callback);

  try {
    StringWriter sw = new StringWriter();
    JsonWriter js = new JsonWriter(sw);

    js.beginObject()
      .name("id").value(requestID)
      .name("method").value(methodName);
    /* JsonWriter does not offer writing raw string (without quotes), that's why
       here we directly write to output string using the the underlying StringWriter */
    sw.append(",\"arguments\":").append(jsonArgsArray);
    js.endObject().close();
    sendMessage(requestID, sw.toString());
  } catch (IOException e) {
    triggerRequestFailure(requestID, e);
  }
}
项目:RNLearn_Project1    文件:JSDebuggerWebSocketClient.java   
public void prepareJSRuntime(JSDebuggerCallback callback) {
  int requestID = mRequestID.getAndIncrement();
  mCallbacks.put(requestID, callback);

  try {
    StringWriter sw = new StringWriter();
    JsonWriter js = new JsonWriter(sw);
    js.beginObject()
      .name("id").value(requestID)
      .name("method").value("prepareJSRuntime")
      .endObject()
      .close();
    sendMessage(requestID, sw.toString());
  } catch (IOException e) {
    triggerRequestFailure(requestID, e);
  }
}
项目:RNLearn_Project1    文件:JSDebuggerWebSocketClient.java   
public void loadApplicationScript(
    String sourceURL,
    HashMap<String, String> injectedObjects,
    JSDebuggerCallback callback) {
  int requestID = mRequestID.getAndIncrement();
  mCallbacks.put(requestID, callback);

  try {
    StringWriter sw = new StringWriter();
    JsonWriter js = new JsonWriter(sw)
       .beginObject()
       .name("id").value(requestID)
       .name("method").value("executeApplicationScript")
       .name("url").value(sourceURL)
       .name("inject").beginObject();
    for (String key : injectedObjects.keySet()) {
      js.name(key).value(injectedObjects.get(key));
    }
    js.endObject().endObject().close();
    sendMessage(requestID, sw.toString());
  } catch (IOException e) {
    triggerRequestFailure(requestID, e);
  }
}
项目:RNLearn_Project1    文件:JSDebuggerWebSocketClient.java   
public void executeJSCall(
    String methodName,
    String jsonArgsArray,
    JSDebuggerCallback callback) {
  int requestID = mRequestID.getAndIncrement();
  mCallbacks.put(requestID, callback);

  try {
    StringWriter sw = new StringWriter();
    JsonWriter js = new JsonWriter(sw);

    js.beginObject()
      .name("id").value(requestID)
      .name("method").value(methodName);
    /* JsonWriter does not offer writing raw string (without quotes), that's why
       here we directly write to output string using the the underlying StringWriter */
    sw.append(",\"arguments\":").append(jsonArgsArray);
    js.endObject().close();
    sendMessage(requestID, sw.toString());
  } catch (IOException e) {
    triggerRequestFailure(requestID, e);
  }
}
项目:AOSP-Kayboard-7.1.2    文件:JsonUtils.java   
public static String listToJsonStr(final List<Object> list) {
    if (list == null || list.isEmpty()) {
        return EMPTY_STRING;
    }
    final StringWriter sw = new StringWriter();
    final JsonWriter writer = new JsonWriter(sw);
    try {
        writer.beginArray();
        for (final Object o : list) {
            writer.beginObject();
            if (o instanceof Integer) {
                writer.name(INTEGER_CLASS_NAME).value((Integer)o);
            } else if (o instanceof String) {
                writer.name(STRING_CLASS_NAME).value((String)o);
            }
            writer.endObject();
        }
        writer.endArray();
        return sw.toString();
    } catch (final IOException e) {
    } finally {
        close(writer);
    }
    return EMPTY_STRING;
}
项目:samba-documents-provider    文件:ShareManager.java   
private static String encode(String uri, ShareTuple tuple) {
  final StringWriter stringWriter = new StringWriter();
  try (final JsonWriter jsonWriter = new JsonWriter(stringWriter)) {
    jsonWriter.beginObject();
    jsonWriter.name(URI_KEY).value(uri);

    jsonWriter.name(CREDENTIAL_TUPLE_KEY);
    encodeTuple(jsonWriter, tuple);
    jsonWriter.endObject();
  } catch (IOException e) {
    Log.e(TAG, "Failed to encode credential for " + uri);
    return null;
  }

  return stringWriter.toString();
}
项目:cordova-websocket-clientcert    文件:WebSocketClient.java   
@Override
public void onOpen(ServerHandshake handshakedata) {

    StringWriter stringWriter = new StringWriter();
    JsonWriter writer = new JsonWriter(stringWriter);

    try {
        writer.beginObject();
        writer.name("event").value("onOpen");
        writer.name("resourceId").value(this.id);
        writer.endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.callback(PluginResult.Status.OK, stringWriter.toString());
}
项目:cordova-websocket-clientcert    文件:WebSocketClient.java   
@Override
public void onMessage(String message) {

    StringWriter stringWriter = new StringWriter();
    JsonWriter writer = new JsonWriter(stringWriter);

    try {
        writer.beginObject();
        writer.name("event").value("onMessage");
        writer.name("message").value(message);
        writer.endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.callback(PluginResult.Status.OK, stringWriter.toString());
}
项目:cordova-websocket-clientcert    文件:WebSocketClient.java   
@Override
public void onClose(int code, String reason, boolean remote) {
    StringWriter stringWriter = new StringWriter();
    JsonWriter writer = new JsonWriter(stringWriter);

    try {
        writer.beginObject();
        writer.name("event").value("onClose");
        writer.name("code").value(code);
        writer.name("reason").value(reason);
        writer.name("remote").value(remote);
        writer.endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.callback(PluginResult.Status.OK, stringWriter.toString());
}
项目:cordova-websocket-clientcert    文件:WebSocketClient.java   
@Override
public void onError(Exception ex) {
    StringWriter stringWriter = new StringWriter();
    JsonWriter writer = new JsonWriter(stringWriter);

    try {
        writer.beginObject();
        writer.name("event").value("onError");

        if (ex instanceof UnresolvedAddressException) {
            writer.name("errorCode").value("ERR_NAME_NOT_RESOLVED");
            writer.name("errorMessage").value("Unable to resolve address. Please check the url and your network connection");
        } else {
            writer.name("errorCode").value("ERR_NAME_UNKNOWN");
            writer.name("errorMessage").value("Unknown error was thrown");
        }

        writer.endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.callback(PluginResult.Status.OK, stringWriter.toString());
}
项目:segment-android    文件:JsonUtils.java   
/**
 * Writes the given {@link Object} to the {@link JsonWriter}.
 *
 * @throws IOException
 */
private static void writeValue(Object value, JsonWriter writer) throws IOException {
  if (value == null) {
    writer.nullValue();
  } else if (value instanceof Number) {
    writer.value((Number) value);
  } else if (value instanceof Boolean) {
    writer.value((Boolean) value);
  } else if (value instanceof List) {
    listToWriter((List) value, writer);
  } else if (value instanceof Map) {
    mapToWriter((Map) value, writer);
  } else {
    writer.value(String.valueOf(value));
  }
}
项目:DietDiaryApp    文件:DriveBackupService.java   
private void writeSettings(@NonNull final JsonWriter writer) throws IOException {
    // Write settings
    writer.name("Settings").beginObject();

    if (mSharedPreferences.contains(KEY_GENERAL_CLOCK_MODE_STRING)) {
        writer.name(KEY_GENERAL_CLOCK_MODE_STRING)
                .value(mSharedPreferences.getString(KEY_GENERAL_CLOCK_MODE_STRING, "-1"));
    }

    if (mSharedPreferences.contains(KEY_NOTIFICATIONS_ACTIVE_BOOL)) {
        writer.name(KEY_NOTIFICATIONS_ACTIVE_BOOL)
                .value(mSharedPreferences.getBoolean(KEY_NOTIFICATIONS_ACTIVE_BOOL, true));
    }

    if (mSharedPreferences.contains(KEY_NOTIFICATIONS_DAILY_REMAINDER_BOOL)) {
        writer.name(KEY_NOTIFICATIONS_DAILY_REMAINDER_BOOL)
                .value(mSharedPreferences.getBoolean(KEY_NOTIFICATIONS_DAILY_REMAINDER_BOOL, true));
    }

    if (mSharedPreferences.contains(KEY_NOTIFICATIONS_DAILY_REMAINDER_TIME_STRING)) {
        writer.name(KEY_NOTIFICATIONS_DAILY_REMAINDER_TIME_STRING)
                .value(mSharedPreferences.getString(KEY_NOTIFICATIONS_DAILY_REMAINDER_TIME_STRING, "19:00"));
    }

    writer.endObject();
}
项目:DietDiaryApp    文件:DriveBackupService.java   
private void writeEvent(@NonNull final JsonWriter writer, @NonNull final String[] types,
                        @NonNull final String[] foodTypes, @NonNull final String[] drinkTypes,
                        @NonNull Event event) throws IOException {
    String subType;
    switch (event.getType()) {
        case Event.TYPE_FOOD:
            subType = foodTypes[event.getSubType()];
            break;
        case Event.TYPE_DRINK:
            subType = drinkTypes[event.getSubType()];
            break;
        default:
            subType = "";
    }

    writer.beginObject();
    writer.name(KEY_ID).value(event.getID());
    writer.name(KEY_DATE).value(event.getDate().toString(DatabaseHelper.DB_DATE_FORMATTER));
    writer.name(KEY_TIME).value(event.getTime().toString(DatabaseHelper.DB_TIME_FORMATTER));
    writer.name(KEY_TYPE).value(types[event.getType()]);
    writer.name(KEY_TITLE).value(subType);
    writer.name(KEY_DESC).value(event.getDescription());
    writer.endObject();
}
项目:peanut-link    文件:User.java   
public String toJson() {
    final StringWriter sw = new StringWriter(256);
    final JsonWriter writer = new JsonWriter(sw);

    try {
        writer.beginObject()
                .name("uuid").value(uuid)
                .name("ucode").value(ucode)
                .name("session").value(session)
                .endObject()
                .close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return sw.toString();
}
项目:FMTech    文件:csf.java   
public final byte[] a(T paramT)
{
  ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
  String str1;
  try
  {
    JsonWriter localJsonWriter = new JsonWriter(new BufferedWriter(new OutputStreamWriter(localByteArrayOutputStream, e), 8192));
    a(localJsonWriter, paramT);
    localJsonWriter.flush();
    return localByteArrayOutputStream.toByteArray();
  }
  catch (IOException localIOException)
  {
    str1 = String.valueOf(getClass().getSimpleName());
    if (str1.length() == 0) {}
  }
  for (String str2 = "Cannot generate JSON using ".concat(str1);; str2 = new String("Cannot generate JSON using ")) {
    throw new RuntimeException(str2, localIOException);
  }
}
项目:nexus-gallery    文件:ImagePreset.java   
public void writeJson(JsonWriter writer, String name) {
    int numFilters = mFilters.size();
    try {
        writer.beginObject();
        for (int i = 0; i < numFilters; i++) {
            FilterRepresentation filter = mFilters.get(i);
            if (filter instanceof FilterUserPresetRepresentation) {
                continue;
            }
            String sname = filter.getSerializationName();
            if (DEBUG) {
                Log.v(LOGTAG, "Serialization: " + sname);
                if (sname == null) {
                    Log.v(LOGTAG, "Serialization name null for filter: " + filter);
                }
            }
            writer.name(sname);
            filter.serializeRepresentation(writer);
        }
        writer.endObject();

    } catch (IOException e) {
       Log.e(LOGTAG,"Error encoding JASON",e);
    }
}
项目:nexus-gallery    文件:FilterGradRepresentation.java   
@Override
public void serializeRepresentation(JsonWriter writer) throws IOException {
    writer.beginObject();
    int len = mBands.size();
    int count = 0;

    for (int i = 0; i < len; i++) {
        Band point = mBands.get(i);
        if (point.mask) {
            continue;
        }
        writer.name(LINE_NAME + count);
        count++;
        writer.beginArray();
        writer.value(point.xPos1);
        writer.value(point.yPos1);
        writer.value(point.xPos2);
        writer.value(point.yPos2);
        writer.value(point.brightness);
        writer.value(point.contrast);
        writer.value(point.saturation);
        writer.endArray();
    }
    writer.endObject();
}
项目:nexus-gallery    文件:FilterChanSatRepresentation.java   
@Override
public void serializeRepresentation(JsonWriter writer) throws IOException {
    writer.beginObject();

    writer.name(ARGS);
    writer.beginArray();
    writer.value(getValue(MODE_MASTER));
    writer.value(getValue(MODE_RED));
    writer.value(getValue(MODE_YELLOW));
    writer.value(getValue(MODE_GREEN));
    writer.value(getValue(MODE_CYAN));
    writer.value(getValue(MODE_BLUE));
    writer.value(getValue(MODE_MAGENTA));
    writer.endArray();
    writer.endObject();
}
项目:nexus-gallery    文件:FilterCurvesRepresentation.java   
@Override
public void serializeRepresentation(JsonWriter writer) throws IOException {
    writer.beginObject();
    {
        writer.name(NAME_TAG);
        writer.value(getName());
        for (int i = 0; i < mSplines.length; i++) {
            writer.name(SERIALIZATION_NAME + i);
            writer.beginArray();
            int nop = mSplines[i].getNbPoints();
            for (int j = 0; j < nop; j++) {
                ControlPoint p = mSplines[i].getPoint(j);
                writer.beginArray();
                writer.value(p.x);
                writer.value(p.y);
                writer.endArray();
            }
            writer.endArray();
        }

    }
    writer.endObject();
}
项目:nexus-gallery    文件:FilterVignetteRepresentation.java   
@Override
public void serializeRepresentation(JsonWriter writer) throws IOException {
    writer.beginObject();
    writer.name(ELLIPSE);
    writer.beginArray();
    writer.value(mCenterX);
    writer.value(mCenterY);
    writer.value(mRadiusX);
    writer.value(mRadiusY);
    writer.endArray();

    writer.name(ARGS);
    writer.beginArray();
    writer.value(mParamVignette.getValue());
    writer.value(mParamExposure.getValue());
    writer.value(mParamSaturation.getValue());
    writer.value(mParamContrast.getValue());
    writer.value(mParamFalloff.getValue());
    writer.endArray();
    writer.endObject();
}
项目:Android-Orma    文件:BuiltInSerializers.java   
/**
 * A generic serializer for string collections.
 *
 * @param collection Collection to serialize
 * @param <C>        A concrete collection class, e.g. {@code ArrayList<String>}.
 * @return JSON representation of the string collection.
 */
@NonNull
public static <C extends Collection<String>> String serializeStringCollection(@NonNull C collection) {
    StringWriter writer = new StringWriter();
    JsonWriter jsonWriter = new JsonWriter(writer);
    try {
        jsonWriter.beginArray();
        for (String s : collection) {
            jsonWriter.value(s);
        }
        jsonWriter.endArray();
        jsonWriter.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return writer.toString();
}
项目:footstep    文件:MainActivity.java   
private void writeToJSON(OutputStream out, Date date, Location loc) throws IOException {
    FileOutputStream outputStream;
    JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
    writer.setIndent("  ");
    writer.beginArray();

    writer.beginObject();
    writer.name("Date").value(date.toString());

    writer.name("Location");
    writer.beginArray();
    writer.value(loc.getLatitude());
    writer.value(loc.getLongitude());
    writer.endArray();

    writer.endObject();
    writer.close();
}
项目:dailyJournal    文件:JsonConverterStream.java   
/**
 * Write passed party to passed Json writer
 * @param writer
 * @param party
 * @throws IOException
 */
public void writeParty(JsonWriter writer, Party party) throws IOException {
    //print open curly braces {
    writer.beginObject();

    //print keys and values
    writer.name(KEY_ID).value(party.getId());
    writer.name(KEY_NAME).value(party.getName());
    writer.name(KEY_PHONE).value(party.getPhone());
    writer.name(KEY_DEBIT).value(party.getDebitTotal());
    writer.name(KEY_CREDIT).value(party.getCreditTotal());
    writer.name(KEY_TYPE).value(party.getType().toString());
    writer.name(KEY_PICTURE).value(party.getPicturePath());

    //print journals
    writeJournals(writer, party.getId());

    //print close curly braces }
    writer.endObject();
}
项目:SchulinfoApp-android    文件:News.java   
@Override
public void save() {
    try {
        OutputStream out = SIAApp.SIA_APP.openFileOutput("news", Context.MODE_PRIVATE);
        JsonWriter writer = new JsonWriter(new OutputStreamWriter(out));

        writer.setIndent("  ");
        writer.beginArray();
        for(Entry s : this) {
            writer.beginObject();

            writer.name("id").value(s.id);
            writer.name("date").value(s.date.getTime());
            writer.name("topic").value(s.topic);
            writer.name("source").value(s.source);
            writer.name("title").value(s.title);
            writer.name("text").value(s.text);

            writer.endObject();
        }
        writer.endArray();
        writer.close();
    } catch(Exception e) {
        e.printStackTrace();
    }
}
项目:SchulinfoApp-android    文件:Mensa.java   
public void save() {
    try {
        OutputStream out = SIAApp.SIA_APP.openFileOutput("mensa", Context.MODE_PRIVATE);
        JsonWriter writer = new JsonWriter(new OutputStreamWriter(out));

        writer.setIndent("  ");
        writer.beginArray();
        for(MensaItem s : this) {
            writer.beginObject();

            writer.name("id").value(s.id);
            writer.name("date").value(s.date);
            writer.name("meal").value(s.meal);
            writer.name("garnish").value(s.garnish);
            writer.name("dessert").value(s.dessert);
            writer.name("vegetarian").value(s.vegetarian);
            writer.name("image").value(s.image);

            writer.endObject();
        }
        writer.endArray();
        writer.close();
    } catch(Exception e) {
        e.printStackTrace();
    }
}
项目:nuntius-android    文件:Message.java   
public String toJSON(Context context) {
    StringWriter out = new StringWriter();
    JsonWriter writer = new JsonWriter(out);

    try {
        writer.beginObject();
        writer.name("event").value(event);

        writer.name("eventItems");
        writer.beginArray();

        if (type == SendType.SMS) {
            toJsonSMessage(context, writer, sMessage);
        } else if (type == SendType.NOTI) {
            for (StatusBarNotification sbn : notifications) {
                toJsonNotification(context, writer, sbn);
            }
        }
        writer.endArray();
        writer.endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return out.toString();
}
项目:nuntius-android    文件:Message.java   
private void toJsonSMessage(Context context, JsonWriter writer, SMessage sMessage) throws IOException {
    writer.beginObject();
    writer.name("id").value("0"); // test value
    writer.name("sender").value(sMessage.getSender());
    writer.name("sender_num").value(sMessage.getSenderNum());
    writer.name("message").value(sMessage.getMessage());

    if (context != null){
        final PackageManager pm = context.getPackageManager();
        try {
            ApplicationInfo ai = pm.getApplicationInfo(Telephony.Sms.getDefaultSmsPackage(context), 0); // require api 19 min is actually 19.

            Bitmap bitmap = toBitmap(pm.getApplicationIcon(ai));
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
            writer.name("icon").value(new String(Base64.encode(stream.toByteArray(), Base64.DEFAULT), "UTF-8"));
        } catch (final PackageManager.NameNotFoundException e) {
            Log.d(TAG, "Could not get the icon and label for the default sms app");
        }
    }
    writer.endObject();
}
项目:nuntius-android    文件:Message.java   
@TargetApi(Build.VERSION_CODES.KITKAT)
private void writeActions(JsonWriter writer, Notification notification) throws IOException {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }

    if (notification.actions != null) {
        Log.d(TAG, "writing action");
        writer.name("actions");
        writer.beginArray();
        for (Notification.Action a : notification.actions) {
            Log.d(TAG, "writing action : " + a.title.toString());
            writer.beginObject();
            writer.name("title").value(a.title.toString());
            writer.endObject();
        }
        writer.endArray();
    }
}
项目:DPR-KITA    文件:ViewSnapshot.java   
private void addProperties(JsonWriter j, View v)
    throws IOException {
    final Class<?> viewClass = v.getClass();
    for (final PropertyDescription desc : mProperties) {
        if (desc.targetClass.isAssignableFrom(viewClass) && null != desc.accessor) {
            final Object value = desc.accessor.applyMethod(v);
            if (null == value) {
                // Don't produce anything in this case
            } else if (value instanceof Number) {
                j.name(desc.name).value((Number) value);
            } else if (value instanceof Boolean) {
                j.name(desc.name).value((Boolean) value);
            } else {
                j.name(desc.name).value(value.toString());
            }
        }
    }
}
项目:LimeLight    文件:JSONTool.java   
/**
 * @param writer
 * @param transition the ChapterTransition object to be written in JSON
 * @throws IOException
 */
public static void writeTransition(JsonWriter writer, ChapterTransition transition) throws IOException {
    writer.beginObject();
    writer.name("type").value("transition");
    writer.name("time").value(transition.getTime());
    writer.name("item_position").value(transition.getItemPosition());
    writer.name("child_id").value(transition.getChildID());
    writer.name("id").value(transition.getAnchorViewID());
    writer.name("message").value(transition.getMessage());
    writer.name("message_res_id").value(transition.getMessageResID());
    writer.name("graphic_res_id").value(transition.getGraphicResID());
    writer.name("is_action_bar_item").value(transition.isInActionBar());
    writer.name("x_offset").value(transition.getWidthRatio());
    writer.name("y_offset").value(transition.getHeightRatio());
    writer.name("text_color").value(transition.getTextColor());
    writer.name("text_background_color").value(transition.getTextBackgroundColor());
    writer.name("text_size").value(transition.getTextSize());
    writer.name("text_background_transparent").value(transition.hasTransparentBackground());
    writer.name("animation").value(transition.getAnimation());
    writer.endObject();
}
项目:LimeLight    文件:JSONTool.java   
/**
 * @param writer
 * @param act the act object to be written into JSON
 * @throws IOException
 */
public static void writeAct(JsonWriter writer, Act act) throws IOException {
    writer.beginObject();
    writer.name("id").value(act.getAnchorViewID());
    writer.name("message").value(act.getMessage());
    writer.name("message_res_id").value(act.getMessageResID());
    writer.name("graphic_res_id").value(act.getGraphicResID());
    writer.name("is_action_bar_item").value(act.isInActionBar());
    writer.name("x_offset").value(act.getWidthRatio());
    writer.name("y_offset").value(act.getHeightRatio());
    writer.name("text_color").value(act.getTextColor());
    writer.name("text_background_color").value(act.getTextBackgroundColor());
    writer.name("text_size").value(act.getTextSize());
    writer.name("text_background_transparent").value(act.hasTransparentBackground());
    writer.name("animation").value(act.getAnimation());
    writer.name("activity_name").value(act.getActivityName());
    writer.endObject();
}
项目:nansai    文件:PersonFileWriter.java   
public boolean write(final List<Person> persons,
        final OutputStream personStream) {
    final OutputStreamWriter ouw = new OutputStreamWriter(personStream,
            Charsets.UTF_8);
    final JsonWriter writer = new JsonWriter(ouw);
    try {
        writer.beginArray();
        for (final Person person : persons) {
            writePerson(person, writer);
        }
        writer.endArray();
        writer.close();
        return true;
    } catch (final IOException e) {
        Closeables.closeQuietly(writer);
    } finally {
        Closeables.closeQuietly(writer);
    }

    return false;
}
项目:Orpheus    文件:PluginLoader.java   
public void writeDisabledPlugins(List<ComponentName> plugins) {
    StringWriter sw = new StringWriter(100);
    JsonWriter jw = new JsonWriter(sw);
    try {
        jw.beginArray();
        for (ComponentName cn : plugins) {
            jw.value(cn.flattenToString());
        }
        jw.endArray();
        Timber.v("Write disabled plugins=" + sw.toString());
        settings.putString(PREF_DISABLED_PLUGINS, sw.toString());
    } catch (IOException e) {
        settings.remove(PREF_DISABLED_PLUGINS);
    } finally {
        IOUtils.closeQuietly(jw);
    }
}
项目:crabapple    文件:StepRelateFragment.java   
public void writeMessagesArray(JsonWriter writer, List<LatLng> mesgs)
        throws IOException {

    writer.beginArray();
    if(null != mesgs) {
        for (LatLng message : mesgs) {
            writeMessage(writer, message);
        }
    } else {
        Log.e(TAG, "file don't contain geo data");
    }
    // record this step place
    writeThisStep(writer);

    writer.endArray();
}
项目:cartographer    文件:Cartographer.java   
/**
 * Serializes the map into it's json representation into the provided {@link Writer}. If you want
 * to retrieve the json as a string,  use {@link #toJson(Map)} instead.
 */
public void toJson(Map<?, ?> map, Writer writer) throws IOException {
  if (map == null) {
    throw new IllegalArgumentException("map == null");
  }
  if (writer == null) {
    throw new IllegalArgumentException("writer == null");
  }

  JsonWriter jsonWriter = new JsonWriter(writer);
  jsonWriter.setLenient(isLenient);
  if (prettyPrint) {
    jsonWriter.setIndent("  ");
  }
  try {
    mapToWriter(map, jsonWriter);
  } finally {
    jsonWriter.close();
  }
}
项目:cartographer    文件:Cartographer.java   
/**
 * Writes the given {@link Object} to the {@link JsonWriter}.
 *
 * @throws IOException
 */
private static void writeValue(Object value, JsonWriter writer) throws IOException {
  if (value == null) {
    writer.nullValue();
  } else if (value instanceof Number) {
    writer.value((Number) value);
  } else if (value instanceof Boolean) {
    writer.value((Boolean) value);
  } else if (value instanceof List) {
    listToWriter((List) value, writer);
  } else if (value instanceof Map) {
    mapToWriter((Map) value, writer);
  } else if (value.getClass().isArray()) {
    arrayToWriter(value, writer);
  } else {
    writer.value(String.valueOf(value));
  }
}