Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Commit 42b8052

Browse files
michaeljmarshallEnrico Olivelli
authored andcommitted
[fix] DataOutputStreamWritable#writeByteBuffer offset value
1 parent 223c745 commit 42b8052

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package org.apache.kafka.common.requests;
15+
16+
import org.apache.kafka.common.utils.Utils;
17+
18+
import java.io.DataOutputStream;
19+
import java.io.IOException;
20+
import java.nio.ByteBuffer;
21+
22+
/**
23+
* This class is necessary to bypass a bug in
24+
* <a href="https://github.com/apache/kafka/blob/927edfece3db8aab7d01850955f9a65e5c110da5/clients/src/main/java/org/apache/kafka/common/protocol/DataOutputStreamWritable.java#L102">DataOutputStreamWritable</a>
25+
*/
26+
public class DataOutputStreamWritable extends org.apache.kafka.common.protocol.DataOutputStreamWritable {
27+
public DataOutputStreamWritable(DataOutputStream out) {
28+
super(out);
29+
}
30+
@Override
31+
public void writeByteBuffer(ByteBuffer buf) {
32+
try {
33+
if (buf.hasArray()) {
34+
out.write(buf.array(), buf.arrayOffset(), buf.limit());
35+
} else {
36+
byte[] bytes = Utils.toArray(buf);
37+
out.write(bytes);
38+
}
39+
} catch (IOException e) {
40+
throw new RuntimeException(e);
41+
}
42+
}
43+
}

kafka-impl/src/main/java/org/apache/kafka/common/requests/KopResponseUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.io.DataOutputStream;
1919
import java.nio.ByteBuffer;
2020
import lombok.extern.slf4j.Slf4j;
21-
import org.apache.kafka.common.protocol.DataOutputStreamWritable;
2221
import org.apache.kafka.common.protocol.Message;
2322
import org.apache.kafka.common.protocol.ObjectSerializationCache;
2423
import org.apache.kafka.common.protocol.Writable;

0 commit comments

Comments
 (0)