Collections-Streams

LimitedWriteStream
A LimitedWriteStream is a specialized WriteStream that has a maximum size of the collection it streams over. When this limit is reached a special limitBlock is executed. This can for example be used to "bail out" of lengthy streaming operations before they have finished. For a simple example take a look at the universal Object printString.
The message SequenceableCollection class streamContents:limitedTo: creates a LimitedWriteStream. In this case it prevents very large (or possibly recursive) object structures to "overdo" their textual representation.
nextPut:
Ensure that the limit is not exceeded
nextPutAll:
Append the elements of aCollection to the sequence of objects accessible
by the receiver. Answer aCollection.
pastEndPut:
Grow the collection by doubling the size, but keeping the growth between 20 and 1000000.
Then put <anObject> at the current write position.
setLimit:limitBlock:
Limit the numer of elements this stream will write...
LimitingLineStreamWrapper
I'm a wrapper for a stream optimized for line-by-line access using #nextLine. My instances can be nested.
I read one line ahead. Reading terminates when the stream ends, or if the limitingBlock evaluated with the line answers true. To skip the delimiting line for further reading use #skipThisLine.
Character-based reading (#next) is permitted, too. Send #updatePosition when switching from line-based reading.
See examples at the class side.
--bf 2/19/1999 12:52
atEnd
close
delimiter:
Set limitBlock to check for a delimiting string. Be unlimiting if nil
example1
example2
exampleStream
lastLineRead
Return line last read. At stream end, this is the boundary line or nil
limitingBlock:
The limitingBlock is evaluated with a line to check if this line terminates the stream
linesUpToEnd
next
Provide character-based access
nextLine
on:delimiter:
peekLine
printOn:
Append to the argument, aStream, a sequence of characters that
identifies the receiver.
setStream:delimiter:
skipThisLine
upToEnd
updatePosition
Call this before doing character-based access
PositionableStream
I represent an accessor for a sequence of objects (a collection) that are externally named by indices so that the point of access can be repositioned. I am abstract in that I do not implement the messages next and nextPut: which are inherited from my superclass Stream.
asBinaryOrTextStream
Convert to a stream that can switch between bytes and characters
asMIMEDocument
asMIMEDocumentType:
asZLibReadStream
atEnd
Primitive. Answer whether the receiver can access any more objects.
Optional. See Object documentation whatIsAPrimitive.
back
Go back one element and return it.
backChunk
Answer the contents of the receiver back to the previous terminator character. Doubled terminators indicate an embedded terminator character.
backUpTo:
Back up the position to he subCollection. Position must be somewhere within the stream initially. Leave it just after it. Return true if succeeded. No wildcards, and case does matter.
basicNextChunk
Answer the contents of the receiver, up to the next terminator character. Doubled terminators indicate an embedded terminator character.
boolean
Answer the next boolean value from this (binary) stream.
boolean:
Store the given boolean value on this (binary) stream.
checkForPreamble:
contents
Answer with a copy of my collection from 1 to readLimit.
contentsOfEntireFile
For non-file streams
copyMethodChunkFrom:
Copy the next chunk from aStream (must be different from the receiver).
copyMethodChunkFrom:at:
Copy the next chunk from aStream (must be different from the receiver).
copyPreamble:from:at:
Look for a changeStamp for this method by peeking backward.
Write a method preamble, with that stamp if found.
decodeString:andRuns:
decodeStyle:version:
Decode the runs array from the ReferenceStream it is stored in.
fileIn
This is special for reading expressions from text that has been formatted
with exclamation delimitors. The expressions are read and passed to the
Compiler. Answer the result of compilation.
fileInAnnouncing:
This is special for reading expressions from text that has been formatted
with exclamation delimitors. The expressions are read and passed to the
Compiler. Answer the result of compilation. Put up a progress report with
the given announcement as the title.
fileInFor:announcing:
This is special for reading expressions from text that has been formatted
with exclamation delimitors. The expressions are read and passed to the
Compiler. Answer the result of compilation. Put up a progress report with
the given announcement as the title.
Does NOT handle preambles or postscripts specially.
fileInSilentlyAnnouncing:
This is special for reading expressions from text that has been formatted
with exclamation delimitors. The expressions are read and passed to the
Compiler. Answer the result of compilation. Put up a progress report with
the given announcement as the title.
header
If the stream requires a standard header, override this message. See HtmlFileStream
int16
Answer the next signed, 16-bit integer from this (binary) stream.
int16:
Store the given signed, 16-bit integer on this (binary) stream.
int32
Answer the next signed, 32-bit integer from this (binary) stream.
int32:
Store the given signed, 32-bit integer on this (binary) stream.
isBinary
Return true if the receiver is a binary byte stream
isEmpty
Answer whether the receiver's contents has no elements.
last
Return the final element in the receiver
match:
Set the access position of the receiver to be past the next occurrence of the subCollection. Answer whether subCollection is found. No wildcards, and case does matter.
next:
Answer the next anInteger elements of my collection. Must override
because default uses self contents species, which might involve a large
collection.
next:into:
Read n objects into the given collection.
Return aCollection or a partial copy if less than
n elements have been read.
next:into:startingAt:
Read n objects into the given collection.
Return aCollection or a partial copy if less than
n elements have been read.
next:putAll:
Store the next anInteger elements from the given collection.
next:putAll:startingAt:
Store the next anInteger elements from the given collection.
nextChunk
Answer the contents of the receiver, up to the next terminator character. Doubled terminators indicate an embedded terminator character.
nextChunkText
Deliver the next chunk as a Text. Decode the following ]style[ chunk if present. Position at start of next real chunk.
nextDelimited:
Answer 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.
nextInt32
Read a 32-bit signed integer from the next 4 bytes
nextInt32Put:
Write a signed integer to the next 4 bytes
nextInto:
Read the next elements of the receiver into aCollection.
Return aCollection or a partial copy if less than aCollection
size elements have been read.
nextInto:startingAt:
Read the next elements of the receiver into aCollection.
Return aCollection or a partial copy if less than aCollection
size elements have been read.
nextLine
Answer next line (may be empty), or nil if at end
nextLittleEndianNumber:
Answer the next n bytes as a positive Integer or LargePositiveInteger, where the bytes are ordered from least significant to most significant.
nextLittleEndianNumber:put:
Answer the next n bytes as a positive Integer or LargePositiveInteger, where the bytes are ordered from least significant to most significant.
nextNumber:
Answer the next n bytes as a positive Integer or LargePositiveInteger.
nextNumber:put:
Append to the receiver the argument, v, which is a positive
SmallInteger or a LargePositiveInteger, as the next n bytes.
Possibly pad with leading zeros.
nextString
Read a string from the receiver. The first byte is the length of the string, unless it is greater than 192, in which case the first four bytes encode the length. I expect to be in ascii mode when called (caller puts back to binary).
nextStringOld
Read a string from the receiver. The first byte is the length of the
string, unless it is greater than 192, in which case the first *two* bytes
encode the length. Max size 16K.
nextStringPut:
Append the string, s, to the receiver. Only used by DataStream. Max size of 64*256*256*256.
nextWord
Answer the next two bytes from the receiver as an Integer.
nextWordPut:
Append to the receiver an Integer as the next two bytes.
nextWordsInto:
Fill the word based buffer from my collection.
Stored on stream as Big Endian. Optimized for speed.
Read in BigEndian, then restoreEndianness.
oldBack
Go back one element and return it. Use indirect messages in case I am a StandardFileStream
oldPeekBack
Return the element at the previous position, without changing position. Use indirect messages in case self is a StandardFileStream.
on:
on:from:to:
originalContents
Answer the receiver's actual contents collection, NOT a copy. 1/29/96 sw
padTo:put:
Pad using the argument, aCharacter, to the next boundary of nBytes characters.
padToNextLongPut:
Make position be on long word boundary, writing the padding
character, char, if necessary.
parseLangTagFor:
peek
Answer what would be returned if the message next were sent to the
receiver. If the receiver is at the end, answer nil.
peekBack
Return the element at the previous position, without changing position. Use indirect messages in case self is a StandardFileStream.
peekFor:
Answer false and do not move over the next element if it is not equal to
the argument, anObject, or if the receiver is at the end. Answer true
and increment the position for accessing elements, if the next element is
equal to anObject.
position
Answer the current position of accessing the sequence of objects.
position:
Set the current position for accessing the objects to be anInteger, as long
as anInteger is within the bounds of the receiver's contents. If it is not,
create an error notification.
positionError
Since I am not necessarily writable, it is up to my subclasses to override
position: if expanding the collection is preferrable to giving this error.
positionOfSubCollection:
Return a position such that that element at the new position equals the first element of sub, and the next elements equal the rest of the elements of sub. Begin the search at the current position.
If no such match is found, answer 0.
positionOfSubCollection:ifAbsent:
Return a position such that that element at the new position equals the first element of sub, and the next elements equal the rest of the elements of sub. Begin the search at the current position.
If no such match is found, answer the result of evaluating argument, exceptionBlock.
pushBack:
Compatibility with SocketStreams
reset
Set the receiver's position to the beginning of the sequence of objects.
resetContents
Set the position and limits to 0.
setFrom:to:
setToEnd
Set the position of the receiver to the end of the sequence of objects.
skip:
Set the receiver's position to be the current position+anInteger. A
subclass might choose to be more helpful and select the minimum of the
receiver's size and position+anInteger, or the maximum of 1 and
position+anInteger for the repositioning.
skipSeparators
skipSeparatorsAndPeekNext
A special function to make nextChunk fast
skipStyleChunk
Get to the start of the next chunk that is not a style for the previous chunk
skipTo:
Set the access position of the receiver to be past the next occurrence of
anObject. Answer whether anObject is found.
string
Answer the next string from this (binary) stream.
string:
Store the given string on this (binary) stream. The string must contain 65535 or fewer characters.
trailer
If the stream requires a standard trailer, override this message. See HtmlFileStream
uint16
Answer the next unsigned, 16-bit integer from this (binary) stream.
uint16:
Store the given unsigned, 16-bit integer on this (binary) stream.
uint24
Answer the next unsigned, 24-bit integer from this (binary) stream.
uint24:
Store the given unsigned, 24-bit integer on this (binary) stream.
uint32
Answer the next unsigned, 32-bit integer from this (binary) stream.
uint32:
Store the given unsigned, 32-bit integer on this (binary) stream.
unCommand
If this read stream is at a <, then skip up to just after the next >. For removing html commands.
untilEnd:displayingProgress:
untilEndWithFork:displayingProgress:
upTo:
Answer a subcollection from the current access position to the
occurrence (if any, but not inclusive) of anObject in the receiver. If
anObject is not in the collection, answer the entire rest of the receiver.
upToAll:
Answer a subcollection from the current access position to the occurrence (if any, but not inclusive) of aCollection. If aCollection is not in the stream, answer the entire rest of the stream.
upToAndSkipThroughAll:
Needed for Seaside ports to other dialects where #upToAll: may have
different semantics
upToAny:
Answer a subcollection from the current access position to the
occurrence (if any, but not inclusive) of any objects in the given collection in the receiver. If
any of these is not in the collection, answer the entire rest of the receiver.
upToEnd
Answer a subcollection from the current access position through the last element of the receiver.
verbatim:
Do not attempt to translate the characters. Use to override nextPutAll:
RWBinaryOrTextStream
A simulation of a FileStream, but living totally in memory. Hold the contents of a file or web page from the network. Can then fileIn like a normal FileStream.
Need to be able to switch between binary and text, as a FileStream does, without recopying the whole collection. Convert to binary upon input and output. Always keep as text internally.
asBinaryOrTextStream
Convert to a stream that can switch between bytes and characters
ascii
binary
do nothing
contents
Answer with a copy of my collection from 1 to readLimit.
isBinary
Return true if the receiver is a binary byte stream
next
Primitive. Return the next object in the Stream represented by the
receiver. Fail if the collection of this stream is not an Array or a String.
Fail if the stream is positioned at its end, or if the position is out of
bounds in the collection. Optional. See Object documentation
whatIsAPrimitive.
next:
Answer the next anInteger elements of my collection. Must override to get class right.
next:into:startingAt:
Read n objects into the given collection.
Return aCollection or a partial copy if less than n elements have been read.
next:putAll:startingAt:
Optimized for ByteArrays
nextPut:
Primitive. Insert the argument at the next position in the Stream
represented by the receiver. Fail if the collection of this stream is not an
Array or a String. Fail if the stream is positioned at its end, or if the
position is out of bounds in the collection. Fail if the argument is not
of the right type for the collection. Optional. See Object documentation
whatIsAPrimitive.
nextPutAll:
Optimized for ByteArrays
padToEndWith:
We don't have pages, so we are at the end, and don't need to pad.
reset
Set the receiver's position to the beginning of the sequence of objects.
setFileTypeToObject
do nothing. We don't have a file type
text
upTo:
Answer a subcollection from the current access position to the
occurrence (if any, but not inclusive) of anObject in the receiver. If
anObject is not in the collection, answer the entire rest of the receiver.
upToEnd
Must override to get class right.
ReadStream
I represent an accessor for a sequence of objects that can only read objects from the sequence.
ascii
localName
next
Primitive. Answer the next object in the Stream represented by the
receiver. Fail if the collection of this stream is not an Array or a String.
Fail if the stream is positioned at its end, or if the position is out of
bounds in the collection. Optional. See Object documentation
whatIsAPrimitive.
next:
Answer the next anInteger elements of my collection. overriden for efficiency
next:into:startingAt:
Read n objects into the given collection.
Return aCollection or a partial copy if less than
n elements have been read.
nextPut:
Insert the argument, anObject, as the next object accessible by the
receiver. Answer anObject.
on:from:to:
readStream
polymorphic with SequenceableCollection. Return self
size
Compatibility with other streams (e.g., FileStream)
upTo:
fast version using indexOf:
upToEnd
Answer a subcollection from the current access position through the last element of the receiver.
ReadWriteStream
I represent an accessor for a sequence of objects. My instances can both read and store objects.
=
Answer whether the receiver and the argument represent the same
object. If = is redefined in any subclass, consider also redefining the
message hash.
asHttpResponseTo:
asUnZippedStream
Decompress this file if needed, and return a stream. No file is written. File extension may be .gz or anything else. Also works on archives (.zip, .gZip).
contents
Answer with a copy of my collection from 1 to readLimit.
fileInObjectAndCode
This file may contain:
1) a fileIn of code
2) just an object in SmartReferenceStream format
3) both code and an object.
File it in and return the object. Note that self must be a FileStream or RWBinaryOrTextStream. Maybe ReadWriteStream incorporate RWBinaryOrTextStream?
fileNameEndsWith:
See comment in FileStream fileNameEndsWith:
fileOutChangeSet:andObject:
Write a file that has both the source code for the named class and an object as bits. Any instance-specific object will get its class written automatically.
fileOutChanges
Append to the receiver a description of all class changes.
fileOutClass:andObject:
Write a file that has both the source code for the named class and an object as bits. Any instance-specific object will get its class written automatically.
fileOutClass:andObject:blocking:
Write a file that has both the source code for the named class and an object as bits. Any instance-specific object will get its class written automatically. Accept a list of objects to map to nil or some other object (blockers). In addition to teh choices in each class's objectToStoreOnDataStream
hash
Answer a SmallInteger whose value is related to the receiver's identity.
May be overridden, and should be overridden in any classes that define =
isZipArchive
Determine if this appears to be a valid Zip archive
name
Answer a name for the receiver. This is used generically in the title of certain inspectors, such as the referred-to inspector, and specificially by various subsystems. By default, we let the object just print itself out..
next
Primitive. Return the next object in the Stream represented by the
receiver. Fail if the collection of this stream is not an Array or a String.
Fail if the stream is positioned at its end, or if the position is out of
bounds in the collection. Optional. See Object documentation
whatIsAPrimitive.
next:
Answer the next anInteger elements of my collection. overriden for efficiency
readStream
polymorphic with SequenceableCollection. Return self
Stream
I am an abstract class that represents an accessor for a sequence of objects. This sequence is referred to as my "contents".
<<
arguments:
asHttpResponseTo:
atEnd
Answer whether the receiver can access any more objects.
basicNext
basicNextPut:
basicNextPutAll:
binary
do nothing
close
Presumably sets the status of the receiver to be closed. This message does
nothing at this level, but is included for FileStream compatibility.
closed
contents
Answer all of the contents of the receiver.
do:
Evaluate aBlock for each of the objects accessible by receiver.
flush
Do nothing by default
isMessageStream
isStream
Return true if the receiver responds to the stream protocol
isTranscriptStream
isTypeHTTP
javascript:
localName
new
next
Answer the next object accessible by the receiver.
next:
Answer the next anInteger number of objects accessible by the receiver.
next:put:
Make anObject be the next anInteger number of objects accessible by the
receiver. Answer anObject.
nextMatchAll:
Answer true if next N objects are the ones in aColl,
else false. Advance stream of true, leave as was if false.
nextMatchFor:
Gobble the next object and answer whether it is equal to the argument,
anObject.
nextPut:
Insert the argument, anObject, as the next object accessible by the
receiver. Answer anObject.
nextPutAll:
Append the elements of aCollection to the sequence of objects accessible
by the receiver. Answer aCollection.
nextWordsPutAll:
Write the argument a word-like object in big endian format on the receiver.
May be used to write other than plain word-like objects (such as ColorArray).
openReadOnly
print:
Have anObject print itself on the receiver.
printOn:
Append to the argument, aStream, a sequence of characters that
identifies the receiver.
readOnly
sleep
an FTP-based stream might close the connection here
upToEnd
answer the remaining elements in the string
write:
TextStream
A TextStream is xxxxxxxxx.
Instance Variables
applyAttribute:beginningAt:
nextPutAll:
Optimized access to get around Text at:Put: overhead
withAttribute:do:
No-op here is overriden in TextStream for font emphasis
withAttributes:do:
No-op here is overriden in TextStream for font emphasis
TranscriptStream
This class is a much simpler implementation of Transcript protocol that supports multiple views and very simple conversion to morphic. Because it inherits from Stream, it is automatically compatible with code that is designe to write to streams.
bs
buildWith:
characterLimit
Tell the views how much to retain on screen
clear
Clear all characters and redisplay the view.
close
Presumably sets the status of the receiver to be closed. This message does
nothing at this level, but is included for FileStream compatibility.
codePaneMenu:shifted:
Note that unless we override perform:orSendTo:, PluggableTextController will respond to all menu items
endEntry
Display all the characters since the last endEntry, and reset the stream
flush
Do nothing by default
initialExtent
Answer the desired extent for the receiver when a view on it is first opened on the screen.
5/22/96 sw: in the absence of any override, obtain from RealEstateAgent
initialize
Subclasses should redefine this method to perform initializations on instance creation
isSelfEvaluating
isTranscriptStream
new
newTranscript:
open
openAsMorph
Answer a morph viewing this transcriptStream
openAsMorphLabel:
Build a morph viewing this transcriptStream
openLabel:
Open a window on this transcriptStream
openMorphicTranscript
pastEndPut:
If the stream reaches its limit, just output the contents and reset.
perform:orSendTo:
Selector was just chosen from a menu by a user. If can respond, then
perform it on myself. If not, send it to otherTarget, presumably the
editPane from which the menu was invoked.
printOn:
Append to the argument, aStream, a sequence of characters that
identifies the receiver.
registerInFlapsRegistry
release
Remove references to objects that may refer to the receiver. This message
should be overridden by subclasses with any cycles, in which case the
subclass should also include the expression super release.
semaphore
show:
TextCollector compatibility
step
Objects that may be models of SystemWindows need to respond to this, albeit vacuously
unload
windowColorSpecification
Transcripter
Transcripter is a dog-simple scrolling stream with display. It is intended to operate with no support from MVC or color in a minimal, or headless version of Squeak. No attention has been paid to appearance or performance.
black
clear
confirm:
Put up a yes/no menu with caption queryString. Answer true if the
response is yes, false if no. This is a modal question--the user must
respond yes or no.
emergencyEvaluator
endEntry
No-op for compatibility with TranscriptStream.
initInFrame:
isTranscriptStream
newInFrame:
readEvalPrint
request:
show:
startTranscriptProcess
white
WriteStream
I represent an accessor for a sequence of objects that can only store objects in the sequence.
<<
we want a readable version of nextPutAll however it may be difficult to fully recreate nextPutAll:
for all the different types of stream. Rather then simply send to nextPutAll:
we handle the String (or ByteArray) argument
as fast as possible - the rest we delegate to putOn: This means that we handle single characters and bytes
whereas nextPutAll: is only for sequencable collections.
.
Note this may not work in every case that nextPutAll: does subject to extensive testing,
but it should work in the important cases
asHttpResponseTo:
braceArray
This method is used in compilation of brace constructs.
It MUST NOT be deleted or altered.
braceArray:
This method is used in compilation of brace constructs.
It MUST NOT be deleted or altered.
contentType
contents
Answer with a copy of my collection from 1 to readLimit.
cr
Append a return character to the receiver.
crlf
crtab
Append a return character, followed by a single tab character, to the
receiver.
crtab:
Append a return character, followed by anInteger tab characters, to the
receiver.
endEntry
No-op for compatibility with TranscriptStream.
ensureASpace
Append a space character to the receiver IFF there is not one on the end.
ensureEndsWith:
Append anObject to the receiver IFF there is not one on the end.
ensureNoSpace
If there is not one on the end, remove it.
growTo:
anInteger is the required minimal new size of the collection
next
Answer the next object accessible by the receiver.
next:putAll:startingAt:
Store the next anInteger elements from the given collection.
nextChunkPut:
Append the argument, aString, to the receiver, doubling embedded terminators.
nextChunkPutWithStyle:
Append the argument, aText, to the receiver, doubling embedded terminators. Put out one chunk for the string and one for the style runs. Mark the style with ]style[.
nextPut:
Primitive. Insert the argument at the next position in the Stream
represented by the receiver. Fail if the collection of this stream is not an
Array or a String. Fail if the stream is positioned at its end, or if the
position is out of bounds in the collection. Fail if the argument is not
of the right type for the collection. Optional. See Object documentation
whatIsAPrimitive.
nextPutAll:
Append the elements of aCollection to the sequence of objects accessible
by the receiver. Answer aCollection.
nextPutKeyword:withArg:
Emit a keyword/value pair in the alternate syntax
on:
on:from:to:
pastEndPut:
Grow the collection by doubling the size, but keeping the growth between 20 and 1000000.
Then put <anObject> at the current write position.
peekLast
Return that item just put at the end of the stream
position:
Refer to the comment in PositionableStream|position:.
reset
Refer to the comment in PositionableStream|reset.
resetToStart
setToEnd
Refer to the comment in PositionableStream|setToEnd.
size
Primitive. Answer the number of indexable variables in the receiver.
This value is the same as the largest legal subscript. Essential. See Object
documentation whatIsAPrimitive.
space
Append a space character to the receiver.
space:
Append anInteger space characters to the receiver.
store:
Have anObject print on the receiver for purposes of rereading.
tab
Append a tab character to the receiver.
tab:
Append anInteger tab characters to the receiver.
timeStamp
Append the current time to the receiver as a String.
with:
with:from:to:
withAttribute:do:
No-op here is overriden in TextStream for font emphasis
withAttributes:do:
No-op here is overriden in TextStream for font emphasis