Back: SortedCollection-searching Up: Base classes Forward: Stream-accessing-reading   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document

1.150 Stream

Defined in namespace Smalltalk
Superclass: Object
Category: Streams
I am an abstract class that provides interruptable sequential access to objects. I can return successive objects from a source, or accept successive objects and store them sequentially on a sink. I provide some simple iteration over the contents of one of my instances, and provide for writing collections sequentially.

1.150.1 Stream: accessing-reading  (instance)
1.150.2 Stream: accessing-writing  (instance)
1.150.3 Stream: basic  (instance)
1.150.4 Stream: built ins  (instance)
1.150.5 Stream: character writing  (instance)
1.150.6 Stream: concatenating  (instance)
1.150.7 Stream: enumerating  (instance)
1.150.8 Stream: filing out  (instance)
1.150.9 Stream: filtering  (instance)
1.150.10 Stream: polymorphism  (instance)
1.150.11 Stream: positioning  (instance)
1.150.12 Stream: printing  (instance)
1.150.13 Stream: storing  (instance)
1.150.14 Stream: testing  (instance)


1.150.1 Stream: accessing-reading

contents
Answer the whole contents of the receiver, from the next object to the last

name
Return nil by default; not all streams have a name.

next
Return the next object in the receiver

next: anInteger
Return the next anInteger objects in the receiver

nextAvailable: anInteger
Return up to anInteger objects in the receiver, stopping if the end of the stream is reached

nextLine
Returns a collection of the same type that the stream accesses, containing the next line up to the next new-line character. Returns the entire rest of the stream's contents if no new-line character is found.

nextMatchFor: anObject
Answer whether the next object is equal to anObject. Even if it does not, anObject is lost

