Open instantiable class
The class of wrapper-streams.
inner-stream:<stream>.
io
streams
The class that implements the basic wrapper-stream functionality.
It takes a required init-keyword inner-stream:, which is used to specify the wrapped stream.
The <wrapper-stream> class implements default methods for all of the stream protocol functions described in this document. Each default method on <wrapper-stream> simply "trampolines" to its inner stream.
In the example below, <io-wrapper-stream>, a subclass of <wrapper-stream>, "passes on" functions such as read-element and write-element by simply delegating these operations to the inner stream:
define method read-element (ws :: <io-wrapper-stream>,
#key on-end-of-stream)
=> (element)
read-element(ws.inner-stream)
end method;define method write-element (ws :: <io-wrapper-stream>,
element)
=> ()
write-element(ws.inner-stream,element)
end method; Assuming that <io-wrapper-stream> delegates all other operations to its inner stream, the following is sufficient to implement a 16-bit Unicode character stream wrapping an 8-bit character stream.
define class <unicode-stream> (<io-wrapper-stream>) end class;
define method read-element (s :: <unicode-stream>,
#key on-end-of-stream)
=> (ch :: <unicode-character>)
with-stream-locked (s)
let first-char = read-element(s.inner-stream,
on-end-of-stream);
let second-char = read-element(s.inner-stream,
on-end-of-stream);
end;
convert-byte-pair-to-unicode(first-char, second-char)
end method;define method write-element (s :: <unicode-stream>,
c :: <character>)
=> ()
let (first-char, second-char)
= convert-unicode-to-byte-pair(c);
with-stream-locked (s)
write-element(s.inner-stream, first-char);
write-element(s.inner-stream, second-char)
end;
c
end method;define method stream-position (s :: <unicode-stream>) => (p :: <integer>) truncate/(stream-position(s.inner-stream), 2) end method;
define method stream-position-setter (p :: <integer>,
s :: <unicode-stream>);
stream-position(s.inner-stream) := p * 2
end method;