08 - Java Serialization with memory buffer - Theory

Опубликовано: 24 Март 2026
на канале: Rishi’s programming channel
163
3

‪@backstreetbrogrammer‬

--------------------------------------------------------------------------------
Chapter 02 - Serialization with memory buffer
--------------------------------------------------------------------------------

The first example is using memory as buffer to where the serialized streams of bytes will be written to and then retrieved from using deserialization.

Java Object ==| Serialize to byte array ==| Memory
Memory ==| Deserialize from byte array ==| Java Object

ByteArrayOutputStream class is used to serialize to byte array. This class implements an output stream in which the data is written into a byte array. The buffer automatically grows as data is written to it. The data can be retrieved using toByteArray() and toString().
ByteArrayInputStream class is used to deserialize from byte array. This class contains an internal buffer that contains bytes that may be read from the stream. An internal counter keeps track of the next byte to be supplied by the read method.

Drawback using memory buffer is that once the JVM shuts down - the serialized data in memory is erased and can not be used after application restart.


Java Serialization Playlist:    • Java Serialization  
Java Serialization Github: https://github.com/backstreetbrogramm...

Dynamic Programming Playlist:    • Dynamic Programming  
Dynamic Programming Github: https://github.com/backstreetbrogramm...

#java #javadevelopers #javaprogramming #javaserialization