• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

ByteArrayStream steam!

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is a ByteArrayStream for! To me, ObjectOutputStreams and PrintWriters are much, MUCH cooler. Could you answer me?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cooler? What are you? 11 years old? Oh, wait, I see that you are.
The short answer is that there are different Readers and Streams for different purposes. Not all data is Objects and Strings. Have a look at the Java Tutorial chapter on IO for the basics on Java Streams.
 
Allion Salvador
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HEY!!! What kind of comment is that?!!! Thanks, though. I just didn't think they were too useful.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Allion]: HEY!!! What kind of comment is that?!!!

A good-natured one, I think. Most adult programmers aren't too concerned with the "coolness" of a class. If we cared about coolness, we probably wouldn't have become programmers.

I just didn't think they were too useful.

They aren't - unless you want to write data to a byte array, sequentially. Then they're very useful. There are other ways this could be done, of course, but if you're using streams elsewhere in your code then BAOS and BAIS are very convenient ways to connect streams to arrays (and vice versa).
[ November 17, 2005: Message edited by: Jim Yingst ]
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Allion Salvador:
HEY!!! What kind of comment is that?!!!



I'm just playing with you. Notice the smiley.
As Jim said, "cool" isn't as big a factor as "utility" is to a programmer. You never know exactly what problems you are going to have, so it's best to have a large number of tools to choose from.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Most adult programmers aren't too concerned with the "coolness" of a class. If we cared about coolness, we probably wouldn't have become programmers.



I am offended by that comment.

Who you calling an Adult?

Mark
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what are you talking about??
i don't understand your question!!!
who can help me to deal with my problem which topic name is [ask for advice]

thank you very much
 
Allion Salvador
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No,no! I was talking about the "superiority complex" thingamabob. It didn't sound too encouraging or stimulating! I understand the stream thingy, though. Thank you!


Zwetschenwasser tastes better when fermented in a brine of acephalous crustaceans

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Despite the smilies, Allion, now I can't tell if you are joking!

That "superiority" quote is Joe's signature file -- it gets automatically appended to every message he posts. It's something somebody said to him here at the Ranch one time, back in the olden times before we went and made him a Bartender. You're right that it wasn't a nice thing for that person to say at the time. Joe, being a real mensch, knows how to laugh at himself, though.
 
Sheriff
Posts: 22803
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've actually used the ByteArray streams once.

I was given a network protocol written in C++ which could send char[]. I had to use this protocol to send Java objects over a network. And how do you convert a Java object to a char[] / byte[]*? By using ByteArray streams: write to an ObjectOutputStream which uses a ByteArrayOutputStream, write to the ObjectOutputStream and then use toByteArray() of the ByteArrayOutputStream. Other way around, create a ByteArrayInputStream from an existing byte[], use it to create an ObjectInputStream and use its readObject method.


* Actually, a Java char is 2 bytes, and C++ chars are mostly 1 byte (although it is compiler specific). A Java char[] would not be useful most of the times.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Getting back to the topic, constructing streams is like connecting pipes
together. Some are meant just to connect to other streams, like ObjectOutputStream,
while others are terminals, like ByteArrayInputStream and ByteArrayOutputStream.
These two give you in-memory sourcs/targets for reading/writing data, and as
such, are very useful. Here's a standard example: suppose you have a
serializable class and you need to implement clone -- hey wait, you
don't have to code that up, just serialize to a byte[] and then materialize
back into an object:
 
Grow a forest with seedballs and this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic