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 @@ -26,7 +26,7 @@ public ChannelBufferInput(ReadableByteChannel channel, int bufferSize) {
}

public void reset(ReadableByteChannel channel) throws IOException {
channel.close();
this.channel.close();
this.channel = channel;
this.reachedEOF = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public InputStreamBufferInput(InputStream in, int bufferSize) {
}

public void reset(InputStream in) throws IOException {
in.close();
this.in.close();
this.in = in;
reachedEOF = false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.msgpack.core.buffer

import org.msgpack.core.MessagePackSpec
import org.msgpack.core.{MessageUnpacker, MessagePack, MessagePackSpec}
import java.io._
import xerial.core.io.IOUtil
import scala.util.Random
import java.util.zip.{GZIPOutputStream, GZIPInputStream}
import java.nio.ByteBuffer
import org.msgpack.unpacker.MessagePackUnpacker

/**
* Created on 5/30/14.
Expand Down Expand Up @@ -98,4 +99,54 @@ class MessageBufferInputTest extends MessagePackSpec {
}

}

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

def createTempFileWithInputStream = {
val f = createTempFile
val out = new FileOutputStream(f)
new MessagePack().newPacker(out).packInt(42).close
val in = new FileInputStream(f)
(f, in)
}

def createTempFileWithChannel = {
val (f, in) = createTempFileWithInputStream
val ch = in.getChannel
(f, ch)
}

def readInt(buf:MessageBufferInput) : Int = {
val unpacker = new MessageUnpacker(buf)
unpacker.unpackInt
}

"InputStreamBufferInput" should {
"reset buffer" in {
val (f0, in0) = createTempFileWithInputStream
val buf = new InputStreamBufferInput(in0)
readInt(buf) shouldBe 42

val (f1, in1) = createTempFileWithInputStream
buf.reset(in1)
readInt(buf) shouldBe 42
}
}

"ChannelBufferInput" should {
"reset buffer" in {
val (f0, in0) = createTempFileWithChannel
val buf = new ChannelBufferInput(in0)
readInt(buf) shouldBe 42

val (f1, in1) = createTempFileWithChannel
buf.reset(in1)
readInt(buf) shouldBe 42
}
}

}