# Java ByteArrayOutputStream alternative in ruby

**URL:** <https://www.ruby-forum.com/t/java-bytearrayoutputstream-alternative-in-ruby/108148>\
**Category:** Ruby\
**Created:** [June 29, 2007, 1:26pm UTC](https://www.ruby-forum.com/t/java-bytearrayoutputstream-alternative-in-ruby/108148 "2007-06-29T13:26:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Googy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dfb087/32.png) [@Googy](https://www.ruby-forum.com/u/Googy)\
**Post date:** [June 29, 2007, 1:26pm UTC](https://www.ruby-forum.com/t/java-bytearrayoutputstream-alternative-in-ruby/108148/1 "2007-06-29T13:26:11Z")

</div>

Hi,

I am porting a library from java to ruby. My problem is simulating  
ByteArrayOutputStream in ruby. I want to pack bytes integers and all  
other kinds of data in to a stream buffer then get it as a packed  
string and send it over network.

Thanks.

---

<div class="post-metadata">

**Author:** ![Googy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dfb087/32.png) [@Googy](https://www.ruby-forum.com/u/Googy)\
**Post date:** [June 29, 2007, 2:58pm UTC](https://www.ruby-forum.com/t/java-bytearrayoutputstream-alternative-in-ruby/108148/2 "2007-06-29T14:58:27Z")

</div>

On Jun 29, 2007, at 6:25 AM, Googy wrote:

> I am porting a library from java to ruby. My problem is simulating  
> ByteArrayOutputStream in ruby. I want to pack bytes integers and all  
> other kinds of data in to a stream buffer then get it as a packed  
> string and send it over network.

Look-up Array#pack in your favorite documentation source.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![Googy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dfb087/32.png) [@Googy](https://www.ruby-forum.com/u/Googy)\
**Post date:** [June 29, 2007, 4:51pm UTC](https://www.ruby-forum.com/t/java-bytearrayoutputstream-alternative-in-ruby/108148/3 "2007-06-29T16:51:40Z")

</div>

On Jun 29, 5:55 pm, James Edward G. II [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On Jun 29, 2007, at 6:25 AM, Googy wrote:
> 
> > I am porting a library from java to ruby. My problem is simulating  
> > ByteArrayOutputStream in ruby. I want to pack bytes integers and all  
> > other kinds of data in to a stream buffer then get it as a packed  
> > string and send it over network.
> 
> Look-up Array#pack in your favorite documentation source.
> 
> James Edward G. II

Yeah, Did that before.  
But My problem is I collect binary data as the program runs and then  
send it over the network. So I want to know if there are any classes  
proving in memory streams.

I have one more doubt, how do you concatenate two packed values, for  
e.g you pack some stuff into a string at one location, and in some  
other location you pack another chunk of binary data. And how do you  
concatenate those two packed values, is normal string concatenation is  
sufficient for concatenating two chunks of binary data packed in  
strings ?

---

<div class="post-metadata">

**Author:** ![Googy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dfb087/32.png) [@Googy](https://www.ruby-forum.com/u/Googy)\
**Post date:** [June 29, 2007, 4:58pm UTC](https://www.ruby-forum.com/t/java-bytearrayoutputstream-alternative-in-ruby/108148/4 "2007-06-29T16:58:41Z")

</div>

On Jun 29, 2007, at 9:50 AM, Googy wrote:

> > Look-up Array#pack in your favorite documentation source.
> > 
> > James Edward G. II
> 
> Yeah, Did that before.  
> But My problem is I collect binary data as the program runs and then  
> send it over the network. So I want to know if there are any classes  
> proving in memory streams.

Well, String and Array can both be added too as needed, so I’m not  
sure how they fail to meet your needs.

> I have one more doubt, how do you concatenate two packed values, for  
> e.g you pack some stuff into a string at one location, and in some  
> other location you pack another chunk of binary data. And how do you  
> concatenate those two packed values, is normal string concatenation is  
> sufficient for concatenating two chunks of binary data packed in  
> strings ?

Sure.

James Edward G. II
