Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > transferring large amounts of data

Thread Tools

transferring large amounts of data

Posts: n/a

I have several questions.

I want to transfer a 1MB file between two machines using TCP sockets.
Assume, for some strange reason, that I have all my 1MB stored in a byte
array in memory (inefficient, I know) and want to transfer it over the
socket. Will that work? Or will the receiver side give me trouble?

Is it possible to use PIPEs to connect the File directly to the

I know that the most sensible way would be neither of the above, but to
probably read chunks at a while and transfer the whole thing in chunks.

Reply With Quote
Posts: n/a
The read() call on the receiving side can use a buffer of arbitrary
length- you might just have to call read() more often if you use a very
small buffer.
Note that the read() call will most probably NOT fill a 1-Mbyte buffer,
but will return after reading less data. So you have to interpret the
return value of your call ! (If you know that there
is a 1Mbyte chunk coming, you have to call read() in a loop until all
data is read.
The following piece of code might help you:
public static void readCompleteBlocking(InputStream is,byte[] target)
throws IOException
int readBytes=0;
if(read<1)throw new IOException("read() returned 0 or

Reply With Quote
Posts: n/a
On 31 Oct 2005 11:27:10 -0800, "(E-Mail Removed)"
<(E-Mail Removed)> wrote:

>Note that the read() call will most probably NOT fill a 1-Mbyte buffer,
>but will return after reading less data.

So true. Yet one might think (at least I did) that calling available()
would give an approximation of the ideal size for the input array.
This being especially true for J2ME where you don't want to just go
around creating large arrays in the limited available memory.

But this was not true, in my limited tests. While available() showed
500, the total read time (in millis) did not suffer (reading from a
server on localhost) until less than ~100 bytes were read at a clip.

Maybe that's just a J2ME thing, though.

Reply With Quote

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
Opinion: Optimal way of holding large amounts of data between pages? David ASP .Net 0 06-21-2006 08:08 PM
HTTP POST to send large amounts of data? Bint HTML 1 03-19-2006 02:11 PM
storing large amounts of data in a list/dictionary flamesrock Python 2 03-12-2005 04:59 AM
Handling large amounts of data Wayne Marsh C Programming 3 11-20-2004 11:40 PM
Using Dataset for large amounts of data Brent ASP .Net 3 04-07-2004 01:43 PM