@Override public JsonArrayBuilder addAll(JsonArrayBuilder builder) { if (builder == null) { throw new NullPointerException(JsonMessages.ARRBUILDER_ARRAY_BUILDER_NULL()); } if (valueList == null) { valueList = new ArrayList<>(); } valueList.addAll(builder.build()); return this; }
@Override public JsonArrayBuilder add(int index, JsonObjectBuilder builder) { if (builder == null) { throw new NullPointerException(JsonMessages.ARRBUILDER_OBJECT_BUILDER_NULL()); } addValueList(index, builder.build()); return this; }
private void validateValue(Object value) { if (value == null) { throw new NullPointerException(JsonMessages.ARRBUILDER_VALUE_NULL()); } }
@Override public JsonGenerator write(String name, double value) { if (currentContext.scope != Scope.IN_OBJECT) { throw new JsonGenerationException( JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } if (Double.isInfinite(value) || Double.isNaN(value)) { throw new NumberFormatException(JsonMessages.GENERATOR_DOUBLE_INFINITE_NAN()); } writeName(name); writeString(String.valueOf(value)); return this; }
@Override public void close() { if (currentContext.scope != Scope.IN_NONE || currentContext.first) { throw new JsonGenerationException(JsonMessages.GENERATOR_INCOMPLETE_JSON()); } flushBuffer(); try { writer.close(); } catch (IOException ioe) { throw new JsonException(JsonMessages.GENERATOR_CLOSE_IO_ERR(), ioe); } bufferPool.recycle(buf); }
@Override public JsonGenerator writeStartArray() { if (currentContext.scope == Scope.IN_OBJECT) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } if (currentContext.scope == Scope.IN_NONE && !currentContext.first) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_MULTIPLE_TEXT()); } writeComma(); writeChar('['); stack.push(currentContext); currentContext = new Context(Scope.IN_ARRAY); return this; }
private void checkContextForValue() { if ((!currentContext.first && currentContext.scope != Scope.IN_ARRAY && currentContext.scope != Scope.IN_FIELD) || (currentContext.first && currentContext.scope == Scope.IN_OBJECT)) { throw new JsonGenerationException( JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } }
@Override public void flush() { flushBuffer(); try { writer.flush(); } catch (IOException ioe) { throw new JsonException(JsonMessages.GENERATOR_FLUSH_IO_ERR(), ioe); } }
void flushBuffer() { try { if (len > 0) { writer.write(buf, 0, len); len = 0; } } catch (IOException ioe) { throw new JsonException(JsonMessages.GENERATOR_WRITE_IO_ERR(), ioe); } }
@Override public JsonGenerator write(double value) { checkContextForValue(); if (Double.isInfinite(value) || Double.isNaN(value)) { throw new NumberFormatException(JsonMessages.GENERATOR_DOUBLE_INFINITE_NAN()); } writeValue(String.valueOf(value)); popFieldContext(); return this; }
@Override public JsonGenerator writeStartObject() { if (currentContext.scope == Scope.IN_OBJECT) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } if (currentContext.scope == Scope.IN_NONE && !currentContext.first) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_MULTIPLE_TEXT()); } writeComma(); writeChar('{'); stack.push(currentContext); currentContext = new Context(Scope.IN_OBJECT); return this; }
@Override public JsonGenerator write(String name, double value) { if (currentContext.scope != Scope.IN_OBJECT) { throw new JsonGenerationException( JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } if (Double.isInfinite(value) || Double.isNaN(value)) { throw new NumberFormatException(JsonMessages.GENERATOR_DOUBLE_INFINITE_NAN()); } writeName(name); writeString(String.valueOf(value)); return this; }
@Override public void close() { if (currentContext.scope != Scope.IN_NONE || currentContext.first) { throw new JsonGenerationException(JsonMessages.GENERATOR_INCOMPLETE_JSON()); } flushBuffer(); try { writer.close(); } catch (IOException ioe) { throw new JsonException(JsonMessages.GENERATOR_CLOSE_IO_ERR(), ioe); } bufferPool.recycle(buf); }
@Override public JsonGenerator write(String name, BigDecimal value) { if (currentContext.scope != Scope.IN_OBJECT) { throw new JsonGenerationException( JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } writeName(name); writeString(String.valueOf(value)); return this; }
@Override public void flush() { flushBuffer(); try { writer.flush(); } catch (IOException ioe) { throw new JsonException(JsonMessages.GENERATOR_FLUSH_IO_ERR(), ioe); } }
void flushBuffer() { try { if (len > 0) { writer.write(buf, 0, len); len = 0; } } catch (IOException ioe) { throw new JsonException(JsonMessages.GENERATOR_WRITE_IO_ERR(), ioe); } }
@Override public JsonGenerator write(double value) { checkContextForValue(); if (Double.isInfinite(value) || Double.isNaN(value)) { throw new NumberFormatException(JsonMessages.GENERATOR_DOUBLE_INFINITE_NAN()); } writeValue(String.valueOf(value)); popFieldContext(); return this; }
@Override public JsonGenerator writeStartObject() { if (currentContext.scope == Scope.IN_OBJECT) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } if (currentContext.scope == Scope.IN_NONE && !currentContext.first) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_MULTIPLE_TEXT()); } writeComma(); writeChar('{'); stack.push(currentContext); currentContext = new Context(Scope.IN_OBJECT); return this; }
@Override public JsonGenerator write(double value) { if (currentContext.scope != Scope.IN_ARRAY) { throw new JsonGenerationException( JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } if (Double.isInfinite(value) || Double.isNaN(value)) { throw new NumberFormatException(JsonMessages.GENERATOR_DOUBLE_INFINITE_NAN()); } writeValue(String.valueOf(value)); return this; }
public void close() { if (currentContext.scope != Scope.IN_NONE || currentContext.first) { throw new JsonGenerationException(JsonMessages.GENERATOR_INCOMPLETE_JSON()); } flushBuffer(); try { writer.close(); } catch (IOException ioe) { throw new JsonException(JsonMessages.GENERATOR_CLOSE_IO_ERR(), ioe); } bufferPool.recycle(buf); }