JavaSE - Decorative Design Patterns

Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.

IO:
java.io.OutputStream
方法:

image

FileOutputStream outputs data to disk

image

As shown in the figure below: It is the output data, and the output is a byte

image

As shown in the figure below, the output data is to output multiple bytes

image

The following figure is a file copy, one input channel, one output channel, copied from the source file to the specified file

image

But copying will be very slow. There are two kinds in the machine, one is solid-state hard disk and the other is mechanical hard disk. Your solid-state hard disk is faster, but every time you request a byte, it will go to the hard disk to get one. , the speed of reading one is slower, and the speed of reading more than one is faster. No matter how big, just read it in 8k mode.

image

Decorative design mode: Introduction: It is to process (process) on the basis of the original data to form a new product. The current file flow is byte by byte, just like a river, and the water is drawn out with a pipe. This is a The original transportation is transported through a pool for purification, and after the evolution is completed, a processing area is carried out, and then it is packaged into a bottled water, that is to say, it is processed in the original data to form a new product, and then decorated to form a new product. product, decoration is a process

image

For example: processing the original bytes to form a photo, this kind of processing is a kind of decoding

image

Beverage example: Add new condiments to form a new product on the basis of the original

image

As shown in the pictures below, they are all condiments, you can mix them at will

image

image

image

image

image

Then write a test class, you can mix and match at will

image

BufferedOutputStream continues to buffer in memory

image

ObjectOutputStream

image

mistake:

image

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325189699&siteId=291194637