_writer.write(buf, 0, 2); return; buf[12] = HEX_CHARS[lo >> 4]; buf[13] = HEX_CHARS[lo & 0xF]; _writer.write(buf, 8, 6); } else { // We know it's a control char, so only the last 2 chars are non-0 buf[6] = HEX_CHARS[ch >> 4]; buf[7] = HEX_CHARS[ch & 0xF]; _writer.write(buf, 2, 6); escape = _characterEscapes.getEscapeSequence(ch).getValue(); } else { escape = _currentEscape.getValue(); _currentEscape = null;
@Override protected final void _verifyValueWrite(String typeMsg) throws IOException final int status = _writeContext.writeValue(); if (_cfgPrettyPrinter != null) { _verifyPrettyValueWrite(typeMsg, status); return; case JsonWriteContext.STATUS_OK_AFTER_SPACE: // root-value separator if (_rootValueSeparator != null) { byte[] raw = _rootValueSeparator.asUnquotedUTF8(); if (raw.length > 0) { _writeBytes(raw); _reportCantWriteValueExpectName(typeMsg); return;
protected final void _writePPFieldName(SerializableString name) throws IOException { final int status = _writeContext.writeFieldName(name.getValue()); if (status == JsonWriteContext.STATUS_EXPECT_VALUE) { _reportError("Can not write a field name, expecting a value"); } if (status == JsonWriteContext.STATUS_OK_AFTER_COMMA) { _cfgPrettyPrinter.writeObjectEntrySeparator(this); } else { _cfgPrettyPrinter.beforeObjectEntries(this); } final boolean addQuotes = !_cfgUnqNames; // standard if (addQuotes) { if (_outputTail >= _outputEnd) { _flushBuffer(); } _outputBuffer[_outputTail++] = _quoteChar; } _writeBytes(name.asQuotedUTF8()); if (addQuotes) { if (_outputTail >= _outputEnd) { _flushBuffer(); } _outputBuffer[_outputTail++] = _quoteChar; } }
private final void _writeUnq(SerializableString name) throws IOException { int len = name.appendQuotedUTF8(_outputBuffer, _outputTail); if (len < 0) { _writeBytes(name.asQuotedUTF8()); } else { _outputTail += len; } }
@Override public void writeRaw(SerializableString text) throws IOException { int len = text.appendUnquotedUTF8(_outputBuffer, _outputTail); if (len < 0) { _writeBytes(text.asUnquotedUTF8()); } else { _outputTail += len; } }
@Override public void writeRawValue(SerializableString text) throws IOException { _verifyValueWrite(WRITE_RAW); int len = text.appendUnquotedUTF8(_outputBuffer, _outputTail); if (len < 0) { _writeBytes(text.asUnquotedUTF8()); } else { _outputTail += len; } }
private void _writeString2(SerializableString sstr) throws IOException { // Note: copied from writeRaw: char[] text = sstr.asQuotedChars(); final int len = text.length; if (len < SHORT_WRITE) { int room = _outputEnd - _outputTail; if (len > room) { _flushBuffer(); } System.arraycopy(text, 0, _outputBuffer, _outputTail, len); _outputTail += len; } else { _flushBuffer(); _writer.write(text, 0, len); } if (_outputTail >= _outputEnd) { _flushBuffer(); } _outputBuffer[_outputTail++] = _quoteChar; }
@Override public void writeString(SerializableString value) throws IOException { if (_itemFilter == null) { return; } if (_itemFilter != TokenFilter.INCLUDE_ALL) { TokenFilter state = _filterContext.checkValue(_itemFilter); if (state == null) { return; } if (state != TokenFilter.INCLUDE_ALL) { if (!state.includeString(value.getValue())) { return; } } _checkParentPath(); } delegate.writeString(value); }
@Override public void writeFieldName(SerializableString name) throws IOException { TokenFilter state = _filterContext.setFieldName(name.getValue()); if (state == null) { _itemFilter = null; return; } if (state == TokenFilter.INCLUDE_ALL) { _itemFilter = state; delegate.writeFieldName(name); return; } state = state.includeProperty(name.getValue()); _itemFilter = state; if (state == TokenFilter.INCLUDE_ALL) { _checkPropertyParentPath(); } }
/** * Method similar to {@link #writeRawValue(String)}, but potentially more * efficient as it may be able to use pre-encoded content (similar to * {@link #writeRaw(SerializableString)}. * * @since 2.5 */ public void writeRawValue(SerializableString raw) throws IOException { writeRawValue(raw.getValue()); }
_writePPFieldName(name); return; final int status = _writeContext.writeFieldName(name.getValue()); if (status == JsonWriteContext.STATUS_EXPECT_VALUE) { _reportError("Can not write a field name, expecting a value"); _flushBuffer(); int len = name.appendQuotedUTF8(_outputBuffer, _outputTail); if (len < 0) { // couldn't append, bit longer processing _writeBytes(name.asQuotedUTF8()); } else { _outputTail += len;
/** * Method that will force generator to copy * input text verbatim with <b>no</b> modifications (including * that no escaping is done and no separators are added even * if context [array, object] would otherwise require such). * If such separators are desired, use * {@link #writeRawValue(String)} instead. *<p> * Note that not all generator implementations necessarily support * such by-pass methods: those that do not will throw * {@link UnsupportedOperationException}. *<p> * The default implementation delegates to {@link #writeRaw(String)}; * other backends that support raw inclusion of text are encouraged * to implement it in more efficient manner (especially if they * use UTF-8 encoding). * * @since 2.1 */ public void writeRaw(SerializableString raw) throws IOException { writeRaw(raw.getValue()); }
@Override public final void writeFieldName(SerializableString name) throws IOException { // Object is a value, need to verify it's allowed if (_writeContext.writeFieldName(name.getValue()) == JsonWriteContext.STATUS_EXPECT_VALUE) { _reportError("Can not write a field name, expecting a value"); } _writeFieldName(name.getValue()); }
@Override public final void writeFieldName(SerializableString name) throws IOException, JsonGenerationException { // Object is a value, need to verify it's allowed int status = _writeContext.writeFieldName(name.getValue()); if (status == JsonWriteContext.STATUS_EXPECT_VALUE) { _reportError("Can not write a field name, expecting a value"); } if (_cfgPrettyPrinter != null) { _writePPFieldName(name, (status == JsonWriteContext.STATUS_OK_AFTER_COMMA)); return; } if (status == JsonWriteContext.STATUS_OK_AFTER_COMMA) { if (_outputTail >= _outputEnd) { _flushBuffer(); } _outputBuffer[_outputTail++] = BYTE_COMMA; } _writeFieldName(name); }
@Override protected final void _verifyValueWrite(String typeMsg) throws IOException final int status = _writeContext.writeValue(); if (_cfgPrettyPrinter != null) { case JsonWriteContext.STATUS_OK_AFTER_SPACE: // root-value separator if (_rootValueSeparator != null) { writeRaw(_rootValueSeparator.getValue());
/** * @since 2.1 */ public String getRootValueSeparator() { return (_rootValueSeparator == null) ? null : _rootValueSeparator.getValue(); }
@Override public final void writeString(SerializableString text) throws IOException { _verifyValueWrite(WRITE_STRING); if (_outputTail >= _outputEnd) { _flushBuffer(); } _outputBuffer[_outputTail++] = _quoteChar; int len = text.appendQuotedUTF8(_outputBuffer, _outputTail); if (len < 0) { _writeBytes(text.asQuotedUTF8()); } else { _outputTail += len; } if (_outputTail >= _outputEnd) { _flushBuffer(); } _outputBuffer[_outputTail++] = _quoteChar; }
int c = string.charAt(i); if (c <= 0x7F && _outputEscapes[c] == CharacterEscapes.ESCAPE_CUSTOM) { SerializableString escape = _characterEscapes.getEscapeSequence(c); if (escape == null) { _reportError("Invalid custom escape definitions; custom escape " sb.append(escape.getValue());
if (i == INT_QUOTE) { byte[] nameBytes = str.asQuotedUTF8(); final int len = nameBytes.length; while (true) { if (ptr == end) { // yes, match! _parsingContext.setCurrentName(str.getValue()); i = _skipColonFast(ptr+1); _isNextTokenNameYes(i);
if (i == INT_QUOTE) { char[] nameChars = sstr.asQuotedChars(); final int len = nameChars.length; while (true) { if (ptr == end) { // yes, match! _parsingContext.setCurrentName(sstr.getValue()); _isNextTokenNameYes(_skipColonFast(ptr+1)); return true; return _isNextTokenNameMaybe(i, sstr.getValue());