Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inputstream and outputstream

Status
Not open for further replies.

satellite03

IS-IT--Management
Dec 26, 2003
248
IN
i have confusion on "inputstream" and "outputstream".
is this two are interchangable ? suppose i have a program. it needs some binary input, that means i need to feed "inputstream" and when it outputs in binary i would call it "outputstream". but i noticed in some cases things becomes reversed. especially in JSP,Servlets, File upload, file download i confuse these terms.
whats the general rule i should keep in mind ?
can you please explain on this ?
 
This is standard IO - you read from an input stream, you write to an output stream - no exceptions.

--------------------------------------------------
Free Database Connection Pooling Software
 
>This is standard IO - you read from an input stream, you >write to an output stream - no exceptions.

thats good.

suppose , i want to upload a file to a server . then what is inputstream and what is outputstream in this case ?

i am thinking this way,

first i have a source. the source is a file. i will make it a stream i.e a inputstream . now i have to write a program which will take this inputstream and produce a outputstream.Now this outputstream will form a file in the remote server

is this correct ?

thank you for your brave comment.


 
To upload a file to a server, you would :

Create a FileInputStream from the file.
Read the data from the file into a byte[] .
Open a connection to the server.
Send the byte[] to the server using the outputstream.
Read the inputstream from the server.
Done.

--------------------------------------------------
Free Database Connection Pooling Software
 
To upload a file to a server, you would :

Create a FileInputStream from the file.
Read the data from the file into a byte[] .
Open a connection to the server.
Send the byte[] to the server using the outputstream. // line-1
Read the inputstream from the server. // line -2
Done.

is //line-2 is necessary ? you already have sent the data to the server by //line-1 . and //line-1 makes the upload complete. is not it ?
 
No it doesn't - HTTP (I'm guessing you are uploading to a web server) is a two way protocol, and you will probably run into trouble if you do not read the inputstream from the server, as many servers will block on the native send() method.

--------------------------------------------------
Free Database Connection Pooling Software
 
No it doesn't - HTTP (I'm guessing you are uploading to a web server) is a two way protocol, and you will probably run into trouble if you do not read the inputstream from the server, as many servers will block on the native send() method.

i can not undestand your post.
you said
>if you do not read the inputstream from the server

but see, i did not want to download again. i just wanted to upload. so there is no question of further reading inputstream from server, once it has been uploaded.

So , for UPLOAD only // line-2 should be missing from your algorithm. why it can not be done ? i could not understand your point.
 
Sedj is saying that the server may not begin reading data in until you establish a connection to it to accept data back. Http is defined as a two-way request/response protocol, so if you're using http, that may be the way it's handled.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Ok, thats good. so just to make happy the HTTP protocol i have do that.

>Read the inputstream from the server.

How do you codify this statement ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top