Refine search
/** * Overridable factory method that actually instantiates desired * context object for async (non-blocking) parsing * * @since 2.9.7 */ protected IOContext _createNonBlockingContext(Object srcRef) { // [jackson-core#476]: disable buffer recycling for 2.9 to avoid concurrency issues; // easiest done by just constructing private "recycler": BufferRecycler recycler = new BufferRecycler(); return new IOContext(recycler, srcRef, false); }
/** * @since 2.4 */ public char[] allocTokenBuffer(int minSize) { _verifyAlloc(_tokenCBuffer); return (_tokenCBuffer = _bufferRecycler.allocCharBuffer(BufferRecycler.CHAR_TOKEN_BUFFER, minSize)); }
public void releaseTokenBuffer(char[] buf) { if (buf != null) { _verifyRelease(buf, _tokenCBuffer); _tokenCBuffer = null; _bufferRecycler.releaseCharBuffer(BufferRecycler.CHAR_TOKEN_BUFFER, buf); } }
public char[] allocCharBuffer(int ix, int minSize) { final int DEF_SIZE = charBufferLength(ix); if (minSize < DEF_SIZE) { minSize = DEF_SIZE; } char[] buffer = _charBuffers[ix]; if (buffer == null || buffer.length < minSize) { buffer = calloc(minSize); } else { _charBuffers[ix] = null; } return buffer; }
public byte[] allocByteBuffer(int ix, int minSize) { final int DEF_SIZE = byteBufferLength(ix); if (minSize < DEF_SIZE) { minSize = DEF_SIZE; } byte[] buffer = _byteBuffers[ix]; if (buffer == null || buffer.length < minSize) { buffer = balloc(minSize); } else { _byteBuffers[ix] = null; } return buffer; }
/** *<p> * Note: the method can only be called once during its life cycle. * This is to protect against accidental sharing. */ public byte[] allocReadIOBuffer() { _verifyAlloc(_readIOBuffer); return (_readIOBuffer = _bufferRecycler.allocByteBuffer(BufferRecycler.BYTE_READ_IO_BUFFER)); }
public void releaseBase64Buffer(byte[] buf) { if (buf != null) { // sanity checks, release once-and-only-once, must be one owned _verifyRelease(buf, _base64Buffer); _base64Buffer = null; _bufferRecycler.releaseByteBuffer(BufferRecycler.BYTE_BASE64_CODEC_BUFFER, buf); } }
/** * Main accessor to call for accessing possibly recycled {@link BufferRecycler} instance. */ public static BufferRecycler getBufferRecycler() { SoftReference<BufferRecycler> ref = _recyclerRef.get(); BufferRecycler br = (ref == null) ? null : ref.get(); if (br == null) { br = new BufferRecycler(); if (_bufferRecyclerTracker != null) { ref = _bufferRecyclerTracker.wrapAndTrack(br); } else { ref = new SoftReference<BufferRecycler>(br); } _recyclerRef.set(ref); } return br; }
public final char[] allocCharBuffer(int ix) { return allocCharBuffer(ix, 0); }
/** * @param ix One of <code>READ_IO_BUFFER</code> constants. */ public final byte[] allocByteBuffer(int ix) { return allocByteBuffer(ix, 0); }
/** * Clean up method to call to release all buffers this object may be * using. After calling the method, no other accessors can be used (and * attempt to do so may result in an exception) */ public void release() { reset(); if (_bufferRecycler != null && _currBlock != null) { _bufferRecycler.releaseByteBuffer(BufferRecycler.BYTE_WRITE_CONCAT_BUFFER, _currBlock); _currBlock = null; } }
/** * 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.CHAR_TEXT_BUFFER, buf); } } }
public final byte[] allocByteBuffer(ByteBufferType type) { int ix = type.ordinal(); byte[] buffer = _byteBuffers[ix]; if (buffer == null) { buffer = balloc(type.size); } else { _byteBuffers[ix] = null; } return buffer; }
public final char[] allocCharBuffer(CharBufferType type, int minSize) { if (type.size > minSize) { minSize = type.size; } int ix = type.ordinal(); char[] buffer = _charBuffers[ix]; if (buffer == null || buffer.length < minSize) { buffer = calloc(minSize); } else { _charBuffers[ix] = null; } return buffer; }
/** * @since 2.4 */ public byte[] allocReadIOBuffer(int minSize) { _verifyAlloc(_readIOBuffer); return (_readIOBuffer = _bufferRecycler.allocByteBuffer(BufferRecycler.BYTE_READ_IO_BUFFER, minSize)); }
public void releaseWriteEncodingBuffer(byte[] buf) { if (buf != null) { /* Let's do sanity checks to ensure once-and-only-once release, * as well as avoiding trying to release buffers not owned */ _verifyRelease(buf, _writeEncodingBuffer); _writeEncodingBuffer = null; _bufferRecycler.releaseByteBuffer(BufferRecycler.BYTE_WRITE_ENCODING_BUFFER, buf); } }
/** * Main accessor to call for accessing possibly recycled {@link BufferRecycler} instance. */ public static BufferRecycler getBufferRecycler() { SoftReference<BufferRecycler> ref = _recyclerRef.get(); BufferRecycler br = (ref == null) ? null : ref.get(); if (br == null) { br = new BufferRecycler(); if (_bufferRecyclerTracker != null) { ref = _bufferRecyclerTracker.wrapAndTrack(br); } else { ref = new SoftReference<BufferRecycler>(br); } _recyclerRef.set(ref); } return br; }
public char[] allocCharBuffer(int ix, int minSize) { final int DEF_SIZE = charBufferLength(ix); if (minSize < DEF_SIZE) { minSize = DEF_SIZE; } char[] buffer = _charBuffers[ix]; if (buffer == null || buffer.length < minSize) { buffer = calloc(minSize); } else { _charBuffers[ix] = null; } return buffer; }
public byte[] allocByteBuffer(int ix, int minSize) { final int DEF_SIZE = byteBufferLength(ix); if (minSize < DEF_SIZE) { minSize = DEF_SIZE; } byte[] buffer = _byteBuffers[ix]; if (buffer == null || buffer.length < minSize) { buffer = balloc(minSize); } else { _byteBuffers[ix] = null; } return buffer; }
/** * Helper method used to find a buffer to use, ideally one * recycled earlier. */ private char[] buf(int needed) { if (_allocator != null) { return _allocator.allocCharBuffer(BufferRecycler.CHAR_TEXT_BUFFER, needed); } return new char[Math.max(needed, MIN_SEGMENT_LEN)]; }