File tree Expand file tree Collapse file tree
main/java/org/msgpack/core/buffer
test/scala/org/msgpack/core/buffer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public ChannelBufferOutput(WritableByteChannel channel) {
1919 }
2020
2121 public void reset (WritableByteChannel channel ) throws IOException {
22- channel .close ();
22+ this . channel .close ();
2323 this .channel = channel ;
2424 }
2525
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public OutputStreamBufferOutput(OutputStream out) {
1919 }
2020
2121 public void reset (OutputStream out ) throws IOException {
22- out .close ();
22+ this . out .close ();
2323 this .out = out ;
2424 }
2525
Original file line number Diff line number Diff line change 1+ package org .msgpack .core .buffer
2+
3+ import org .msgpack .core .MessagePackSpec
4+ import java .io ._
5+
6+ class MessageBufferOutputTest extends MessagePackSpec {
7+
8+ def createTempFile = {
9+ val f = File .createTempFile(" msgpackTest" , " msgpack" )
10+ f.deleteOnExit
11+ f
12+ }
13+
14+ def createTempFileWithOutputStream = {
15+ val f = createTempFile
16+ val out = new FileOutputStream (f)
17+ (f, out)
18+ }
19+
20+ def createTempFileWithChannel = {
21+ val (f, out) = createTempFileWithOutputStream
22+ val ch = out.getChannel
23+ (f, ch)
24+ }
25+
26+ def writeIntToBuf (buf: MessageBufferOutput ) = {
27+ val mb0 = buf.next(8 )
28+ mb0.putInt(0 , 42 )
29+ buf.flush(mb0)
30+ buf.close
31+ }
32+
33+ " OutputStreamBufferOutput" should {
34+ " reset buffer" in {
35+ val (f0, out0) = createTempFileWithOutputStream
36+ val buf = new OutputStreamBufferOutput (out0)
37+ writeIntToBuf(buf)
38+ f0.length.toInt should be > 0
39+
40+ val (f1, out1) = createTempFileWithOutputStream
41+ buf.reset(out1)
42+ writeIntToBuf(buf)
43+ f1.length.toInt should be > 0
44+ }
45+ }
46+
47+ " ChannelBufferOutput" should {
48+ " reset buffer" in {
49+ val (f0, ch0) = createTempFileWithChannel
50+ val buf = new ChannelBufferOutput (ch0)
51+ writeIntToBuf(buf)
52+ f0.length.toInt should be > 0
53+
54+ val (f1, ch1) = createTempFileWithChannel
55+ buf.reset(ch1)
56+ writeIntToBuf(buf)
57+ f1.length.toInt should be > 0
58+ }
59+ }
60+
61+ }
You can’t perform that action at this time.
0 commit comments