-1

I have a large file that needs to be transferred over socket from server to client. If I want to use writeObject in ObjectOutputStream to send the object, what's the normal way to do it? How about reading at the client side?

Community
  • 1
  • 1
Ting W
  • 29
  • 1
  • 5

2 Answers2

0

Be careful with Object Streams, they have the bad side effect to store and keep the Objects in memory to prevent double instances. Close it as soon as you are done with it.

If the object is large, you can chain your stream with a compressor, there are many good compression Objects in java like DeflatorOutputStream and InflatorInputStream.

For a quick tutorial on how to do it, check this : https://docs.oracle.com/javase/tutorial/essential/io/objectstreams.html

Guillaume F.
  • 5,905
  • 2
  • 31
  • 59
  • Doesn't answer the question, whatever it is. – user207421 Nov 21 '15 at 09:17
  • He didn't ask about (a) appropriateness/pitfalls of using object streams or (b) compression. That merely leaves your link, which makes the relevant parts of this a link-only answer. – user207421 Nov 24 '15 at 00:05
-1

do I need to break the data into different segments ... ?

No. Just call writeObject() at one end and readObject() at the other. TCP will sort out all the segmentation for you.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • @downvoter OK, which is it? You don't call `readObject()`? `writeObject()`? TCP won't sort out all the segmentation for you? Information please. – user207421 Nov 24 '15 at 09:29