Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix IOInputStream single-byte read #750

Merged
merged 1 commit into from

2 participants

@grddev

Java does signed type conversions by default. Thus, any bytes above 127 resulted in negative return values, which where either illegal return values or signifying end of file.

@grddev grddev Fix IOInputStream single-byte read
Java does signed type conversions by default. Thus, any bytes above 127
resulted in negative return values, which where either illegal return
values or signifying end of file.
7e8bf33
@headius headius merged commit 7f4581b into jruby:master
@headius
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 20, 2013
  1. @grddev

    Fix IOInputStream single-byte read

    grddev authored
    Java does signed type conversions by default. Thus, any bytes above 127
    resulted in negative return values, which where either illegal return
    values or signifying end of file.
This page is out of date. Refresh to see the latest.
View
8 spec/java_integration/addons/stringio_addons.rb
@@ -4,10 +4,13 @@
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'
@@ -15,6 +18,7 @@
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
View
2  src/org/jruby/util/IOInputStream.java
@@ -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;
}
Something went wrong with that request. Please try again.