Package com.google.gson.stream

Examples of com.google.gson.stream.JsonWriter.beginArray()


            try (JsonWriter jsonWriter = new JsonWriter(new BufferedWriter(writer))) {
                if (object instanceof GeneratedMessage) {
                    ProtobufJsonWriter.serialize((GeneratedMessage) object, jsonWriter);
                } else {
                    Iterable<? extends Message> iterable = (Iterable<? extends Message>) object;
                    jsonWriter.beginArray();
                    for (Message msg : iterable) {
                        ProtobufJsonWriter.serialize(msg, jsonWriter);
                    }
                    jsonWriter.endArray();
                }
View Full Code Here


      try {
        Files.createParentDirs(workFile);
        JsonWriter writer =
            new JsonWriter(new OutputStreamWriter(new FileOutputStream(workFile), Charsets.UTF_8));
        writer.setIndent("  ")// always pretty print
        writer.beginArray();
        this.writer = Optional.of(writer);
      } catch (IOException e) {
        logger.log(SEVERE, String.format(
            "An error occured writing trial %s. Results in %s will be incomplete.", trial.id(),
            resultFile), e);
View Full Code Here

    try {
      File dataFile = getDataFile();
      dataFile.getParentFile().mkdirs();
      JsonWriter writer = new JsonWriter(new FileWriter(dataFile, false));
      writer.setIndent("  ");
      writer.beginArray();
      for (List<Channel> chanList : instance.channels.values()) {
        for (Channel chan : chanList) {
          writer.beginObject();
          writer.name("name").value(chan.getName());
          if(chan.getUser() != null) {
View Full Code Here

        event = events.peekFirst();

        try {
          JsonWriter jsonWriter = new JsonWriter(writer);
          jsonWriter.setIndent("  ");
          jsonWriter.beginArray();
          jsonWriter.value(event.getType().name());
          gson.toJson(event, event.getClass(), jsonWriter);
          jsonWriter.endArray();
          writer.write("\n\n");
        } catch (Throwable t) {
View Full Code Here

        FileOutputStream outputStream = new FileOutputStream(dataFile);
        JsonWriter writer = new JsonWriter(new OutputStreamWriter(
            outputStream, "UTF-8"));
        writer.setSerializeNulls(true);
        writer.setIndent("    ");
        writer.beginArray();
        for (Map.Entry<UUID, WorkerInfo> i : workerStack.entrySet()) {
          adapter.setCurrentUUID(i.getKey());
          serializer.toJson(i.getValue(), WorkerInfo.class, writer);
        }
        writer.endArray();
View Full Code Here

                               ImmutableMultimap.of(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=utf-8"));
      ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
      JsonWriter jsonWriter = new JsonWriter(new OutputStreamWriter(new ChannelBufferOutputStream(buffer),
                                                                    Charsets.UTF_8));
      // Response is an array of stream event
      jsonWriter.beginArray();
      while (limit > 0 && eventsRead > 0) {
        limit -= eventsRead;

        for (StreamEvent event : events) {
          GSON.toJson(event, StreamEvent.class, jsonWriter);
View Full Code Here

        event = events.peekFirst();

        try {
          JsonWriter jsonWriter = new JsonWriter(writer);
          jsonWriter.setIndent("  ");
          jsonWriter.beginArray();
          jsonWriter.value(event.getType().name());
          gson.toJson(event, event.getClass(), jsonWriter);
          jsonWriter.endArray();
        } catch (Throwable t) {
          Closeables.closeQuietly(writer);
View Full Code Here

        event = events.peekFirst();

        try {
          JsonWriter jsonWriter = new JsonWriter(writer);
          jsonWriter.setIndent("  ");
          jsonWriter.beginArray();
          jsonWriter.value(event.getType().name());
          gson.toJson(event, event.getClass(), jsonWriter);
          jsonWriter.endArray();
        } catch (Throwable t) {
          Closeables.close(writer, false);
View Full Code Here

        event = events.peekFirst();

        try {
          JsonWriter jsonWriter = new JsonWriter(writer);
          jsonWriter.setIndent("  ");
          jsonWriter.beginArray();
          jsonWriter.value(event.getType().name());
          gson.toJson(event, event.getClass(), jsonWriter);
          jsonWriter.endArray();
          jsonWriter.flush();
        } catch (Throwable t) {
View Full Code Here

                Collection<Variable> vars = variables.get(name);

                writer.name(name);
                if (vars.size() > 1) {
                    // Only render as an array if we have a name collision
                    writer.beginArray();
                }
                for (Variable variable : vars) {
                    Formatter formatter = _snitch.getFormatter(variable);
                    formatter.format(variable.getValue(), writer);
                }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.