Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public BytesWritableConverter() {
/** {@inheritDoc} */
@Override
public ByteBuffer convert(BytesWritable input) {
return ByteBuffer.wrap(input.getBytes());
return ByteBuffer.wrap(input.getBytes(), 0, input.getLength());
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ void convertBytesWritable() {
assertEquals(3, bytes.get(2));
}

@Test
void convertBytesWritableRespectsLogicalLength() {
AvroDatumConverter<BytesWritable, ByteBuffer> converter = mFactory.create(BytesWritable.class);
byte[] backing = new byte[] { 1, 2, 3, 4, 5 };
BytesWritable writable = new BytesWritable(backing);
writable.setSize(3);

ByteBuffer bytes = converter.convert(writable);

assertEquals(3, bytes.remaining());
assertEquals(1, bytes.get(0));
assertEquals(2, bytes.get(1));
assertEquals(3, bytes.get(2));
}

@Test
void convertByteWritable() {
AvroDatumConverter<ByteWritable, GenericFixed> converter = mFactory.create(ByteWritable.class);
Expand Down
Loading