Make space for len bytes. If len is small, allocate a reserve space too. Never grow bigger than the limit or AbstractChunk#ARRAY_MAX_SIZE. @param count The size
(int count)
| 554 | * @param count The size |
| 555 | */ |
| 556 | public void makeSpace(int count) { |
| 557 | int limit = getLimitInternal(); |
| 558 | |
| 559 | long newSize; |
| 560 | long desiredSize = end + count; |
| 561 | |
| 562 | // Can't grow above the limit |
| 563 | if (desiredSize > limit) { |
| 564 | desiredSize = limit; |
| 565 | } |
| 566 | |
| 567 | if (buff == null) { |
| 568 | if (desiredSize < 256) { |
| 569 | desiredSize = 256; // take a minimum |
| 570 | } |
| 571 | buff = new byte[(int) desiredSize]; |
| 572 | } |
| 573 | |
| 574 | // limit < buf.length (the buffer is already big) |
| 575 | // or we already have space |
| 576 | if (desiredSize <= buff.length) { |
| 577 | return; |
| 578 | } |
| 579 | // grow in larger chunks |
| 580 | if (desiredSize < 2L * buff.length) { |
| 581 | newSize = buff.length * 2L; |
| 582 | } else { |
| 583 | newSize = buff.length * 2L + count; |
| 584 | } |
| 585 | |
| 586 | if (newSize > limit) { |
| 587 | newSize = limit; |
| 588 | } |
| 589 | byte[] tmp = new byte[(int) newSize]; |
| 590 | |
| 591 | // Compacts buffer |
| 592 | System.arraycopy(buff, start, tmp, 0, end - start); |
| 593 | buff = tmp; |
| 594 | end = end - start; |
| 595 | start = 0; |
| 596 | } |
| 597 | |
| 598 | |
| 599 | // -------------------- Conversion and getters -------------------- |
no test coverage detected