eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'PeekableStream':

Home

everywhere
www.exept.de
for:
[back]

Class: PeekableStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--PeekableStream
         |
         +--ActorStream
         |
         +--EncodedStream
         |
         +--FilteringStream
         |
         +--PositionableStream
         |
         +--ZipArchive::AbstractZipStream

Package:
stx:libbasic
Category:
Streams
Version:
rev: 1.39 date: 2010/03/12 12:39:13
user: cg
file: PeekableStream.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


abstract superclass for all Stream which support read-ahead
(i.e. peeking) of one element.
Concrete subclasses must implement a peek method.


Class protocol:

Signal constants
o  currentFileInDirectoryQuerySignal
return the querySignal, which can be used to ask for the current directory
during a fileIn (that is the directory where the filed-in file resides),
and in a fileBrowsers doIt.
Using this, allows for the loaded code or doIts to ask for the fileBrowsers
current directory, by asking this querySignal (which is nice sometimes).

o  currentSourceContainerQuery
return the querySignal, which can be used to ask for the current source container filename
during a fileIn
Using this, allows for the loaded code to remember the classes file name.

initialization
o  initialize
setup the signal used to handle errors during fileIn

queries
o  currentFileInDirectory
during a fileIn (if a script), the script can ask for the current directory

o  currentSourceContainer
during a fileIn (if a script), the script can ask for the current filename


Instance protocol:

chunk input/output
o  nextChunk
return the next chunk, i.e. all characters up to the next
exclamation mark. Within the chunk, exclamation marks have to be doubled,
they are undoubled here.
Except for primitive code, in which doubling is not needed (allowed).
This exception was added to make it easier to edit primitive code with
external editors. However, this means, that other Smalltalks cannot always
read chunks containing primitive code
- but that doesn't really matter, since C-primitives are an ST/X feature anyway.

fileIn
o  fileIn
file in from the receiver, i.e. read chunks and evaluate them -
return the value of the last chunk.

o  fileInBinary
file in from the receiver, i.e. read binary stored classes and/or objects.
Return the last object.

positioning
o  skipAny: skipCollection
skip all characters included in the argument-set.
returns the next peeked element or nil, if the end-of-stream was reached.

o  skipSeparators
skip all whitespace; returns the next peeked element or
nil, if the end-of-stream was reached.
The streams elements should be characters.
Notice: compare this method to skipSpaces

o  skipSeparatorsExceptCR
skip all whitespace except carriage return; returns the
next peeked element or nil, if the end-of-stream was reached.
The streams elements should be characters.
Notice: compare this method to skipSpaces and skipSeparators

o  skipSpaces
skip all spaces; returns the next peeked element or
nil, if the end-of-stream was reached.
The streams elements should be characters.
Notice: this one skips only spaces (i.e. no cr, tabs etc)
usually, skipSeparators is what you want.

private fileIn
o  basicFileInNotifying: someone passChunk: passChunk
central method to file in from the receiver, i.e. read chunks and evaluate them -
return the value of the last chunk.
Someone (which is usually some codeView) is notified of errors.

o  fileInNextChunkNotifying: someone
read next chunk, evaluate it and return the result;
someone (which is usually some codeView) is notified of errors.
Filein is done as follows:
read a chunk
if it started with an excla, evaluate it, and let the resulting object
fileIn more chunks.
This is a nice trick, since the methodsFor: expression evaluates to
a ClassCategoryReader which reads and compiles chunks for its class.
However, other than methodsFor expressions are possible - you can
(in theory) create readers for any syntax.

o  fileInNextChunkNotifying: someone passChunk: passChunk
read next chunk, evaluate it and return the result;
someone (which is usually some codeView) is notified of errors.
Filein is done as follows:
read a chunk
if it started with an excla, evaluate it, and let the resulting object
fileIn more chunks.
This is a nice trick, since the methodsFor: expression evaluates to
a ClassCategoryReader which reads and compiles chunks for its class.
However, other than methodsFor expressions are possible - you can
(in theory) create readers for any syntax.

o  fileInNextChunkNotifying: someone passChunk: passChunk silent: beSilent
read next chunk, evaluate it and return the result;
someone (which is usually some codeView) is notified of errors.
Filein is done as follows:
read a chunk
if it started with an excla, evaluate it, and let the resulting object
fileIn more chunks.
This is a nice trick, since the methodsFor: expression evaluates to
a ClassCategoryReader which reads and compiles chunks for its class.
However, other than methodsFor expressions are possible - you can
(in theory) create readers for any syntax.

o  fileInNotifying: notifiedLoader passChunk: passChunk
central method to file in from the receiver, i.e. read chunks and evaluate them -
return the value of the last chunk.
Someone (which is usually some codeView) is notified of errors.

o  fileInXMLNotifying: someone passChunk: passChunk
filein an XML source file (format as in campSmalltalk DTD)

reading
o  nextDecimalInteger
read the next integer in radix 10. Does NOT skip initial whitespace.
The streams elements should be characters.
Be careful - this method returns 0 if not posiioned on a digit intitially
or if the end of the stream is encountered.

o  nextDelimited: terminator
return the contents of the receiver, up to the next terminator character.
Doubled terminators indicate an embedded terminator character.
For example: 'this '' was a quote'.
Start postioned before the initial terminator.

o  nextPeek
advance to next element and return the peeked element

o  nextUpTo: anObject
read a collection of all objects up-to anObject and return these
elements, but excluding anObject.
The next read operation will return anObject.
If anObject is not encountered, all elements up to the end are read
and returned, and the stream is positioned at the end.
Compare this with #upTo: which positions behind anObject

o  peek
return the next element of the stream without advancing (i.e.
the following send of next will return this element again.)
- we do not know here how to do it, it must be redefined in subclass

** This method raises an error - it must be redefined in concrete classes **

o  peekFor: anObject
if the next-to-be-read object is equal to the argument, anObject, read it
and return true. Otherwise, leave the receiver unaffected and return false.

o  peekOrNil
like #peek, this returns the next readAhead element, if available.
However, unlike #peek, this does not raise an atEnd-query signal - even
if handled. Instead, nil is returned immediately.

o  throughAnyForWhich: checkBlock
read & return a collection of all objects up-to and including
the elements for which checkBlock returns true.
(i.e. read until checkBlock returns false on an element)
If no such element is encountered, all elements up to the end are read
and returned.

o  upToMatching: aBlock
Return the next elements up to but not including the next element
for which aBlock returns true.
The next read will return that matching element.

o  upToSeparator
Return the next elements up to but not including the next separator.
The next read will return the separator.
If no separator is encountered, the contents up to the end is returned.
The elements are supposed to understand #isSeparator
(i.e. the receiver is supposed to be a character-stream).

reading-strings
o  nextAlphaNumericWord
read the next word (i.e. up to non letter-or-digit).
Return a string containing those characters.
Any leading non-alphaNumeric chars are skipped.

o  nextMatching: matchBlock1 thenMatching: matchBlock2
read the next word. The first character must match matchBlock1,
remaining characters must match matchBlock2.
Return a string containing those characters.

o  nextSymbol
read the next selector-symbol (i.e. up to non letter-or-digit).
Return a string containing those characters.
Any leading non-alphaNumeric chars are skipped.

o  nextWord
return the next characters which form an alphanumeric word
(i.e. everything upTo (but excluding) the next non alphanumeric
element)



ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 20:36:26 GMT