This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes how to use ByteArrayInputStream? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "how to use ByteArrayInputStream?" Watch "how to use ByteArrayInputStream?" New topic
Author

how to use ByteArrayInputStream?

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Hello,
I am getting input / send output thru socket.... how can i use ByteArrayInputStream and ByteArrayOutputStream to get the input data from socket??? how can i combine a stream of data to be send to socket using ByteArrayInputStream and ByteArrayOutputStream ???
See the problem is that if I use other Streams and their read method has one problem it blocks the stream till it:
1. either gets some bytes
2. or gets some exeption
though my objective is to get immediate information wheather their is some data available their or not? I was thinking of using ByteArrayInputStream Read method and will try to read first byte to see if it is -1 or not..but could able to understand how to use it...or is their any other way out..
Can you please help me?
regards,
Arun
Peter Reinhardt
Ranch Hand

Joined: Aug 02, 2002
Posts: 57
hi,
I don't think that a ByteArrayInputStream can solve your problem, a ByteArrayInputStream simply reads bytes out of an byte-array. It has nothing to do with a socket.
If you have a look at SocketInputStream you will see that there is a method called "available()" which gives you the number of bytes you can read without blocking.
Generally the Java input streams are all blocking (up to jdk 1.4), you can try to use the new input streams of 1.4 (java.nio) to solve your problem.
Peter


SCJP 1.2, SCJD, SCEA, IBM 484, Weblogic 7
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Thanks Peter for ur reply..
but I am not able to SocketInputStream class..where it is available i am using JDK1.3 or it is in JDK1.4... sorry perhaps missing somewhere.
Though I can get an answer by setting the timeout field but now a bit curious about this SocketInput/output stream where can i get this.
Pl show me the path..
regards,
arun
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use ByteArrayInputStream?
 
Similar Threads
how to use ByteArrayInputStream?
Error connecting to server running on VB!
object stream
reading a stream twice but download it only once
BufferedReader conflicting with InputStream ?