Exemplo n.º 1
0
 public void a(JsonWriter paramJsonWriter, Map<K, V> paramMap) throws IOException {
   int m = 0;
   int k = 0;
   if (paramMap == null) {
     paramJsonWriter.nullValue();
     return;
   }
   if (!f.a(a)) {
     paramJsonWriter.beginObject();
     paramMap = paramMap.entrySet().iterator();
     while (paramMap.hasNext()) {
       localObject = (Map.Entry) paramMap.next();
       paramJsonWriter.name(String.valueOf(((Map.Entry) localObject).getKey()));
       c.a(paramJsonWriter, ((Map.Entry) localObject).getValue());
     }
     paramJsonWriter.endObject();
     return;
   }
   Object localObject = new ArrayList(paramMap.size());
   ArrayList localArrayList = new ArrayList(paramMap.size());
   paramMap = paramMap.entrySet().iterator();
   int i = 0;
   if (paramMap.hasNext()) {
     Map.Entry localEntry = (Map.Entry) paramMap.next();
     com.google.gson.k localk = b.a(localEntry.getKey());
     ((List) localObject).add(localk);
     localArrayList.add(localEntry.getValue());
     if ((localk.g()) || (localk.h())) {}
     for (int j = 1; ; j = 0) {
       i = j | i;
       break;
     }
   }
   if (i != 0) {
     paramJsonWriter.beginArray();
     i = k;
     while (i < ((List) localObject).size()) {
       paramJsonWriter.beginArray();
       g.a((com.google.gson.k) ((List) localObject).get(i), paramJsonWriter);
       c.a(paramJsonWriter, localArrayList.get(i));
       paramJsonWriter.endArray();
       i += 1;
     }
     paramJsonWriter.endArray();
     return;
   }
   paramJsonWriter.beginObject();
   i = m;
   while (i < ((List) localObject).size()) {
     paramJsonWriter.name(a((com.google.gson.k) ((List) localObject).get(i)));
     c.a(paramJsonWriter, localArrayList.get(i));
     i += 1;
   }
   paramJsonWriter.endObject();
 }
Exemplo n.º 2
0
 @Override
 public void write(JsonWriter out, Quest value) throws IOException {
   out.beginObject();
   out.name(NAME).value(value.getName());
   out.name(DESCRIPTION).value(value.getDescription());
   out.name(X).value(value.getGuiX());
   out.name(Y).value(value.getGuiY());
   if (value.useBigIcon()) {
     out.name(BIG_ICON).value(true);
   }
   if (value.getIcon() != null) {
     MinecraftAdapter.ITEM_STACK.write(out.name(ICON), value.getIcon());
   }
   writeQuestList(
       out, value.getRequirement(), value.getQuestSet().getQuests(), REQUIREMENTS);
   writeQuestList(out, value.getOptionLinks(), value.getQuestSet().getQuests(), OPTIONS);
   if (value.getRepeatInfo().getType() != RepeatType.NONE) {
     REPEAT_INFO_ADAPTER.write(out.name(REPEAT), value.getRepeatInfo());
   }
   if (value.getTriggerType() != TriggerType.NONE) {
     out.name(TRIGGER).value(value.getTriggerType().name());
   }
   if (value.getTriggerType().isUseTaskCount()) {
     out.name(TRIGGER_TASKS).value(value.getTriggerTasks());
   }
   if (value.getUseModifiedParentRequirement()) {
     out.name(PARENT_REQUIREMENT).value(value.getParentRequirementCount());
   }
   out.name(TASKS).beginArray();
   for (QuestTask task : value.getTasks()) {
     TASK_ADAPTER.write(out, task);
   }
   out.endArray();
   writeItemStackArray(
       out,
       (ItemStack[]) ReflectionHelper.getPrivateValue(Quest.class, value, REWARDS),
       REWARDS);
   writeItemStackArray(
       out,
       (ItemStack[]) ReflectionHelper.getPrivateValue(Quest.class, value, REWARDS_CHOICE),
       REWARDS_CHOICE);
   if (value.getReputationRewards() != null && !value.getReputationRewards().isEmpty()) {
     out.name(REWARDS_REPUTATION).beginArray();
     for (Quest.ReputationReward reward : value.getReputationRewards()) {
       REPUTATION_REWARD_ADAPTER.write(out, reward);
     }
     out.endArray();
   }
   out.endObject();
 }
