Skip to content
This repository was archived by the owner on Jan 16, 2019. It is now read-only.

Stream interfaces

mikey179 edited this page Jan 24, 2012 · 3 revisions

Stream interfaces

Stubbles provides input and output streams for different kind of sources within the net\stubbles\streams package. All input streams implement the net\stubbles\streams\InputStream interface, all output streams the net\stubbles\streams\OutputStream interface. While input streams can be used to read data from a source, output streams can be used to write data to a certain source.

Interfaces and their methods

Input stream methods

The input stream interface provides the following methods:

  • read($length = 8192) - returns given amount of bytes
  • readLine($length = 8192) - returns all characters up to given length until next line break
  • bytesLeft() - returns the amount of bytes left to be read
  • eof() - checks whether end of input was reached
  • close() - closes the stream

Output stream methods

The output stream interface provides the following methods:

  • write($bytes) - writes given bytes and returns amount of written bytes
  • writeLine($bytes) - same as write(), but adds a line break at end of bytes
  • close() - closes the stream

Seekable streams

Some streams are seekable which means you can go from one position in the stream to another. Input streams which are seekable implement the net\stubbles\streams\Seekable interface. It provides the following methods:

  • seek($offset, $whence = Seekable::SET) - sets internal stream pointer to given position
  • tell() - returns the current position of the internal stream pointer
Clone this wiki locally