diff --git a/jni/include/stream_support.h b/jni/include/stream_support.h index 8c83c178a..98d1f56db 100644 --- a/jni/include/stream_support.h +++ b/jni/include/stream_support.h @@ -132,7 +132,6 @@ class NativeEngineIndexOutputMediator { void writeBytes(uint8_t* data, size_t nbytes) { auto left = (int32_t) nbytes; - std::cout << "@@@ [KDY] write " << nbytes << std::endl; while (left > 0) { const auto copyBytes = std::min(left, bufferSize - offset); std::memcpy(buffer.get() + offset, data, copyBytes); @@ -165,7 +164,6 @@ class NativeEngineIndexOutputMediator { } void flush() { - std::cout << "@@@ [KDY] flush " << offset << std::endl; // `writeBytes` method defined. jmethodID writeBytesMethod = getWriteBytesMethod(env); diff --git a/src/main/java/org/opensearch/knn/index/util/IndexOutputWithBuffer.java b/src/main/java/org/opensearch/knn/index/util/IndexOutputWithBuffer.java new file mode 100644 index 000000000..e46b171c6 --- /dev/null +++ b/src/main/java/org/opensearch/knn/index/util/IndexOutputWithBuffer.java @@ -0,0 +1,36 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.knn.index.util; + +import org.apache.lucene.store.IndexOutput; + +import java.io.IOException; + +public class IndexOutputWithBuffer { + public IndexOutputWithBuffer(IndexOutput indexOutput) { + this.indexOutput = indexOutput; + } + + public byte[] getBuffer() { + return buffer; + } + + public void writeBytes(int length) { + try { + indexOutput.writeBytes(buffer, 0, length); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public String toString() { + return "{indexOutput=" + indexOutput + ", len(buffer)=" + buffer.length + "}"; + } + + private IndexOutput indexOutput; + private byte[] buffer = new byte[4 * 1024]; +}