Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

question about streams

Thread view: 
Jackie - 28 Apr 2006 22:27 GMT
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
Monique Y. Mudama - 28 Apr 2006 22:55 GMT
> Hello
>
[quoted text clipped - 7 lines]
> 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);

?

Signature

monique

Help us help you:
http://www.catb.org/~esr/faqs/smart-questions.html

Jackie - 29 Apr 2006 09:29 GMT
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?
Rhino - 29 Apr 2006 15:55 GMT
> 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
[quoted text clipped - 3 lines]
> constantly an bufferedreader on the inputstream. Is there a way to do
> so?

--
Rhino
Chris Uppal - 29 Apr 2006 16:33 GMT
> "tekst en" objects??
>
> What's that in English?

Text and objects.

   -- chris
EJP - 30 Apr 2006 08:51 GMT
> br is a character  stream, while oi (ObjectInputStream) is of course a
> bytestream, so i don't think oi = new ObjectInputStream(br); will work
[quoted text clipped - 5 lines]
> 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.
Gordon Beaton - 29 Apr 2006 10:37 GMT
> 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

Signature

[  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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.