Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace usage of deprecated size() with length() in ByteBuffersDataInput #12948

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private static final class LZ4FastCompressor extends Compressor {

@Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException {
final int len = (int) buffersInput.size();
final int len = (int) buffersInput.length();
byte[] bytes = new byte[len];
buffersInput.readBytes(bytes, 0, len);
LZ4.compress(bytes, 0, len, out, ht);
Expand All @@ -179,7 +179,7 @@ private static final class LZ4HighCompressor extends Compressor {

@Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException {
final int len = (int) buffersInput.size();
final int len = (int) buffersInput.length();
byte[] bytes = new byte[len];
buffersInput.readBytes(bytes, 0, len);
LZ4.compress(bytes, 0, len, out, ht);
Expand Down Expand Up @@ -265,7 +265,7 @@ private static class DeflateCompressor extends Compressor {

@Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException {
final int len = (int) buffersInput.size();
final int len = (int) buffersInput.length();

byte[] bytes = new byte[len];
buffersInput.readBytes(bytes, 0, len);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private void doCompress(byte[] bytes, int off, int len, DataOutput out) throws I

@Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException {
final int len = (int) (buffersInput.size() - buffersInput.position());
final int len = (int) (buffersInput.length() - buffersInput.position());
final int dictLength = len / (NUM_SUB_BLOCKS * DICT_SIZE_FACTOR);
final int blockLength = (len - dictLength + NUM_SUB_BLOCKS - 1) / NUM_SUB_BLOCKS;
out.writeVInt(dictLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void doCompress(byte[] bytes, int dictLen, int len, DataOutput out) thro

@Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException {
final int len = (int) (buffersInput.size() - buffersInput.position());
final int len = (int) (buffersInput.length() - buffersInput.position());
final int dictLength = Math.min(LZ4.MAX_DISTANCE, len / (NUM_SUB_BLOCKS * DICT_SIZE_FACTOR));
final int blockLength = (len - dictLength + NUM_SUB_BLOCKS - 1) / NUM_SUB_BLOCKS;
buffer = ArrayUtil.growNoCopy(buffer, dictLength + blockLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private void flush(boolean force) throws IOException {
// compress stored fields to fieldsStream.
if (sliced) {
// big chunk, slice it, using ByteBuffersDataInput ignore memory copy
final int capacity = (int) bytebuffers.size();
final int capacity = (int) bytebuffers.length();
for (int compressed = 0; compressed < capacity; compressed += chunkSize) {
int l = Math.min(chunkSize, capacity - compressed);
ByteBuffersDataInput bbdi = bytebuffers.slice(compressed, l);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static class TermIterator extends FieldTermIterator {

private TermIterator(long delGen, ByteBuffersDataInput input) {
this.input = input;
end = input.size();
end = input.length();
this.delGen = delGen;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void close() throws IOException {}
@Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out)
throws IOException {
out.copyBytes(buffersInput, buffersInput.size());
out.copyBytes(buffersInput, buffersInput.length());
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void seek(long pos) throws IOException {
@Override
public long length() {
ensureOpen();
return in.size();
return in.length();
}

@Override
Expand Down Expand Up @@ -209,7 +209,7 @@ public void readLongs(long[] dst, int offset, int length) throws IOException {
public IndexInput clone() {
ensureOpen();
ByteBuffersIndexInput cloned =
new ByteBuffersIndexInput(in.slice(0, in.size()), "(clone of) " + toString());
new ByteBuffersIndexInput(in.slice(0, in.length()), "(clone of) " + toString());
try {
cloned.seek(getFilePointer());
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class TestByteBuffersDataInput extends RandomizedTest {
public void testSanity() throws IOException {
ByteBuffersDataOutput out = new ByteBuffersDataOutput();
ByteBuffersDataInput o1 = out.toDataInput();
assertEquals(0, o1.size());
assertEquals(0, o1.length());
LuceneTestCase.expectThrows(
EOFException.class,
() -> {
Expand All @@ -47,9 +47,9 @@ public void testSanity() throws IOException {
out.writeByte((byte) 1);

ByteBuffersDataInput o2 = out.toDataInput();
assertEquals(1, o2.size());
assertEquals(1, o2.length());
assertEquals(0, o2.position());
assertEquals(0, o1.size());
assertEquals(0, o1.length());

assertTrue(o2.ramBytesUsed() > 0);
assertEquals(1, o2.readByte());
Expand Down Expand Up @@ -106,7 +106,7 @@ public void testRandomReadsOnSlices() throws Exception {
dst.toDataInput().slice(prefix.length, dst.size() - prefix.length - suffix.length);

assertEquals(0, src.position());
assertEquals(dst.size() - prefix.length - suffix.length, src.size());
assertEquals(dst.size() - prefix.length - suffix.length, src.length());
for (IOConsumer<DataInput> c : reply) {
c.accept(src);
}
Expand Down Expand Up @@ -190,8 +190,8 @@ public void testSeekAndSkip() throws Exception {
curr = skipTo + 1; // +1 for read byte
}

in.seek(in.size());
assertEquals(in.size(), in.position());
in.seek(in.length());
assertEquals(in.length(), in.position());
LuceneTestCase.expectThrows(
EOFException.class,
() -> {
Expand All @@ -203,18 +203,18 @@ public void testSeekAndSkip() throws Exception {
@Test
public void testSlicingWindow() throws Exception {
ByteBuffersDataOutput dst = new ByteBuffersDataOutput();
assertEquals(0, dst.toDataInput().slice(0, 0).size());
assertEquals(0, dst.toDataInput().slice(0, 0).length());

dst.writeBytes(randomBytesOfLength(1024 * 8));
ByteBuffersDataInput in = dst.toDataInput();
for (int offset = 0, max = (int) dst.size(); offset < max; offset++) {
assertEquals(0, in.slice(offset, 0).size());
assertEquals(1, in.slice(offset, 1).size());
assertEquals(0, in.slice(offset, 0).length());
assertEquals(1, in.slice(offset, 1).length());

int window = Math.min(max - offset, 1024);
assertEquals(window, in.slice(offset, window).size());
assertEquals(window, in.slice(offset, window).length());
}
assertEquals(0, in.slice((int) dst.size(), 0).size());
assertEquals(0, in.slice((int) dst.size(), 0).length());
}

@Test
Expand Down Expand Up @@ -265,17 +265,17 @@ public void testSlicingLargeBuffers() throws IOException {
buffers.get(0).position(shift);

ByteBuffersDataInput dst = new ByteBuffersDataInput(buffers);
assertEquals(simulatedLength, dst.size());
assertEquals(simulatedLength, dst.length());

final long max = dst.size();
final long max = dst.length();
long offset = 0;
for (; offset < max; offset += randomIntBetween(MB, 4 * MB)) {
assertEquals(0, dst.slice(offset, 0).size());
assertEquals(1, dst.slice(offset, 1).size());
assertEquals(0, dst.slice(offset, 0).length());
assertEquals(1, dst.slice(offset, 1).length());

long window = Math.min(max - offset, 1024);
ByteBuffersDataInput slice = dst.slice(offset, window);
assertEquals(window, slice.size());
assertEquals(window, slice.length());

// Sanity check of the content against original pages.
for (int i = 0; i < window; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Decompressor clone() {

@Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException {
out.copyBytes(buffersInput, buffersInput.size());
out.copyBytes(buffersInput, buffersInput.length());
}

@Override
Expand Down