Exemplo n.º 3
0
        @Override
        public void write(JsonWriter out, JsonElement value) throws IOException {
          if (value == null || value.isJsonNull()) {
            out.nullValue();
          } else if (value.isJsonPrimitive()) {
            JsonPrimitive primitive = value.getAsJsonPrimitive();
            if (primitive.isNumber()) {
              out.value(primitive.getAsNumber());
            } else if (primitive.isBoolean()) {
              out.value(primitive.getAsBoolean());
            } else {
              out.value(primitive.getAsString());
            }

          } else if (value.isJsonArray()) {
            out.beginArray();
            for (JsonElement e : value.getAsJsonArray()) {
              write(out, e);
            }
            out.endArray();

          } else if (value.isJsonObject()) {
            out.beginObject();
            for (Map.Entry<String, JsonElement> e : value.getAsJsonObject().entrySet()) {
              out.name(e.getKey());
              write(out, e.getValue());
            }
            out.endObject();

          } else {
            throw new IllegalArgumentException("Couldn't write " + value.getClass());
          }
        }
Exemplo n.º 4
0
  public File executeQuery(String command, String rootDirectory) throws SQLException, IOException {
    Statement stmt = null;
    if (this.conn != null) {
      final String fileName = UUID.randomUUID().toString();
      final File file = File.createTempFile(fileName, ".json");
      try {
        stmt = this.conn.createStatement();
        ResultSet results = stmt.executeQuery(command);
        ResultSetMetaData rsmd = results.getMetaData();

        // Borrowed from
        // http://stackoverflow.com/questions/18960446/how-to-convert-a-java-resultset-into-json
        JsonWriter writer = new JsonWriter(new PrintWriter(file));
        int count = 0;
        int numRows = 0;
        boolean hasRows = results.last();
        if (hasRows) {
          numRows = results.getRow();
        }
        results.beforeFirst();

        writer.beginObject();
        writer.name("elements");
        writer.beginArray();

        while (results.next()) {
          writer.beginObject();
          for (int idx = 1; idx <= rsmd.getColumnCount(); idx++) {
            writer.name(rsmd.getColumnLabel(idx));
            writer.value(results.getString(idx));
          }
          writer.endObject();
          count++;
        }
        if (count == 0) {
          writer.beginObject();
          writer.endObject();
        }
        writer.endArray();
        writer.endObject();

        writer.flush();
        writer.close();
        return file;

      } catch (SQLException e) {
        e.printStackTrace();
        return null;
      } finally {
        if (stmt != null) {
          stmt.close();
        }
      }
    }
    return null;
  }
Exemplo n.º 5
0
 @Override
 public void write(JsonWriter out, QuestTask value) throws IOException {
   out.beginObject();
   TaskType type = TaskType.getType(value.getClass());
   out.name(TYPE).value(type.name());
   if (!value.getDescription().equals(type.name))
     out.name(DESCRIPTION).value(value.getDescription());
   if (!value.getLongDescription().equals(type.description))
     out.name(LONG_DESCRIPTION).value(value.getLongDescription());
   if (value instanceof QuestTaskItems) {
     out.name(ITEMS).beginArray();
     for (QuestTaskItems.ItemRequirement requirement : ((QuestTaskItems) value).getItems()) {
       ITEM_REQUIREMENT_ADAPTER.write(out, requirement);
     }
     out.endArray();
   } else if (value instanceof QuestTaskDeath) {
     out.name(DEATHS).value(((QuestTaskDeath) value).getDeaths());
   } else if (value instanceof QuestTaskLocation) {
     out.name(LOCATIONS).beginArray();
     for (QuestTaskLocation.Location requirement : ((QuestTaskLocation) value).locations) {
       LOCATION_ADAPTER.write(out, requirement);
     }
     out.endArray();
   } else if (value instanceof QuestTaskMob) {
     out.name(MOBS).beginArray();
     for (QuestTaskMob.Mob requirement : ((QuestTaskMob) value).mobs) {
       MOB_ADAPTER.write(out, requirement);
     }
     out.endArray();
   } else if (value instanceof QuestTaskReputation) {
     out.name(REPUTATION).beginArray();
     for (QuestTaskReputation.ReputationSetting requirement :
         ((QuestTaskReputation) value).getSettings()) {
       REPUTATION_ADAPTER.write(out, requirement);
     }
     out.endArray();
     if (value instanceof QuestTaskReputationKill) {
       out.name(KILLS).value(((QuestTaskReputationKill) value).getKills());
     }
   }
   out.endObject();
 }
