Skip to content

Instantly share code, notes, and snippets.

@blinsay
Created October 29, 2014 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blinsay/1a7c9f30e9fd18a4a1bf to your computer and use it in GitHub Desktop.
Save blinsay/1a7c9f30e9fd18a4a1bf to your computer and use it in GitHub Desktop.
[6] pry(main)> def write_bytes_to_stream(thing)
[6] pry(main)* bs = ByteArrayOutputStream.new(1024)
[6] pry(main)* bs.write(thing)
[6] pry(main)* bs.flush
[6] pry(main)* bs.close
[6] pry(main)* bs.to_byte_array
[6] pry(main)* end
=> nil
[8] pry(main)> write_bytes_to_stream("hi there".to_java_bytes)
=> byte[104, 105, 32, 116, 104, 101, 114, 101]@53251a66
[9] pry(main)> write_bytes_to_stream(1023)
=> byte[-1]@20f5281c
[10] pry(main)> write_bytes_to_stream(1024)
=> byte[0]@38604b81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment