" Smalltalk/PositionableStream.st -*- Smalltalk -*- " PositionableStream : Stream ( collection position readLimit ) PositionableStream on: aCollection [ self := self _clone. collection := aCollection. readLimit := aCollection size. position := 0. "otherwise WriteStream>>reset will barf sending #max:" self reset ] PositionableStream reset [ position := 0. ] PositionableStream atEnd [ " Answer whether the receiver can access any more objects. " ^position >= readLimit ] PositionableStream position: anInteger [ " 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." (anInteger between: 0 and: readLimit) ifTrue: [position := anInteger] ifFalse: [self positionError] ] PositionableStream skip: anInteger [ " 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 +n anInteger, or the maximum of 0 and position + anInteger, for the repositioning. " self position: position + anInteger ] PositionableStream size [ ^readLimit ] PositionableStream contents [ " Answer with a copy of my collection from 0 to readLimit. " ^collection copyFrom: 0 to: readLimit ] PositionableStream peek [ | nextObject | self atEnd ifTrue: [^nil]. nextObject := self next. position := position - 1. ^nextObject ]