Skip to content

Commit

Permalink
JRUBY-5064: ChannelStream#read() should return an unsigned value.
Browse files Browse the repository at this point in the history
For InputStream compatibility. Reading int from buffered bytes works but
reading from unbeffered bytes did not work.
  • Loading branch information
Hiroshi Nakamura committed Sep 7, 2010
1 parent ff64ee7 commit a806844
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/org/jruby/util/io/ChannelStream.java
Expand Up @@ -1457,7 +1457,8 @@ public int read() throws IOException {
}

byte[] b = new byte[1];
return read(b, 0, 1) == 1 ? b[0] : -1;
// java.io.InputStream#read must return an unsigned value;
return read(b, 0, 1) == 1 ? b[0] & 0xff: -1;
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions test/test_unmarshal.rb
Expand Up @@ -23,4 +23,15 @@ def testUnmarshal
flunk "Unmarshalling failed with EOF error at " + result + " string."
end

def test_fixnum_unbuffered
# need to read unbuffered value from ChannelStream.
obj = Array.new(2000, 60803)
dump = Marshal.dump(obj)
piper, pipew = IO.pipe
pipew << dump
Marshal.load(piper).each do |e|
assert_equal(60803, e, 'JRUBY-5064')
end
end

end

0 comments on commit a806844

Please sign in to comment.