This commit is contained in:
easyice 2023-12-14 23:06:50 +08:00
parent cf13a92950
commit 7e9acc1fbc
9 changed files with 27 additions and 27 deletions

View File

@ -157,7 +157,7 @@ public abstract class CompressionMode {
@Override @Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException { 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]; byte[] bytes = new byte[len];
buffersInput.readBytes(bytes, 0, len); buffersInput.readBytes(bytes, 0, len);
LZ4.compress(bytes, 0, len, out, ht); LZ4.compress(bytes, 0, len, out, ht);
@ -179,7 +179,7 @@ public abstract class CompressionMode {
@Override @Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException { 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]; byte[] bytes = new byte[len];
buffersInput.readBytes(bytes, 0, len); buffersInput.readBytes(bytes, 0, len);
LZ4.compress(bytes, 0, len, out, ht); LZ4.compress(bytes, 0, len, out, ht);
@ -265,7 +265,7 @@ public abstract class CompressionMode {
@Override @Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException { 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]; byte[] bytes = new byte[len];
buffersInput.readBytes(bytes, 0, len); buffersInput.readBytes(bytes, 0, len);

View File

@ -202,7 +202,7 @@ public final class DeflateWithPresetDictCompressionMode extends CompressionMode
@Override @Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException { 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 dictLength = len / (NUM_SUB_BLOCKS * DICT_SIZE_FACTOR);
final int blockLength = (len - dictLength + NUM_SUB_BLOCKS - 1) / NUM_SUB_BLOCKS; final int blockLength = (len - dictLength + NUM_SUB_BLOCKS - 1) / NUM_SUB_BLOCKS;
out.writeVInt(dictLength); out.writeVInt(dictLength);

View File

@ -169,7 +169,7 @@ public final class LZ4WithPresetDictCompressionMode extends CompressionMode {
@Override @Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException { 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 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; final int blockLength = (len - dictLength + NUM_SUB_BLOCKS - 1) / NUM_SUB_BLOCKS;
buffer = ArrayUtil.growNoCopy(buffer, dictLength + blockLength); buffer = ArrayUtil.growNoCopy(buffer, dictLength + blockLength);

View File

@ -253,7 +253,7 @@ public final class Lucene90CompressingStoredFieldsWriter extends StoredFieldsWri
// compress stored fields to fieldsStream. // compress stored fields to fieldsStream.
if (sliced) { if (sliced) {
// big chunk, slice it, using ByteBuffersDataInput ignore memory copy // 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) { for (int compressed = 0; compressed < capacity; compressed += chunkSize) {
int l = Math.min(chunkSize, capacity - compressed); int l = Math.min(chunkSize, capacity - compressed);
ByteBuffersDataInput bbdi = bytebuffers.slice(compressed, l); ByteBuffersDataInput bbdi = bytebuffers.slice(compressed, l);

View File

@ -115,7 +115,7 @@ public class PrefixCodedTerms implements Accountable {
private TermIterator(long delGen, ByteBuffersDataInput input) { private TermIterator(long delGen, ByteBuffersDataInput input) {
this.input = input; this.input = input;
end = input.size(); end = input.length();
this.delGen = delGen; this.delGen = delGen;
} }

View File

@ -49,7 +49,7 @@ final class SortingStoredFieldsConsumer extends StoredFieldsConsumer {
@Override @Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) public void compress(ByteBuffersDataInput buffersInput, DataOutput out)
throws IOException { throws IOException {
out.copyBytes(buffersInput, buffersInput.size()); out.copyBytes(buffersInput, buffersInput.length());
} }
}; };
} }

View File

@ -53,7 +53,7 @@ public final class ByteBuffersIndexInput extends IndexInput implements RandomAcc
@Override @Override
public long length() { public long length() {
ensureOpen(); ensureOpen();
return in.size(); return in.length();
} }
@Override @Override
@ -209,7 +209,7 @@ public final class ByteBuffersIndexInput extends IndexInput implements RandomAcc
public IndexInput clone() { public IndexInput clone() {
ensureOpen(); ensureOpen();
ByteBuffersIndexInput cloned = ByteBuffersIndexInput cloned =
new ByteBuffersIndexInput(in.slice(0, in.size()), "(clone of) " + toString()); new ByteBuffersIndexInput(in.slice(0, in.length()), "(clone of) " + toString());
try { try {
cloned.seek(getFilePointer()); cloned.seek(getFilePointer());
} catch (IOException e) { } catch (IOException e) {

View File

@ -37,7 +37,7 @@ public final class TestByteBuffersDataInput extends RandomizedTest {
public void testSanity() throws IOException { public void testSanity() throws IOException {
ByteBuffersDataOutput out = new ByteBuffersDataOutput(); ByteBuffersDataOutput out = new ByteBuffersDataOutput();
ByteBuffersDataInput o1 = out.toDataInput(); ByteBuffersDataInput o1 = out.toDataInput();
assertEquals(0, o1.size()); assertEquals(0, o1.length());
LuceneTestCase.expectThrows( LuceneTestCase.expectThrows(
EOFException.class, EOFException.class,
() -> { () -> {
@ -47,9 +47,9 @@ public final class TestByteBuffersDataInput extends RandomizedTest {
out.writeByte((byte) 1); out.writeByte((byte) 1);
ByteBuffersDataInput o2 = out.toDataInput(); ByteBuffersDataInput o2 = out.toDataInput();
assertEquals(1, o2.size()); assertEquals(1, o2.length());
assertEquals(0, o2.position()); assertEquals(0, o2.position());
assertEquals(0, o1.size()); assertEquals(0, o1.length());
assertTrue(o2.ramBytesUsed() > 0); assertTrue(o2.ramBytesUsed() > 0);
assertEquals(1, o2.readByte()); assertEquals(1, o2.readByte());
@ -106,7 +106,7 @@ public final class TestByteBuffersDataInput extends RandomizedTest {
dst.toDataInput().slice(prefix.length, dst.size() - prefix.length - suffix.length); dst.toDataInput().slice(prefix.length, dst.size() - prefix.length - suffix.length);
assertEquals(0, src.position()); 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) { for (IOConsumer<DataInput> c : reply) {
c.accept(src); c.accept(src);
} }
@ -190,8 +190,8 @@ public final class TestByteBuffersDataInput extends RandomizedTest {
curr = skipTo + 1; // +1 for read byte curr = skipTo + 1; // +1 for read byte
} }
in.seek(in.size()); in.seek(in.length());
assertEquals(in.size(), in.position()); assertEquals(in.length(), in.position());
LuceneTestCase.expectThrows( LuceneTestCase.expectThrows(
EOFException.class, EOFException.class,
() -> { () -> {
@ -203,18 +203,18 @@ public final class TestByteBuffersDataInput extends RandomizedTest {
@Test @Test
public void testSlicingWindow() throws Exception { public void testSlicingWindow() throws Exception {
ByteBuffersDataOutput dst = new ByteBuffersDataOutput(); 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)); dst.writeBytes(randomBytesOfLength(1024 * 8));
ByteBuffersDataInput in = dst.toDataInput(); ByteBuffersDataInput in = dst.toDataInput();
for (int offset = 0, max = (int) dst.size(); offset < max; offset++) { for (int offset = 0, max = (int) dst.size(); offset < max; offset++) {
assertEquals(0, in.slice(offset, 0).size()); assertEquals(0, in.slice(offset, 0).length());
assertEquals(1, in.slice(offset, 1).size()); assertEquals(1, in.slice(offset, 1).length());
int window = Math.min(max - offset, 1024); 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 @Test
@ -265,17 +265,17 @@ public final class TestByteBuffersDataInput extends RandomizedTest {
buffers.get(0).position(shift); buffers.get(0).position(shift);
ByteBuffersDataInput dst = new ByteBuffersDataInput(buffers); 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; long offset = 0;
for (; offset < max; offset += randomIntBetween(MB, 4 * MB)) { for (; offset < max; offset += randomIntBetween(MB, 4 * MB)) {
assertEquals(0, dst.slice(offset, 0).size()); assertEquals(0, dst.slice(offset, 0).length());
assertEquals(1, dst.slice(offset, 1).size()); assertEquals(1, dst.slice(offset, 1).length());
long window = Math.min(max - offset, 1024); long window = Math.min(max - offset, 1024);
ByteBuffersDataInput slice = dst.slice(offset, window); ByteBuffersDataInput slice = dst.slice(offset, window);
assertEquals(window, slice.size()); assertEquals(window, slice.length());
// Sanity check of the content against original pages. // Sanity check of the content against original pages.
for (int i = 0; i < window; i++) { for (int i = 0; i < window; i++) {

View File

@ -78,7 +78,7 @@ public class DummyCompressingCodec extends CompressingCodec {
@Override @Override
public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException { public void compress(ByteBuffersDataInput buffersInput, DataOutput out) throws IOException {
out.copyBytes(buffersInput, buffersInput.size()); out.copyBytes(buffersInput, buffersInput.length());
} }
@Override @Override