/** * Ensures that this array list can contain the given number of entries without * resizing. * * @param capacity * the new minimum capacity for this array list. */ public void ensureCapacity(final int capacity) { if (capacity <= a.length || a == ByteArrays.DEFAULT_EMPTY_ARRAY) return; a = ByteArrays.ensureCapacity(a, capacity, size); assert size <= a.length; } /**
/** * Ensures that an array can contain the given number of entries. * * <p> * If you cannot foresee whether this array will need again to be enlarged, you * should probably use {@code grow()} instead. * * @param array * an array. * @param length * the new minimum length for this array. * @return {@code array}, if it contains {@code length} entries or more; * otherwise, an array with {@code length} entries whose first * {@code array.length} entries are the same as those of {@code array}. */ public static byte[] ensureCapacity(final byte[] array, final int length) { return ensureCapacity(array, length, array.length); } /**
/** * Sets the length of the given array. * * @param array * an array. * @param length * the new length for the array. * @return {@code array}, if it contains exactly {@code length} entries; * otherwise, if it contains <em>more</em> than {@code length} entries, * an array with {@code length} entries whose entries are the same as * the first {@code length} entries of {@code array}; otherwise, an * array with {@code length} entries whose first {@code array.length} * entries are the same as those of {@code array}. * */ public static byte[] setLength(final byte[] array, final int length) { if (length == array.length) return array; if (length < array.length) return trim(array, length); return ensureCapacity(array, length); } /**
@Override public byte[] next() { int length, common; if (!hasNext()) throw new NoSuchElementException(); if (i % ratio == 0) { pos = p[i / ratio]; length = readInt(array, pos); s = ByteArrays.ensureCapacity(s, length, 0); ByteBigArrays.copyFromBig(array, pos + count(length), s, 0, length); pos += length + count(length); inSync = true; } else { if (inSync) { length = readInt(array, pos); common = readInt(array, pos + count(length)); s = ByteArrays.ensureCapacity(s, length + common, common); ByteBigArrays.copyFromBig(array, pos + count(length) + count(common), s, common, length); pos += count(length) + count(common) + length; length += common; } else { s = ByteArrays.ensureCapacity(s, length = length(i), 0); extract(i, s, 0, length); } } i++; return ByteArrays.copy(s, 0, length); } @Override
a = ByteArrays.ensureCapacity(a, length, 0); a = ByteArrays.ensureCapacity(a, length + common, common); length += common; } else { a = ByteArrays.ensureCapacity(a, length = length(i), 0); extract(i, a, 0, length);
a = ByteArrays.ensureCapacity(a, length, 0); a = ByteArrays.ensureCapacity(a, length + common, common); length += common; } else { a = ByteArrays.ensureCapacity(a, length = length(i), 0); extract(i, a, 0, length);