splitAt: anObject
Answer an OrderedCollection of parts of the receiver. A new (possibly empty) part starts at the start of the receiver, or after every occurrence of an object which is equal to anObject (as compared by #=).

upTo: anObject
Returns a collection of the same type that the stream accesses, up to but not including the object anObject. Returns the entire rest of the stream's contents if anObject is not present.

upToAll: aCollection
If there is a sequence of objects remaining in the stream that is equal to the sequence in aCollection, set the stream position just past that sequence and answer the elements up to, but not including, the sequence. Else, set the stream position to its end and answer all the remaining elements.

upToEnd
Answer every item in the collection on which the receiver is streaming, from the next one to the last


1.150.2 Stream: accessing-writing

next: anInteger put: anObject
Write anInteger copies of anObject to the receiver

next: n putAll: aCollection startingAt: start
Write n objects to the stream, reading them from aCollection and starting at the start-th item.

nextPut: anObject
Write anObject to the receiver

nextPutAll: aCollection
Write all the objects in aCollection to the receiver

nextPutAllFlush: aCollection
Put all the elements of aCollection in the stream, then flush the buffers if supported by the stream.


1.150.3 Stream: basic

species
Answer `Array'.


1.150.4 Stream: built ins

fileIn
File in the contents of the receiver. During a file in operation, global variables (starting with an uppercase letter) that are not declared don't yield an `unknown variable' error. Instead, they are defined as nil in the `Undeclared' dictionary (a global variable residing in Smalltalk). As soon as you add the variable to a namespace (for example by creating a class) the Association will be removed from Undeclared and reused in the namespace, so that the old references will automagically point to the new value.

fileInLine: lineNum fileName: aString at: charPosInt
Private - Much like a preprocessor #line directive; it is used internally by #fileIn, and explicitly by the Emacs Smalltalk mode.


1.150.5 Stream: character writing

cr
Store a cr on the receiver

crTab
Store a cr and a tab on the receiver

encoding
Answer the encoding to be used when storing Unicode characters.

isUnicode
Answer whether the receiver is able to store Unicode characters. Note that if this method returns true, the stream may or may not be able to store Characters (as opposed to UnicodeCharacters) whose value is above 127.

nl
Store a new line on the receiver

nlTab
Store a new line and a tab on the receiver

space
Store a space on the receiver

space: n
Store n spaces on the receiver

tab
Store a tab on the receiver

tab: n
Store n tabs on the receiver


1.150.6 Stream: concatenating

with: aStream
Return a new Stream whose elements are 2-element Arrays, including one element from the receiver and one from aStream.

with: stream1 with: stream2
Return a new Stream whose elements are 3-element Arrays, including one element from the receiver and one from each argument.

with: stream1 with: stream2 with: stream3
Return a new Stream whose elements are 3-element Arrays, including one element from the receiver and one from each argument.


1.150.7 Stream: enumerating

do: aBlock
Evaluate aBlock once for every object in the receiver

linesDo: aBlock
Evaluate aBlock once for every line in the receiver (assuming the receiver is streaming on Characters).


1.150.8 Stream: filing out

fileOut: aClass
File out aClass on the receiver. If aClass is not a metaclass, file out class and instance methods; if aClass is a metaclass, file out only the class methods


1.150.9 Stream: filtering

, aStream
Answer a new stream that concatenates the data in the receiver with the data in aStream. Both the receiver and aStream should be readable.

collect: aBlock
Answer a new stream that will pass the returned objects through aBlock, and return whatever object is returned by aBlock instead. Note that when peeking in the returned stream, the block will be invoked multiple times, with possibly surprising results.

fold: aBlock
First, pass to binaryBlock the first and second elements of the receiver; for each subsequent element, pass the result of the previous evaluation and an element. Answer the result of the last invocation, or the first element if the stream has a single element.

inject: value into: aBlock
First, pass to binaryBlock value and the first element of the receiver; for each subsequent element, pass the result of the previous evaluation and an element. Answer the result of the last invocation, or value if the stream is empty.

lines
Answer a new stream that answers lines from the receiver.

peek
Returns the next element of the stream without moving the pointer. Returns nil when at end of stream. Lookahead is implemented automatically for streams that are not positionable but can be copied.

peekFor: aCharacter
Returns true and gobbles the next element from the stream of it is equal to anObject, returns false and doesn't gobble the next element if the next element is not equal to anObject. Lookahead is implemented automatically for streams that are not positionable but can be copied.

reject: aBlock
Answer a new stream that only returns those objects for which aBlock returns false. Note that the returned stream will not be positionable.

select: aBlock
Answer a new stream that only returns those objects for which aBlock returns true. Note that the returned stream will not be positionable.


1.150.10 Stream: polymorphism

close
Do nothing. This is provided for consistency with file streams

flush
Do nothing. This is provided for consistency with file streams

pastEnd
The end of the stream has been reached. Signal a Notification.


1.150.11 Stream: positioning

isPositionable
Answer true if the stream supports moving backwards with #skip:.

nextHunk
Answer a more-or-less arbitrary amount of data. When used on files, this does at most one I/O operation. For other kinds of stream, the definition may vary. This method is used by the VM when loading data from a Smalltalk stream, and by various kind of Stream decorators supplied with GNU Smalltalk (including zlib streams).

skip: anInteger
Move the position forwards by anInteger places

skipTo: anObject
Move the current position to after the next occurrence of anObject and return true if anObject was found. If anObject doesn't exist, the pointer is atEnd, and false is returned.

skipToAll: aCollection
If there is a sequence of objects remaining in the stream that is equal to the sequence in aCollection, set the stream position just past that sequence and answer true. Else, set the stream position to its end and answer false.


1.150.12 Stream: printing

<< anObject
This method is a short-cut for #display:; it prints anObject on the receiver by sending displayOn: to anObject. This method is provided so that you can use cascading and obtain better-looking code

display: anObject
Print anObject on the receiver by sending displayOn: to anObject. This method is provided so that you can use cascading and obtain better-looking code

print: anObject
Print anObject on the receiver by sending printOn: to anObject. This method is provided so that you can use cascading and obtain better-looking code


1.150.13 Stream: storing

store: anObject
Print Smalltalk code compiling to anObject on the receiver, by sending storeOn: to anObject. This method is provided so that you can use cascading and obtain better-looking code


1.150.14 Stream: testing

atEnd
Answer whether the stream has got to an end

isExternalStream
Answer whether the receiver streams on a file or socket. By default, answer false.

isSequenceable
Answer whether the receiver can be accessed by a numeric index with #at:/#at:put:.

readStream
As a wild guess, return the receiver. WriteStreams should override this method.



Back: Stream-storing Up: Stream Forward: String   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document


This document was generated on May, 22 2008 using texi2html