Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > question about streams

Reply
Thread Tools

question about streams

 
 
Jackie
Guest
Posts: n/a
 
      04-28-2006
Hello

I have a little problem with the following code (s2c is a socket):

is = s2c.getInputStream();
br = new BufferedReader(new InputStreamReader(is));
oi = new ObjectInputStream(is); //here my program hangs. How can I
solve this? Or is it impossible to make 2 streams from one InputStream?

As a student, I'm just starting with java. So maybe it's something very
stupid
Thanks, Chris

 
Reply With Quote
 
 
 
 
Monique Y. Mudama
Guest
Posts: n/a
 
      04-28-2006
On 2006-04-28, Jackie penned:
> Hello
>
> I have a little problem with the following code (s2c is a socket):
>
> is = s2c.getInputStream();
> br = new BufferedReader(new InputStreamReader(is));
> oi = new ObjectInputStream(is); //here my program hangs. How can I
> solve this? Or is it impossible to make 2 streams from one InputStream?
>
> As a student, I'm just starting with java. So maybe it's something very
> stupid


What are you trying to accomplish by doing this?

Depending on what you're trying to do, would it make sense to do

oi = new ObjectInputStream(br);

?

--
monique

Help us help you:
http://www.catb.org/~esr/faqs/smart-questions.html
 
Reply With Quote
 
 
 
 
Jackie
Guest
Posts: n/a
 
      04-29-2006
br is a character stream, while oi (ObjectInputStream) is of course a
bytestream, so i don't think oi = new ObjectInputStream(br); will work
i have to send and receive tekst en objects through a socket. i can
also recieve my Strings with an objectinputstream but i want to use a
bufferedreader because i need some functions of it that
objectinputstream doesn't have. So i just want to be able to set an
objectinputstream on the inputstream of the socket while there is also
constantly an bufferedreader on the inputstream. Is there a way to do
so?

 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      04-29-2006
On 28 Apr 2006 14:27:39 -0700, Jackie wrote:
> I have a little problem with the following code (s2c is a socket):
>
> is = s2c.getInputStream();
> br = new BufferedReader(new InputStreamReader(is));
> oi = new ObjectInputStream(is); //here my program hangs. How can I
> solve this? Or is it impossible to make 2 streams from one InputStream?


You will likely create more problems than you solve by forking the
stream that way. Reconsider your design.

However the ObjectInputStream constructor hangs for a completely
unrelated reason: it is waiting for corresponding ObjectOutputStream
constructor to send some header information.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
Rhino
Guest
Posts: n/a
 
      04-29-2006

"Jackie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> br is a character stream, while oi (ObjectInputStream) is of course a
> bytestream, so i don't think oi = new ObjectInputStream(br); will work
> i have to send and receive tekst en objects


"tekst en" objects??

What's that in English?

Even if I assume that this is just sloppy typing with transposed characters,
I can't think of any English word that resembles this that would make sense
in this context.....

> through a socket. i can
> also recieve my Strings with an objectinputstream but i want to use a
> bufferedreader because i need some functions of it that
> objectinputstream doesn't have. So i just want to be able to set an
> objectinputstream on the inputstream of the socket while there is also
> constantly an bufferedreader on the inputstream. Is there a way to do
> so?
>


--
Rhino


 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      04-29-2006
Rhino wrote:

> "tekst en" objects??
>
> What's that in English?


Text and objects.

-- chris



 
Reply With Quote
 
EJP
Guest
Posts: n/a
 
      04-30-2006
Jackie wrote:
> br is a character stream, while oi (ObjectInputStream) is of course a
> bytestream, so i don't think oi = new ObjectInputStream(br); will work
> i have to send and receive tekst en objects through a socket. i can
> also recieve my Strings with an objectinputstream but i want to use a
> bufferedreader because i need some functions of it that
> objectinputstream doesn't have. So i just want to be able to set an
> objectinputstream on the inputstream of the socket while there is also
> constantly an bufferedreader on the inputstream. Is there a way to do
> so?


Both ObjectInputStream and BufferedReader do buffering internally, so
they are *bound* to interfere with each other no matter which way you
stack them up. You might think that new BufferedReader(new
InputStreamReader(new ObjectInputStream(socket.getInputStream()))) might
be plausible but it isn't. You need to rethink your requirement.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Question: OSPF path selection based on streams bod43 Cisco 1 09-29-2009 02:28 AM
closures and streams question grocery_stocker Perl Misc 3 02-05-2009 11:15 PM
Question on streams K S M C Programming 4 08-25-2007 10:29 AM
Basic question on streams John Simeon C++ 16 07-25-2007 06:22 PM
odd C++ crash question with streams laniik C++ 4 04-08-2005 03:00 AM



Advertisments