Exemplo n.º 6
0
 public void writeJson(JsonWriter writer) throws IOException {
   if (messageParts.size() == 1) {
     latest().writeJson(writer);
   } else {
     writer.beginObject().name("text").value("").name("extra").beginArray();
     for (final MessagePart part : this) {
       part.writeJson(writer);
     }
     writer.endArray().endObject();
   }
 }
 @Override
 protected void writeValues(JsonWriter writer, StringFilter value) throws IOException {
   super.writeValues(writer, value);
   writer.name(JsonValues.patterns.name());
   List<Pattern> patterns = ((StringFilter.PatternList) value).getPatterns();
   writer.beginArray();
   for (Pattern pattern : patterns) {
     writer.value(pattern.pattern());
   }
   writer.endArray();
 }
  /*
   * (non-Javadoc)
   *
   * @see com.google.gson.TypeAdapter#write(com.google.gson.stream.JsonWriter, java.lang.Object)
   */
  @Override
  public void write(JsonWriter writer, SpeechTimestamp speechTimestamp) throws IOException {
    writer.beginArray();

    writer.value(speechTimestamp.getWord());
    writer.value(speechTimestamp.getStartTime());
    writer.value(speechTimestamp.getEndTime());

    writer.endArray();
    writer.flush();
  }
Exemplo n.º 9
0
 @Override
 public void write(JsonWriter out, QuestSet value) throws IOException {
   out.beginObject();
   out.name(NAME).value(value.getName());
   out.name(DESCRIPTION).value(value.getDescription());
   out.name(QUESTS).beginArray();
   for (Quest quest : value.getQuests()) {
     QUEST_ADAPTER.write(out, quest);
   }
   out.endArray().endObject();
 }
    public void write(JsonWriter out, Collection<E> collection) throws IOException {
      if (collection == null) {
        out.nullValue(); // TODO: better policy here?
        return;
      }

      out.beginArray();
      for (E element : collection) {
        elementTypeAdapter.write(out, element);
      }
      out.endArray();
    }
Exemplo n.º 11
0
 @Override
 public void writeJson(@NotNull JsonWriter w) throws IOException {
   w.name(NAME);
   w.beginObject();
   w.name("CacheCodes");
   w.beginArray();
   for (String cache : caches) {
     if (cache != null && !cache.isEmpty()) w.value(cache);
   }
   w.endArray();
   w.endObject();
 }
Exemplo n.º 12
0
 private void writeItemStackArray(JsonWriter out, ItemStack[] stacks, String name)
     throws IOException {
   if (stacks != null) {
     out.name(name).beginArray();
     for (ItemStack stack : stacks) {
       if (stack != null) {
         MinecraftAdapter.ITEM_STACK.write(out, stack);
       }
     }
     out.endArray();
   }
 }
Exemplo n.º 13
0
        public void write(JsonWriter out, BitSet src) throws IOException {
          if (src == null) {
            out.nullValue();
            return;
          }

          out.beginArray();
          for (int i = 0; i < src.length(); i++) {
            int value = (src.get(i)) ? 1 : 0;
            out.value(value);
          }
          out.endArray();
        }
Exemplo n.º 14
0
 private void writeQuestList(
     JsonWriter out, List<Quest> quests, List<Quest> setQuests, String name)
     throws IOException {
   List<Quest> inSetQuests = new ArrayList<>(setQuests);
   inSetQuests.retainAll(quests);
   if (!inSetQuests.isEmpty()) {
     out.name(name).beginArray();
     for (Quest quest : inSetQuests) {
       int index = setQuests.indexOf(quest);
       if (index != -1) {
         out.value(index);
       }
     }
     out.endArray();
   }
 }
Exemplo n.º 15
0
 @Override
 public void write(JsonWriter out, Dependency value) throws IOException {
   out.beginObject();
   out.name(PACKAGE_PROPERTY).value(value.getPackage());
   if (value.getVersion() != null) {
     out.name(VERSION_PROPERTY).value(value.getVersion());
     out.name(DEPENDNCY_OP_PROPERTY).value(value.getDependencyOperator().toString());
   }
   if (value.getAlternatives() != null) {
     out.name(ALTERNATIVES_PROPERTY).beginArray();
     for (Dependency dep : value.getAlternatives()) {
       write(out, dep);
     }
     out.endArray();
   }
   out.endObject();
 }
