WrappedInputStream

class WrappedInputStream : InputStream, StreamDelegate

This class wraps an input stream.

This somehow helps handling input streams. Looks like one cannot direcly use a sub-classed input stream, so there is a stream kept as an internal variable. In addition there is a computed property to return this variable. That way it can be overwritten by sub classe. Maybe there is a better way to handle this.

  • The internal input stream.

    Declaration

    Swift

    let _stream: InputStream
  • Returns the internal input stream.

    Declaration

    Swift

    var stream: InputStream { get }
  • The internal delegate.

    Declaration

    Swift

    weak var _delegate: StreamDelegate?
  • Initialize a wrapped stream with a given input stream.

    Declaration

    Swift

    init(_ stream: InputStream)

    Parameters

    stream

    The input stream.

  • Indicates whether bytes are available on the wrapped input stream.

    Declaration

    Swift

    override var hasBytesAvailable: Bool { get }
  • Read bytes from the wrapped input stream.

    Declaration

    Swift

    override func read(_ dataPtr: UnsafeMutablePointer<UInt8>, maxLength: Int) -> Int

    Parameters

    dataPtr

    A pointer to the buffer, to which the bytes should be read.

    maxLength

    The maximum lenghts of bytes to be read.

    Return Value

    The amount of bytes actually read.

  • Get the buffer of the wrapped input stream.

    Declaration

    Swift

    override func getBuffer(_ buffer: UnsafeMutablePointer<UnsafeMutablePointer<UInt8>?>, length len: UnsafeMutablePointer<Int>) -> Bool

    Parameters

    buffer

    A pointer to the buffer.

    length

    A pointer to a number, where the length of the buffer will be stored.

    Return Value

    true if the buffer is available.

  • Delegate function for the wrapped stream.

    Declaration

    Swift

    func stream(_ aStream: Stream, handle eventCode: Stream.Event)

    Parameters

    aStream

    The stream calling the delegate. Has to be the wrapped input stream.

    eventCode

    The event that occurred.