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(); }
@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()); } }
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; }
/* * (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(); }
@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(); }
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(); }
@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(); }
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(); }
@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(); } }