現在、Java ByteBuffer を使用しています
ByteBuffer batch = ByteBuffer.allocate(tuple_size * batch_size ) ;
int pos = 0;
int sent = 0;
while ( sent++ < batch_size) {
Event event = (Event) it.next();
batch.put(event.getData(), pos, tuple_size);
pos += tuple_size;
}
return batch.array();
現在、batch_size は 2 に設定されています。私の問題は、2 回目のラウンドで、説明できない IndexOutofBoundsException が発生することです。次の詳細を出力します。
System.out.println(pos + " " + batch.capacity() + " " + batch.position() + " " + batch.remaining());
私が得る: 0 200 0 200 (ラウンド 0)
100 200 100 100 (ラウンド 1)
これは人が期待するものです。現在、ドキュメントに基づいて、バインドされたチェックが保持されているようです。
offset - The offset within the array of the first byte to be read; must be non-negative and no larger than array.length
length - The number of bytes to be read from the given array; must be non-negative and no larger than array.length - offset
バッファを完全に埋めるにはどうすればよいですか? (基礎となるバッファの長さを tuple_size * batch_size に保ちながら?)