Board index » jbuilder » Re: break down of file transfer concept

Re: break down of file transfer concept


2003-07-16 11:33:58 AM
jbuilder21
On 7/15/2003 at 5:32:31 PM, Alan Shiers wrote:
Quote
The concept for receiving a file on the server, as I understand it,
goes like this:
1) Create a byte array the size needed to contain all data of the
file. 2) Read in the bytes of info coming in though an InputStream
and put the data into the byte array.
3) Create a File on the hard drive, connect to it with an
OutputStream. 4) Then move the data collected in the byte array into
the file via the OutputStream.
That is not the ideal approach, since it places limitations on the size
of file that you can transfer. You would be much better off if you
read the file in chunks and passed each chunk over to the server, one
at a time.
Quote
when I'm trying to transfer large zipped files [anything over 1Mbyte]
the file never seems to be received intacted.
My guess is that you are running into some limitation in the network
software. Try sending the file over piecemeal, with a buffer size on
the order of 4K. If that works, you will probably want to experiment
with larger buffer sizes, since you might get better performance that
way.
--
Regards,
John McGrath [TeamB]
 
 

Re:Re: break down of file transfer concept

John, you really helped to clarify a thorn in my side for many months of
frustrating coding over this problem of uploading/downloading files.
Many months ago I tried moving the data in chunks of 256 bytes at a
time, again with only moderate success. So I know how that part was
supposed to work. What clinched it for me was when you said, "Try
sending the file over piecemeal, with a buffer size on the order of 4K.
If that works, you will probably want to experiment with larger buffer
sizes, since you might get better performance that way."
That really got me to thinking...immediately I took a closer look at the
constructors of the BufferedInputStream and BufferedOutputStream classes
and as I suspected there is one constructor in each where you can set
the buffer size. This is what I was missing!!!! This is what I had not
noticed or experimented with before!!!
As you recommended, I tweaked my code while adding the 4Kb buffer size
on my stream classes. This made all the difference in the world. Now
I'm able to upload/download my large files without having them
scrambled.
Thanks again,
Alan