Exemplo n.º 16
0
 @Override
 public void writeJson(JsonWriter json) {
   try {
     json.beginObject();
     this.text.writeJson(json);
     json.name("color").value(this.color.name().toLowerCase());
     for (ChatColor style : this.styles) {
       json.name(stylesToNames.get(style)).value(true);
     }
     if ((this.clickActionName != null) && (this.clickActionData != null)) {
       json.name("clickEvent")
           .beginObject()
           .name("action")
           .value(this.clickActionName)
           .name("value")
           .value(this.clickActionData)
           .endObject();
     }
     if ((this.hoverActionName != null) && (this.hoverActionData != null)) {
       json.name("hoverEvent")
           .beginObject()
           .name("action")
           .value(this.hoverActionName)
           .name("value");
       this.hoverActionData.writeJson(json);
       json.endObject();
     }
     if (this.insertionData != null) {
       json.name("insertion").value(this.insertionData);
     }
     if (!this.translationReplacements.isEmpty()
         && (this.text != null)
         && TextualComponent.isTranslatableText(this.text)) {
       json.name("with").beginArray();
       for (JsonRepresentedObject obj : this.translationReplacements) {
         obj.writeJson(json);
       }
       json.endArray();
     }
     json.endObject();
   } catch (IOException e) {
     Bukkit.getLogger().log(Level.WARNING, "A problem occurred during writing of JSON string", e);
   }
 }
Exemplo n.º 17
0
  @Override
  public void write(final KadMessage msg, final OutputStream out) throws IOException {

    Writer utf8Writer = null;
    JsonWriter writer = null;

    try {

      utf8Writer = new OutputStreamWriter(out, "UTF-8");
      writer = new JsonWriter(utf8Writer);

      writer.beginArray();
      final Class<?> clazz = msg.getClass();
      this.gson.toJson(clazz.getSimpleName(), String.class, writer);
      // System.out.println("writing class: "+clazz);
      this.gson.toJson(msg, clazz, writer);
      writer.endArray();

    } finally {
      writer.close();
      utf8Writer.close();
      out.close();
    }
  }
Exemplo n.º 18
0
  /**
   * When browsing objects, we'd like to make it possible to interface the object type list with a
   * Dojo Data Source. To do so, we stream the objects out as a JSON object.
   *
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
  private void doObjTypeRequestJSON(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    int fromIndex, maxResult;
    Connection c;
    PreparedStatement st;
    ResultSet set;
    JsonWriter jOut;
    int recCount;

    //	Set the content up

    response.setContentType("application/json");

    //	Setup our database information

    c = null;
    st = null;
    set = null;

    //	Setup the rest of our environment

    recCount = 0;

    jOut = new JsonWriter(response.getWriter());

    try {

      //	Parse request parameters

      fromIndex = Integer.parseInt(request.getParameter("start"));
      maxResult = Integer.parseInt(request.getParameter("count"));

      //	Create connection to the database and prep the query

      c = DBResourceManager.getConnection();

      st = c.prepareStatement(OBJTYPE_LIST_JSON);
      st.setInt(1, fromIndex);
      st.setInt(2, maxResult);

      //	Execute the query

      set = st.executeQuery();

      //	Now, stream the results out as if they were an object

      jOut.beginObject();
      jOut.name("items").beginArray();

      while (set.next()) {
        //	Write each element out as an object

        jOut.beginObject();

        jOut.name("objid").value(set.getInt("id"));
        jOut.name("objname").value(set.getString("name"));
        jOut.name("objtilesrc").value(set.getString("tilesrc"));
        jOut.name("description").value(set.getString("description"));

        jOut.endObject();

        //	Increment the record count

        recCount++;
      }

      //	Terminate the array

      jOut.endArray();

      //	Note the number of rows

      jOut.name("numRows").value(recCount);

      //	End the overall object

      jOut.endObject();

      //	Flush the output

      jOut.flush();

    } catch (Exception ex) {
      ex.printStackTrace();

    } finally {

      DataTools.safeCleanUp(c, st, set);
    }
  }