Lab 7 EN

Streams are a fundamental abstraction for most I/O facilities. A stream can provide an interface for converting objects into a sequence of bytes or characters. This allows transcription of an object into a file or a string stored in memory for later use. An immediate way to do this is to define an abstract Stream class and the classes derived MemoryStream and FileStream. A buffer is kept in the Stream class and this Stream class contains operations for adding data inside the stream (putInt(int dataInt) and putString (String dataString)). When the buffer is full (the size of the buffer is given when the stream is instantiated), the operation handleBufferFull is invoked for executing the data transfer.

Let’s suppose that we want, in addition to the basic functionality described above, to have a stream providing the next additional features:

  • compression the data stream using different compression algorithms;
  • reducing the data stream to a 7-bit ASCII characters format (7-bit ASCII characters), so that data can be transmitted through a communication channel ASCII.

In the described context:

  • propose a design pattern studied which allow dynamic addition of one of the above additional functionalities to a stream object (or simultaneous addition of both functionalities!).
  • write the code sequence which creates a Stream object to a file named “dummyFile”. Add the integer "12" and the string "aString". The object stream will use both reduced format "7-bit ASCII" and data compression. Implementing the data reducing means to print a message like “Data reducing” on the screen and compressing the data means to print a message like “Data compression” on the screen.