Permalink
Browse files

Merge pull request #750 from grddev/to_inputstream_read

Fix IOInputStream single-byte read
  • Loading branch information...
headius committed May 21, 2013
2 parents 6768a29 + 7e8bf33 commit 7f4581b78d9fd55669eea3b776dbdba36e25046a
Showing with 7 additions and 3 deletions.
  1. +6 −2 spec/java_integration/addons/stringio_addons.rb
  2. +1 −1 src/org/jruby/util/IOInputStream.java
@@ -4,17 +4,21 @@
describe "Ruby StringIO" do
it "should be coercible to java.io.InputStream with StringIO#to_inputstream" do
- file = StringIO.new('abcdefghij')
+ file = StringIO.new("\xC3\x80abcdefghij")
stream = file.to_inputstream
java.io.InputStream.should === stream
-
+
+ stream.read.should == 0xc3
+ stream.read.should == 0x80
+
bytes = "0000000000".to_java_bytes
stream.read(bytes).should == 10
String.from_java_bytes(bytes).should == 'abcdefghij'
end
it "should be coercible to java.io.OutputStream with StringIO#to_outputstream" do
file = StringIO.new
+ stream = file.to_outputstream
java.io.OutputStream.should === stream
bytes = "1234567890".to_java_bytes
@@ -95,7 +95,7 @@ public int read() throws IOException {
IRubyObject readValue = readAdapter.call(io.getRuntime().getCurrentContext(), io, io, numOne);
int returnValue = -1;
if (!readValue.isNil()) {
- returnValue = readValue.convertToString().getByteList().get(0);
+ returnValue = readValue.convertToString().getByteList().get(0) & 0xff;
}
return returnValue;
}

0 comments on commit 7f4581b

Please sign in to comment.