Package com.fasterxml.util.membuf.base

Examples of com.fasterxml.util.membuf.base.BytesSegment


    }

    @Override
    public BytesSegment finishReading()
    {
        BytesSegment result = super.finishReading();
        // clear write pointer for further reuse
        _buffer.clear();
        // and drop reference to read-wrapper:
        _readBuffer = null;
        return result;
View Full Code Here


        @Override
        protected BytesSegment _allocateSegment()
        {
            // can reuse a segment returned earlier?
            if (_reusableSegmentCount > 0) {
                BytesSegment segment = _firstReusableSegment;
                _firstReusableSegment = segment.getNext();
                ++_bufferOwnedSegmentCount;
                --_reusableSegmentCount;
                return segment;
            }
            BytesSegment segment = new ByteBufferBytesSegment(_segmentSize, _cfgAllocateNative);
            ++_bufferOwnedSegmentCount;
            return segment;
        }
View Full Code Here

                // ok, but are allowed to grow that big?
                if ((_usedSegmentsCount + _freeSegmentCount + segmentsToAlloc) > _maxSegmentsToAllocate) {
                    return false;
                }
                // if we are, let's try allocate: will be added to "free" segments first, then used
                BytesSegment newFree = _segmentAllocator.allocateSegments(segmentsToAlloc, _firstFreeSegment);
                if (newFree == null) {
                    return false;
                }
                _freeSegmentCount += segmentsToAlloc;
                _firstFreeSegment = newFree;
View Full Code Here

    protected void _doAppendChunked(byte[] buffer, int offset, int length)
    {
        if (length < 1) {
            return;
        }
        BytesSegment seg = _head;
        while (true) {
            int actual = seg.tryAppend(buffer, offset, length);
            offset += actual;
            length -= actual;
            if (length == 0) { // complete, can leave
                return;
            }
            // otherwise, need another segment, so complete current write
            seg.finishWriting();
            // and allocate, init-for-writing new one:
            BytesSegment newSeg = _reuseFree().initForWriting();
            seg.relink(newSeg);
            _head = seg = newSeg;
        }
    }
View Full Code Here

        if (_freeSegmentCount <= 0) { // no local buffers available yet
            if (_usedSegmentsCount >= _maxSegmentsToAllocate) { // except we are maxed out
                return false;
            }
            // if we are, let's try allocate: will be added to "free" segments first, then used
            BytesSegment newFree = _segmentAllocator.allocateSegments(1, _firstFreeSegment);
            if (newFree == null) {
                return false;
            }
            _freeSegmentCount += 1;
            _firstFreeSegment = newFree;
        }
        // should be set now so:
        final BytesSegment seg = _head;
        seg.finishWriting();
        // and allocate, init-for-writing new one:
        BytesSegment newSeg = _reuseFree().initForWriting();
        seg.relink(newSeg);
        _head = newSeg;
        if (!_head.tryAppend(value)) {
            throw new IllegalStateException("Should have room for a byte after allocation");
        }
View Full Code Here

                // ok, but are allowed to grow that big?
                if ((_usedSegmentsCount + _freeSegmentCount + segmentsToAlloc) > _maxSegmentsToAllocate) {
                    return false;
                }
                // if we are, let's try allocate: will be added to "free" segments first, then used
                BytesSegment newFree = _segmentAllocator.allocateSegments(segmentsToAlloc, _firstFreeSegment);
                if (newFree == null) {
                    return false;
                }
                _freeSegmentCount += segmentsToAlloc;
                _firstFreeSegment = newFree;
View Full Code Here

    protected void _doAppendChunked(byte[] buffer, int offset, int length)
    {
        if (length < 1) {
            return;
        }
        BytesSegment seg = _head;
        while (true) {
            int actual = seg.tryAppend(buffer, offset, length);
            offset += actual;
            length -= actual;
            if (length == 0) { // complete, can leave
                return;
            }
            // otherwise, need another segment, so complete current write
            seg.finishWriting();
            // and allocate, init-for-writing new one:
            BytesSegment newSeg = _reuseFree().initForWriting();
            seg.relink(newSeg);
            _head = seg = newSeg;
        }
    }
View Full Code Here

        @Override
        protected BytesSegment _allocateSegment()
        {
            // can reuse a segment returned earlier?
            if (_reusableSegmentCount > 0) {
                BytesSegment segment = _firstReusableSegment;
                _firstReusableSegment = segment.getNext();
                ++_bufferOwnedSegmentCount;
                --_reusableSegmentCount;
                return segment;
            }
            ArrayBytesSegment segment = new ArrayBytesSegment(_segmentSize);
View Full Code Here

TOP

Related Classes of com.fasterxml.util.membuf.base.BytesSegment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.