/** * Append either the value <code>true</code> or the value * <code>false</code>.<p> * * @param b a boolean * @return this * @throws JSONException if something goes wrong */ public JSONWriter value(boolean b) throws JSONException { return append(b ? "true" : "false"); }
/** * End an array. This method most be called to balance calls to * <code>array</code>.<p> * * @return this * @throws JSONException if incorrectly nested */ public JSONWriter endArray() throws JSONException { return this.end('a', ']'); }
/** * Append a double value.<p> * * @param d a double * @return this * @throws JSONException if the number is not finite */ public JSONWriter value(double d) throws JSONException { return this.value(new Double(d)); }
/** * Begin appending a new object.<p> * * All keys and values until the balancing * <code>endObject</code> will be appended to this object. The * <code>endObject</code> method must be called to mark the object's end.<p> * * @return this * @throws JSONException if the nesting is too deep, or if the object is * started in the wrong place (for example as a key or after the end of the * outermost array or object) */ public JSONWriter object() throws JSONException { if (m_mode == 'i') { m_mode = 'o'; } if ((m_mode == 'o') || (m_mode == 'a')) { append("{"); push('k'); m_comma = false; return this; } throw new JSONException("Misplaced object."); }
/** * End something.<p> * * @param m mode * @param c closing character * @return this * @throws JSONException if unbalanced */ private JSONWriter end(char m, char c) throws JSONException { if (m_mode != m) { throw new JSONException(m == 'o' ? "Misplaced endObject." : "Misplaced endArray."); } pop(m); try { m_writer.write(c); } catch (IOException e) { throw new JSONException(e); } m_comma = true; return this; }
/** * Begin appending a new array.<p> * * All values until the balancing * <code>endArray</code> will be appended to this array. The * <code>endArray</code> method must be called to mark the array's end.<p> * * @return this * @throws JSONException if the nesting is too deep, or if the object is * started in the wrong place (for example as a key or after the end of the * outermost array or object) */ public JSONWriter array() throws JSONException { if ((m_mode == 'i') || (m_mode == 'o') || (m_mode == 'a')) { push('a'); append("["); m_comma = false; return this; } throw new JSONException("Misplaced array."); }
/** * End something.<p> * * @param m mode * @param c closing character * @return this * @throws JSONException if unbalanced */ private JSONWriter end(char m, char c) throws JSONException { if (this.m_mode != m) { throw new JSONException(m == 'o' ? "Misplaced endObject." : "Misplaced endArray."); } this.pop(m); try { this.m_writer.write(c); } catch (IOException e) { throw new JSONException(e); } this.m_comma = true; return this; }
/** * Begin appending a new array.<p> * * All values until the balancing * <code>endArray</code> will be appended to this array. The * <code>endArray</code> method must be called to mark the array's end.<p> * * @return this * @throws JSONException if the nesting is too deep, or if the object is * started in the wrong place (for example as a key or after the end of the * outermost array or object) */ public JSONWriter array() throws JSONException { if (this.m_mode == 'i' || this.m_mode == 'o' || this.m_mode == 'a') { this.push('a'); this.append("["); this.m_comma = false; return this; } throw new JSONException("Misplaced array."); }
/** * Append either the value <code>true</code> or the value * <code>false</code>.<p> * * @param b a boolean * @return this * @throws JSONException if something goes wrong */ public JSONWriter value(boolean b) throws JSONException { return this.append(b ? "true" : "false"); }
/** * End an object. This method most be called to balance calls to * <code>object</code>.<p> * * @return this * @throws JSONException if incorrectly nested */ public JSONWriter endObject() throws JSONException { return end('k', '}'); }
/** * Append a double value.<p> * * @param d a double * @return this * @throws JSONException if the number is not finite */ public JSONWriter value(double d) throws JSONException { return this.value(new Double(d)); }
/** * Begin appending a new object.<p> * * All keys and values until the balancing * <code>endObject</code> will be appended to this object. The * <code>endObject</code> method must be called to mark the object's end.<p> * * @return this * @throws JSONException if the nesting is too deep, or if the object is * started in the wrong place (for example as a key or after the end of the * outermost array or object) */ public JSONWriter object() throws JSONException { if (this.m_mode == 'i') { this.m_mode = 'o'; } if (this.m_mode == 'o' || this.m_mode == 'a') { this.append("{"); this.push('k'); this.m_comma = false; return this; } throw new JSONException("Misplaced object."); }
/** * Append a long value.<p> * * @param l a long * @return this * @throws JSONException if something goes wrong */ public JSONWriter value(long l) throws JSONException { return append(Long.toString(l)); }
/** * End an object. This method most be called to balance calls to * <code>object</code>.<p> * * @return this * @throws JSONException if incorrectly nested */ public JSONWriter endObject() throws JSONException { return this.end('k', '}'); }
/** * Append a long value.<p> * * @param l a long * @return this * @throws JSONException if something goes wrong */ public JSONWriter value(long l) throws JSONException { return this.append(Long.toString(l)); }
/** * End an array. This method most be called to balance calls to * <code>array</code>.<p> * * @return this * @throws JSONException if incorrectly nested */ public JSONWriter endArray() throws JSONException { return end('a', ']'); }
/** * Append an object value.<p> * * @param o the object to append. It can be null, or a Boolean, Number, * String, JSONObject, or JSONArray, or an object with a toJSONString() * method * @return this * @throws JSONException if the value is out of sequence */ public JSONWriter value(Object o) throws JSONException { return append(JSONObject.valueToString(o)); }
/** * Append an object value.<p> * * @param o the object to append. It can be null, or a Boolean, Number, * String, JSONObject, or JSONArray, or an object with a toJSONString() * method * @return this * @throws JSONException if the value is out of sequence */ public JSONWriter value(Object o) throws JSONException { return this.append(JSONObject.valueToString(o)); }