Bhuvanesh Waran
Bhuvanesh Waran

Reputation: 642

Max object size in java

Hi I am new to transferring objects from server to client in JAVA. Can any one knows what is the max size of object that I can transfer from client to server over a SSL network.

As of now am transferring the object from client to server over a SSL network with the two string types, one long type, three date types and one map type of values.

With this I need to add one byte[] type in my object before transfer the object from client to server.

For the value of byte[] I will read an output file of my process and set as the value of its. In my process I don't know how much byte would be in that file.

So can any one tell me if I set the file content in byte[] and transfer over a network any data losses will occur? Can I get my full value after received in server side?

Give me a good suggestion. Thanks in advance.

Upvotes: 1

Views: 501

Answers (1)

user207421
user207421

Reputation: 311023

Can any one knows what is the max size of object that I can transfer from client to server over a SSL network.

  • There is no limit to the size of an SSL transfer, or a TCP transfer either.
  • There is no limit on Java object size other than the maximum number of elements in an array (and available RAM of course).

I need to add one byte[] type in my object before transfer the object from client to server.

For the value of byte[] I will read an output file of my process and set as the value of its. In my process I don't know how much byte would be in that file.

You need to rethink that part of your protocol. A byte[] is limited to 2^31-1 elements, and files can be far bigger than that. You'll have trouble allocating large arrays, reading large files into memory, and reconstituting them at the other end. You should redesign your protocol around sending files in chunks of manageable size, say 8k or 32k at a time, with a length word prefix and an indication of which is the final chunk.

So can any one tell me if I set the file content in byte[] and transfer over a network any data losses will occur?

TCP won't lose data. You'll have the problems I mentioned above when sending, and comparable problems when receiving. Don't do it this way.

Can I get my full value after received in server side?

You can read as much as you like, but you need to be aware that read() isn't contracted to transfer more than one byte at a time. If you expect more, you need to read in a loop until you have everything you expect.

Upvotes: 1

Related Questions