From 3dbe1784bea73d99ab75010d0a8e6bdbde1011b3 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Mon, 27 Apr 2015 10:37:42 +0900 Subject: [PATCH] Fixes #217: Handle when FileInputStream.getChannel() returns null --- .../org/msgpack/core/buffer/InputStreamBufferInput.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/msgpack-core/src/main/java/org/msgpack/core/buffer/InputStreamBufferInput.java b/msgpack-core/src/main/java/org/msgpack/core/buffer/InputStreamBufferInput.java index 0e7e4626d..d9a7c3466 100644 --- a/msgpack-core/src/main/java/org/msgpack/core/buffer/InputStreamBufferInput.java +++ b/msgpack-core/src/main/java/org/msgpack/core/buffer/InputStreamBufferInput.java @@ -3,6 +3,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.channels.FileChannel; import static org.msgpack.core.Preconditions.checkNotNull; @@ -18,7 +19,10 @@ public class InputStreamBufferInput implements MessageBufferInput { public static MessageBufferInput newBufferInput(InputStream in) { checkNotNull(in, "InputStream is null"); if (in instanceof FileInputStream) { - return new ChannelBufferInput(((FileInputStream) in).getChannel()); + FileChannel channel = ((FileInputStream) in).getChannel(); + if(channel != null) { + return new ChannelBufferInput(channel); + } } return new InputStreamBufferInput(in); }