Created
December 14, 2011 20:55
-
-
Save abscondment/1478479 to your computer and use it in GitHub Desktop.
Test case for mirah/mirah#157
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.InputStream | |
import java.io.InputStreamReader | |
import java.io.IOException | |
class Test | |
# take an InputStream, return a String | |
def inputstream_to_string(is:InputStream) | |
buffer = char[0x10000] | |
out = StringBuilder.new | |
inreader = InputStreamReader.new(is, "UTF-8") | |
begin | |
read = int(0) | |
read_more = true | |
while read_more | |
read = inreader.read buffer, 0, buffer.length | |
if read > 0 | |
out.append buffer, 0, read | |
end | |
read_more = read >= 0 | |
end | |
rescue IOException => ex | |
ensure | |
inreader.close | |
end | |
out.toString | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment