Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to quickly dump an int array into an output stream?

807580Aug 13 2009 — edited Aug 13 2009
Hi folks,

I have an int array, very large, I need to stick it into an output stream. One example is to a file.

Now, the only way I've found to get it working thus far is...
for(int i=0; i<oData_p.length; i++)
{            
oOutputStream_c.write(oData_p[i] << 24);
oOutputStream_c.write(oData_p[i] >> 16 & 0xff);
oOutputStream_c.write(oData_p[i] >> 8  & 0xff);
oOutputStream_c.write(oData_p[i] & 0xff);
}
Which for a really large array is causing severe performance problems. Is there no other way to get the int array written to the stream other than this craziness? If I have the same data in a byte array its a million times quicker, but unfortunately (for me) the data is an int array when it 'gets to me' and there is nothin' I can do about it.

Thanks for the advice,
Jibber.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 10 2009
Added on Aug 13 2009
8 comments
461 views