| Author |
file Serialization
|
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
Serial data is sent one element at a time, like a line of cars on an
assembly line
I read this in Java in 21 days book.But can't understand this.May you explain?
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9939
|
|
serial just means you have one pipe, and everything goes through it one at a time. you send the first bit, then the second, then the third, etc.
parallel means you have multiple pipes, so you can send more than one thing at a time. if you had 8 pipes, you could send each of the bits from a byte all at the same time, and the receiving end could re-assemble them.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16681
|
|
That "line of cars on an assembly line" seems like a silly analogy to me.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
So I can say:
Stream consist of serial bytes, In serialization, an object became serial of bytes in stream. That's why it called serialization.
Right?
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
|
Anyone comfirm?
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
File OurpurStreams write bytes to a file. ObjectOurputStreams turn
objects into data that can be written to a stream. So we make a FileOutputStream that lets
us write to a file, and we hook an ObjectOutputStrearn (a chain stream) on the end of it.
Can I say ObjectOutputStrearn is like a filter for FileOutputStream , so then stream write object?
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3044
|
|
|
Yes.
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
A question:
At first, Does ObjectOurputStream serialize the object, then the object write on FileOutputStream?
Or Does FileOutputStream creates a stream, Then it's filtered by ObjectOurputStream?
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
Think good 00. Each class
does onething well. File OurpurStreams write bytes to a file. ObjectOurputStreams turn
objects into data that can be written to a stream. So we make a FileOutputStream that lets
us write to a file, and we hook an ObjectOutputStrearn (a chain stream) on the end of it.
From Head hhhhehehh
head first java
It is not still clear, Which one first?
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2925
|
|
abalfazl hossein wrote:
Think good 00. Each class
does onething well. File OurpurStreams write bytes to a file. ObjectOurputStreams turn
objects into data that can be written to a stream. So we make a FileOutputStream that lets
us write to a file, and we hook an ObjectOutputStrearn (a chain stream) on the end of it.
From Head hhhhehehh
head first java
It is not still clear, Which one first?
You use FileOutputStream to write to a file. But for that you would need some data to be written to file. So for that you use ObjectOutputStream that uses the objects to create the data. First you would require an ObjectOutputStream, but to that you need to specify which file the data has to be store- so you also need a FileOutputStream. You are delegating the writing to a file to the FileOutputStream and ObjectOutputStream is concerned with creating the data to be written.
Internally ObjectOutputStream has a private class(and it extends OutputStream) which uses this OutputStream (FileOutputStream) passed in the constructor of ObjectOutputStream.
|
Mohamed Sanaulla | My Blog
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
I appreciate Mohammad
But there is question for
In this code data transfers without usage of object outputstream or dataoutputstream or....
But you told:
You use FileOutputStream to write to a file. But for that you would need some data to be written to file. So for that you use ObjectOutputStream that uses the objects to create the data.
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2925
|
|
You use ObjectOutputStream in case of Serialization. And for that you want the data in your objects to be written to the file. In otherwise usual cases you can manually write the data in the objects using FileOutputStream. Consider cases where the objects contain other objects and then that contain other objects- in this case you cannot keep obtaining the data from each instance and then write it to the file. You would need a simpler mechanism and that's where Serialization is used.
And in your example above its a simple case of writing some data to a file. And ObjectOutputStream doesn't come into picture here.
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
Then ObjectOutputStream is like a person, that gets on a bus to go NW.and Bus is FileOutputStream here,
Or FileOutputStream is like a rail, and ObjectOutputStream is like a diesel wagon.
ObjectOutputStream gets on FileOutputStream and goes to destination.
Good example?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32604
|
|
abalfazl hossein wrote: . . . Good example?
No
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
Ohh.... I guess I understand it...May you tell me what is problem about my example?Thanks!
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32604
|
|
|
The streams do not take each other anywhere. They send data across themselves, altering the format of those data for their respective destinations.
|
 |
 |
|
|
subject: file Serialization
|
|
|