if (textBuffer == null) { _textBuffer = textBuffer = new TextBuffer(null); char[] outputBuffer = textBuffer.emptyAndGetCurrentSegment(); final int[] escCodes = sOutputEscapes128; final int escCodeCount = escCodes.length; outputBuffer = textBuffer.finishCurrentSegment(); outPtr = 0; System.arraycopy(_quoteBuffer, 0, outputBuffer, outPtr, first); outputBuffer = textBuffer.finishCurrentSegment(); int second = length - first; System.arraycopy(_quoteBuffer, first, outputBuffer, outPtr, second); textBuffer.setCurrentLength(outPtr); return textBuffer.contentsAsArray();
private final void _parseSlowFloatValue(int expType) throws IOException, JsonParseException { /* Nope: floating point. Here we need to be careful to get * optimal parsing strategy: choice is between accurate but * slow (BigDecimal) and lossy but fast (Double). For now * let's only use BD when explicitly requested -- it can * still be constructed correctly at any point since we do * retain textual representation */ try { if (expType == NR_BIGDECIMAL) { _numberBigDecimal = _textBuffer.contentsAsDecimal(); _numTypesValid = NR_BIGDECIMAL; } else { // Otherwise double has to do _numberDouble = _textBuffer.contentsAsDouble(); _numTypesValid = NR_DOUBLE; } } catch (NumberFormatException nex) { // Can this ever occur? Due to overflow, maybe? _wrapError("Malformed numeric value '"+_textBuffer.contentsAsString()+"'", nex); } }
char[] cbuf = _textBuffer.emptyAndGetCurrentSegment(); int cix = 0; ch -= 0x10000; // to normalize it starting with 0x0 if (cix >= cbuf.length) { cbuf = _textBuffer.expandCurrentSegment(); cbuf = _textBuffer.expandCurrentSegment();
/** * Main access method that will construct a String that contains * all the contents, release all internal buffers we may have, * and return result String. * Note that the method is not idempotent -- if called second time, * will just return an empty String. */ public String getAndClear() { String result = _buffer.contentsAsString(); _buffer.releaseBuffers(); return result; } }
throws IOException, JsonParseException _textBuffer.resetWithShared(_inputBuffer, startPtr, (_inputPtr - startPtr)); char[] outBuf = _textBuffer.getCurrentSegment(); int outPtr = _textBuffer.getCurrentSegmentSize(); final int maxCode = codes.length; outBuf = _textBuffer.finishCurrentSegment(); outPtr = 0; _textBuffer.setCurrentLength(outPtr); char[] buf = tb.getTextBuffer(); int start = tb.getTextOffset(); int len = tb.size();
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment(); outBuf = _textBuffer.finishCurrentSegment(); outPtr = 0; outBuf = _textBuffer.finishCurrentSegment(); outPtr = 0; outBuf = _textBuffer.finishCurrentSegment(); outPtr = 0; _textBuffer.setCurrentLength(outPtr);
throws IOException, JsonParseException char[] outBuf = _textBuffer.emptyAndGetCurrentSegment(); int outPtr = _textBuffer.getCurrentSegmentSize(); outBuf = _textBuffer.finishCurrentSegment(); outPtr = 0; _textBuffer.setCurrentLength(outPtr); return JsonToken.VALUE_STRING;
protected void _finishString2() throws IOException, JsonParseException char[] outBuf = _textBuffer.getCurrentSegment(); int outPtr = _textBuffer.getCurrentSegmentSize(); outBuf = _textBuffer.finishCurrentSegment(); outPtr = 0; _textBuffer.setCurrentLength(outPtr);
_textBuffer.setCurrentLength(outPtr); return resetInt(negative, intPartLength); outBuf = _textBuffer.finishCurrentSegment(); outPtr = 0; _textBuffer.setCurrentLength(outPtr);
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment(); final int[] codes = sInputCodesUtf8; if (c == INT_QUOTE) { _inputPtr = ptr+1; _textBuffer.setCurrentLength(outPtr); return;
public char[] getTextBuffer() { // Are we just using shared input buffer? if (_inputStart >= 0) { return _inputBuffer; } if (_resultArray != null) { return _resultArray; } if (_resultString != null) { return (_resultArray = _resultString.toCharArray()); } // Nope; but does it fit in just one segment? if (!_hasSegments) { return _currentSegment; } // Nope, need to have/create a non-segmented array and return it return contentsAsArray(); }
public SegmentedStringWriter(BufferRecycler br) { super(); _buffer = new TextBuffer(br); }
/** * Note: calling this method may not be as efficient as calling * {@link #contentsAsString}, since it's not guaranteed that resulting * String is cached. */ @Override public String toString() { return contentsAsString(); }
return _textBuffer.getTextBuffer();
@Override public int getTextLength() throws IOException, JsonParseException { if (_currToken != null) { // null only before/after document switch (_currToken) { case FIELD_NAME: return _parsingContext.getCurrentName().length(); case VALUE_STRING: if (_tokenIncomplete) { _tokenIncomplete = false; _finishString(); // only strings can be incomplete } // fall through case VALUE_NUMBER_INT: case VALUE_NUMBER_FLOAT: return _textBuffer.size(); default: return _currToken.asCharArray().length; } } return 0; }
_textBuffer.resetWithString(text); _currToken = JsonToken.VALUE_STRING; return text; if (typeBits == 0x00) { _inputPtr = ptr; _textBuffer.resetWithEmpty(); _currToken = JsonToken.VALUE_STRING; return ""; if (_seenStringValueCount >= 0) { // shared text values enabled if (_seenStringValueCount < _seenStringValues.length) { text = _textBuffer.contentsAsString(); _seenStringValues[_seenStringValueCount++] = text; } else { _expandSeenStringValues(); text = _textBuffer.contentsAsString(); text = _textBuffer.contentsAsString(); if (_seenStringValueCount >= 0) { // shared text values enabled if (_seenStringValueCount < _seenStringValues.length) { text = _textBuffer.contentsAsString(); _seenStringValues[_seenStringValueCount++] = text; } else { _expandSeenStringValues(); text = _textBuffer.contentsAsString(); text = _textBuffer.contentsAsString();
char[] buf = _textBuffer.getTextBuffer(); int offset = _textBuffer.getTextOffset(); int len = _intLength; if (_numberNegative) {
/** * Method called to indicate that the underlying buffers should now * be recycled if they haven't yet been recycled. Although caller * can still use this text buffer, it is not advisable to call this * method if that is likely, since next time a buffer is needed, * buffers need to reallocated. * Note: calling this method automatically also clears contents * of the buffer. */ public void releaseBuffers() { if (_allocator == null) { resetWithEmpty(); } else { if (_currentSegment != null) { // First, let's get rid of all but the largest char array resetWithEmpty(); // And then return that array char[] buf = _currentSegment; _currentSegment = null; _allocator.releaseCharBuffer(BufferRecycler.CharBufferType.TEXT_BUFFER, buf); } } }
return NO_CHARS; result = _charArray(_inputLen); System.arraycopy(_inputBuffer, _inputStart, result, 0, _inputLen); } else { // nope int size = size(); if (size < 1) { return NO_CHARS; result = _charArray(size); if (_segments != null) { for (int i = 0, len = _segments.size(); i < len; ++i) {
public char[] emptyAndGetCurrentSegment() { resetWithEmpty(); char[] curr = _currentSegment; if (curr == null) { _currentSegment = curr = allocBuffer(0); } return curr; }