removed endOfStreamQuery - instead, handle unhandled exception
in pastEnd.
--- a/Stream.st Tue Jun 16 13:10:08 1998 +0200
+++ b/Stream.st Tue Jun 16 15:54:37 1998 +0200
@@ -13,7 +13,7 @@
Object subclass:#Stream
instanceVariableNames:'signalAtEnd'
classVariableNames:'StreamErrorSignal PositionErrorSignal ReadErrorSignal
- WriteErrorSignal EndOfStreamSignal EndOfStreamQuerySignal'
+ WriteErrorSignal EndOfStreamSignal'
poolDictionaries:''
category:'Streams'
!
@@ -45,37 +45,45 @@
Subclasses should (at least) implement:
- #next (if readable)
- #nextPut: (if writable)
- #contents
- #atEnd
- #isReadable
- #isWritable
+ #next (if readable)
+ #nextPut: (if writable)
+ #contents
+ #atEnd
+ #isReadable
+ #isWritable
Peekable & Positionable streams should (at least) implement:
- #peek
- #position
- #position:
+ #peek
+ #position
+ #position:
+ [instance variables:]
+ signalAtEnd <nil | Boolean> controls behavior when a read
+ is attempted past the end-of-stream
+ if true, the endOfStreamSignal is
+ raised.
+ if false, nil is returned.
+ if nil (the default), the signal
+ is raised, but if there is no handler,
+ nil is returned.
+
[Class variables:]
- StreamErrorSignal <Signal> parent of all stream errors
-
- PositionErrorSignal <Signal> position attemted on a stream
- which does not support positioning
-
- ReadErrorSignal <Signal> raised on read errors
+ StreamErrorSignal <Signal> parent of all stream errors
- WriteErrorSignal <Signal> raised on write errors
+ PositionErrorSignal <Signal> position attemted on a stream
+ which does not support positioning,
+ or if the position is invalid.
- EndOfStreamSignal <Signal> raised at end of stream if signalAtEnd
- is enabled.
+ ReadErrorSignal <Signal> raised on read errors
- EndOfStreamQuerySignal <QuerySignal> raised at end of stream if signalAtEnd
- is defaulted (nil).
+ WriteErrorSignal <Signal> raised on write errors
+
+ EndOfStreamSignal <Signal> raised at end of stream if signalAtEnd
+ is enabled.
[author:]
- Claus Gittinger
+ Claus Gittinger
"
! !
@@ -83,31 +91,28 @@
initialize
StreamErrorSignal isNil ifTrue:[
- StreamErrorSignal := ErrorSignal newSignalMayProceed:false.
- StreamErrorSignal nameClass:self message:#streamErrorSignal.
- StreamErrorSignal notifierString:'Stream error'.
+ StreamErrorSignal := ErrorSignal newSignalMayProceed:false.
+ StreamErrorSignal nameClass:self message:#streamErrorSignal.
+ StreamErrorSignal notifierString:'Stream error'.
- PositionErrorSignal := StreamErrorSignal newSignalMayProceed:true.
- PositionErrorSignal nameClass:self message:#positionErrorSignal.
- PositionErrorSignal notifierString:'stream as no concept of a position'.
-
- ReadErrorSignal := StreamErrorSignal newSignalMayProceed:false.
- ReadErrorSignal nameClass:self message:#readErrorSignal.
- ReadErrorSignal notifierString:'read error'.
+ PositionErrorSignal := StreamErrorSignal newSignalMayProceed:true.
+ PositionErrorSignal nameClass:self message:#positionErrorSignal.
+ PositionErrorSignal notifierString:'stream as no concept of a position'.
- WriteErrorSignal := StreamErrorSignal newSignalMayProceed:false.
- WriteErrorSignal nameClass:self message:#writeErrorSignal.
- WriteErrorSignal notifierString:'write error'.
+ ReadErrorSignal := StreamErrorSignal newSignalMayProceed:false.
+ ReadErrorSignal nameClass:self message:#readErrorSignal.
+ ReadErrorSignal notifierString:'read error'.
- EndOfStreamSignal := StreamErrorSignal newSignalMayProceed:true.
- EndOfStreamSignal nameClass:self message:#endOfStreamSignal.
- EndOfStreamSignal notifierString:'end of stream'.
+ WriteErrorSignal := StreamErrorSignal newSignalMayProceed:false.
+ WriteErrorSignal nameClass:self message:#writeErrorSignal.
+ WriteErrorSignal notifierString:'write error'.
- EndOfStreamQuerySignal := QuerySignal new defaultAnswer:nil.
- EndOfStreamQuerySignal parent:EndOfStreamSignal.
- EndOfStreamQuerySignal nameClass:self message:#endOfStreamQuerySignal.
- EndOfStreamQuerySignal notifierString:'end of stream'.
+ EndOfStreamSignal := StreamErrorSignal newSignalMayProceed:true.
+ EndOfStreamSignal nameClass:self message:#endOfStreamSignal.
+ EndOfStreamSignal notifierString:'end of stream'.
]
+
+ "Modified: / 16.6.1998 / 15:49:27 / cg"
! !
!Stream class methodsFor:'instance creation'!
@@ -122,12 +127,6 @@
!Stream class methodsFor:'Signal constants'!
-endOfStreamQuerySignal
- "return the query signal raised if read past end of stream is attemted"
-
- ^ EndOfStreamQuerySignal
-!
-
endOfStreamSignal
"return the signal raised if read past end of stream is attemted"
@@ -190,12 +189,13 @@
"set the signalAtEnd flag setting. If true, reading past the end
will raise an EndOfStream exception. If false, no exception is
raised and nil is returned from all reading messages.
- The default is (currently) to NOT raise a signal."
+ The default is to raise a signal, but return nil if
+ not handled."
signalAtEnd := aBoolean.
- "Created: 5.2.1996 / 18:24:53 / stefan"
- "Modified: 15.5.1996 / 17:36:12 / cg"
+ "Created: / 5.2.1996 / 18:24:53 / stefan"
+ "Modified: / 16.6.1998 / 15:51:57 / cg"
! !
!Stream methodsFor:'closing'!
@@ -314,17 +314,22 @@
Otherwise raise the signal, but only if handled; otherwise return nil."
signalAtEnd == true ifTrue:[
- "/ always raise ...
- ^ EndOfStreamSignal raiseRequestFrom:self
+ "/ always raise ...
+ ^ EndOfStreamSignal raiseRequestFrom:self
].
signalAtEnd == false ifTrue:[
- "/ never raise ...
- ^ nil
+ "/ never raise ...
+ ^ nil
].
- ^ EndOfStreamQuerySignal raiseRequestFrom:self
+ "/ the default case - raise it, but return nil, if noone cares.
+ Signal noHandlerSignal handle:[:ex |
+ ^ nil
+ ] do:[
+ ^ EndOfStreamSignal raiseRequestFrom:self
+ ]
- "Modified: / 11.11.1997 / 16:14:41 / cg"
+ "Modified: / 16.6.1998 / 15:48:36 / cg"
! !
!Stream methodsFor:'misc'!
@@ -1119,7 +1124,7 @@
"return the next count elements of the stream as aCollection.
If the stream reaches the end before count elements have been read,
return what is available. (i.e. a shorter collection).
- The type of collection is speciefied in #contentsSpecies."
+ The type of collection is specified in #contentsSpecies."
|answerStream
cnt "{ Class: SmallInteger }"|
@@ -1127,21 +1132,21 @@
answerStream := WriteStream on:(self contentsSpecies new).
cnt := count.
1 to:cnt do:[:index |
- self atEnd ifTrue:[
- ^ answerStream contents
- ].
- answerStream nextPut:(self next)
+ self atEnd ifTrue:[
+ ^ answerStream contents
+ ].
+ answerStream nextPut:(self next)
].
^ answerStream contents
"
- (ReadStream on:#(1 2 3 4 5)) nextAvailable:3
+ (ReadStream on:#(1 2 3 4 5)) nextAvailable:3
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10
(ReadStream on:'hello') nextAvailable:3
(ReadStream on:'hello') nextAvailable:10
"
- "Modified: 15.5.1996 / 17:58:42 / cg"
+ "Modified: / 16.6.1998 / 15:52:41 / cg"
!
nextMatchFor:anObject
@@ -1984,6 +1989,6 @@
!Stream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.77 1998-06-15 19:45:23 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.78 1998-06-16 13:54:37 cg Exp $'
! !
Stream initialize!