Object serialization Comprehension

Source: Internet
Author: User

Object serialization:

Definition of Object serialization: refers to the process of converting parallel data into serial data. Object serialization refers to the process of processing object state data in the form of byte streams, it is generally used to implement complete objects. In short, Object serialization can be understood as object read/write operations implemented using the I/O "Object stream" type.

Object serialization is used to store and transmit data in units of objects.

The main task of Object serialization is to write the object state information and traverse the object to create a reference to other objects, recursively serialize all other referenced objects, to create a complete serialized stream.

Specific Object embodiment:

1. inputstreamreader: a bridge between byte and character.

2. outputstreamwriter: a bridge between characters and bytes.

These two stream objects are members of the render stream system.

Then they have a conversion effect, and they are actually a Failover stream. Therefore, when constructing the object, you need to input the byte stream object.

Constructor:

Inputstreamreader (inputstream): This constructor initializes the data using the default encoding table GBK.

Inputstreamreader (inputstream, stringcharset): This constructor can be used to initialize an encoding table.

Outputstreamwriter (outputstream): This constructor initializes the data using the default encoding table GBK.

Outputstreamwriter (outputstream, stringcharset): This constructor can be used to initialize an encoding table.

Objectinputstream

Objectoutputstream

You can use these two stream objects to directly operate on existing objects and store them locally persistently.

The stored objects can be transmitted over the network.

Two object-specific methods:

Objectinputstream

Object readobject (): This method throws an exception: classnotfountexception.

Objectoutputstream

Voidwriteobject (object): the written object must implement an interface: serializable; otherwise, the system will throw: notserializableexception.

Serializable: this interface is actually a method-free mark interface.

Specify a uid for the class. This uid is a long value calculated by the serializable member's digital signature in the class.

If the serialized object needs to be compatible with different class versions. You can customize the uid in the class.

Definition method: static final longserialversionuid = 42l;

Note: static member variables are not serialized.

For non-static members that do not want to be serialized, they can be modified using the transient keyword.

This object encapsulates byte streams and a buffer (byte array) to manipulate data in the array through internal pointers.

Features:

1. This object can only operate on files, so the constructor receives two types of parameters.

A, string path.

B. File object.

2. The object can be read or written to the file.

The operation mode of the object that must be specified during Object Instantiation.

This object contains methods that can directly operate on basic data types.

The most characteristic method of this object:

Skipbytes (): skips the specified number of bytes.

Seek (): Specifies the position of the pointer.

Getfilepointer (): obtains the pointer position.

Note: During Object Instantiation, if the object to be operated does not exist, it is automatically created.

If the file to be operated exists, it will not be created. If the existing file has data.

If no pointer is specified, data written will overwrite the data starting with the file.

It can be used for multi-threaded download, that is, to store data in a file through multiple threads at the same time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.