File tree Expand file tree Collapse file tree 4 files changed +27
-5
lines changed
main/java/org/msgpack/core
test/scala/org/msgpack/core Expand file tree Collapse file tree 4 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -56,11 +56,10 @@ private ArrayBufferOutput getArrayBufferOut()
5656 return (ArrayBufferOutput ) out ;
5757 }
5858
59- /**
60- * Clears the written data.
61- */
59+ @ Override
6260 public void clear ()
6361 {
62+ super .clear ();
6463 getArrayBufferOut ().clear ();
6564 }
6665
Original file line number Diff line number Diff line change @@ -260,6 +260,14 @@ public long getTotalWrittenBytes()
260260 return totalFlushBytes + position ;
261261 }
262262
263+ /**
264+ * Clears the written data.
265+ */
266+ public void clear ()
267+ {
268+ position = 0 ;
269+ }
270+
263271 /**
264272 * Flushes internal buffer to the underlying output.
265273 * <p>
Original file line number Diff line number Diff line change 2828public class ArrayBufferOutput
2929 implements MessageBufferOutput
3030{
31- private List <MessageBuffer > list ;
31+ private final List <MessageBuffer > list ;
32+ private final int bufferSize ;
3233 private MessageBuffer lastBuffer ;
33- private int bufferSize ;
3434
3535 public ArrayBufferOutput ()
3636 {
Original file line number Diff line number Diff line change 1616package org .msgpack .core
1717
1818import java .io .ByteArrayOutputStream
19+ import java .util .Arrays
1920
2021import org .msgpack .value .ValueFactory ._
2122
@@ -32,5 +33,19 @@ class MessageBufferPackerTest extends MessagePackSpec {
3233
3334 packer1.toByteArray shouldBe stream.toByteArray
3435 }
36+
37+ " clear unflushed" in {
38+ val packer = MessagePack .newDefaultBufferPacker
39+ packer.packInt(1 );
40+ packer.clear();
41+ packer.packInt(2 );
42+
43+ packer.toByteArray shouldBe Array (2 )
44+ val buffer = packer.toBufferList().get(0 )
45+ buffer.toByteArray() shouldBe Array (2 )
46+ val array = Arrays .copyOf(buffer.sliceAsByteBuffer().array(), buffer.size())
47+ array shouldBe Array (2 )
48+ }
49+
3550 }
3651}
You can’t perform that action at this time.
0 commit comments