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 @@ -19,7 +19,7 @@ public ChannelBufferOutput(WritableByteChannel channel) {
}

public void reset(WritableByteChannel channel) throws IOException {
channel.close();
this.channel.close();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code should be:

this.channel.close();

this.channel = channel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public OutputStreamBufferOutput(OutputStream out) {
}

public void reset(OutputStream out) throws IOException {
out.close();
this.out.close();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been:

this.out.close();

this.out = out;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.msgpack.core.buffer

import org.msgpack.core.MessagePackSpec
import java.io._

class MessageBufferOutputTest extends MessagePackSpec {

def createTempFile = {
val f = File.createTempFile("msgpackTest", "msgpack")
f.deleteOnExit
f
}

def createTempFileWithOutputStream = {
val f = createTempFile
val out = new FileOutputStream(f)
(f, out)
}

def createTempFileWithChannel = {
val (f, out) = createTempFileWithOutputStream
val ch = out.getChannel
(f, ch)
}

def writeIntToBuf(buf:MessageBufferOutput) = {
val mb0 = buf.next(8)
mb0.putInt(0, 42)
buf.flush(mb0)
buf.close
}

"OutputStreamBufferOutput" should {
"reset buffer" in {
val (f0, out0) = createTempFileWithOutputStream
val buf = new OutputStreamBufferOutput(out0)
writeIntToBuf(buf)
f0.length.toInt should be > 0

val (f1, out1) = createTempFileWithOutputStream
buf.reset(out1)
writeIntToBuf(buf)
f1.length.toInt should be > 0
}
}

"ChannelBufferOutput" should {
"reset buffer" in {
val (f0, ch0) = createTempFileWithChannel
val buf = new ChannelBufferOutput(ch0)
writeIntToBuf(buf)
f0.length.toInt should be > 0

val (f1, ch1) = createTempFileWithChannel
buf.reset(ch1)
writeIntToBuf(buf)
f1.length.toInt should be > 0
}
}

}