Category: Streams
Superclass: Iterable
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.

Method category index

accessing-reading (instance)
accessing-writing (instance)
basic (instance)
buffering (instance)
built ins (instance)
character writing (instance)
compiling (instance)
concatenating (instance)
enumerating (instance)
filing out (instance)
filtering (instance)
polymorphism (instance)
positioning (instance)
printing (instance)
still unclassified (instance)
storing (instance)
streaming protocol (instance)
testing (instance)

accessing-reading (instance)

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

file

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

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. Besides stopping if the end of the stream is reached, this may return less than this number of bytes for various reasons. For example, on files and sockets this operation could be non-blocking, or could do at most one I/O operation.

nextAvailable: anInteger into: aCollection startingAt: pos

Place the next anInteger objects from the receiver into aCollection, starting at position pos. Return the number of items stored. Besides stopping if the end of the stream is reached, this may return less than this number of bytes for various reasons. For example, on files and sockets this operation could be non-blocking, or could do at most one I/O operation.

nextAvailable: anInteger putAllOn: aStream

Copy up to anInteger objects in the receiver to aStream. Besides stopping if the end of the stream is reached, this may return less than this number of bytes for various reasons. For example, on files and sockets this operation could be non-blocking, or could do at most one I/O operation.

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

top


accessing-writing (instance)

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.

top


basic (instance)

species
Answer `Array'.

top


buffering (instance)

next: anInteger into: answer startingAt: pos
Read up to anInteger bytes from the stream and store them into answer. Return the number of bytes that were read, raising an exception if we could not read the full amount of data.

next: anInteger putAllOn: aStream

Read up to anInteger bytes from the stream and store them into aStream. Return the number of bytes that were read, raising an exception if we could not read the full amount of data.

top


built ins (instance)

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 file: aFile at: charPosInt

Private - Much like a preprocessor #line directive; it is used internally by #fileIn, and explicitly by the Emacs Smalltalk mode.

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.

top


character writing (instance)

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

top


compiling (instance)

segmentFrom: startPos to: endPos
Answer an object that, when sent #asString, will yield the result of sending `copyFrom: startPos to: endPos' to the receiver

top


concatenating (instance)

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.

top


enumerating (instance)

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).

top


filing out (instance)

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

top


filtering (instance)

, anIterable
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.

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.

top


polymorphism (instance)

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.

top


positioning (instance)

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

skip: anInteger

Move the position forwards by anInteger places

skipSeparators

Advance the receiver until we find a character that is not a separator. Answer false if we reach the end of the stream, else answer true; in this case, sending #next will return the first non-separator character (possibly the same to which the stream pointed before #skipSeparators was sent).

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.

top


printing (instance)

<< 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

top


still unclassified (instance)

nextPutAllOn: aStream
Write all the objects in the receiver to aStream

top


storing (instance)

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

top


streaming protocol (instance)

nextAvailablePutAllOn: aStream
Copy to aStream 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 to do stream-to-stream copies.

top


testing (instance)

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.

top