PositionableStream.st
author Claus Gittinger <cg@exept.de>
Sat, 01 Mar 2014 23:09:26 +0100
changeset 16186 dae8e43ccc46
parent 15640 d5a8c24894e2
child 16188 4df8b9b15db4
permissions -rw-r--r--
class: PositionableStream comment/format in: #upToAll: changed: #skipThroughAll: to avoid the need for redefinition in non-positionable subclasses.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5393
7e2230bd4bad moved some stuff to superclass
Claus Gittinger <cg@exept.de>
parents: 5308
diff changeset
    12
"{ Package: 'stx:libbasic' }"
7e2230bd4bad moved some stuff to superclass
Claus Gittinger <cg@exept.de>
parents: 5308
diff changeset
    13
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    14
PeekableStream subclass:#PositionableStream
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
    15
	instanceVariableNames:'collection position readLimit writeLimit'
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8363
diff changeset
    16
	classVariableNames:'ZeroPosition InvalidPositionErrorSignal'
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
    17
	poolDictionaries:''
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
    18
	category:'Streams'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    21
!PositionableStream class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    22
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
    26
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    27
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
!
10
claus
parents: 5
diff changeset
    36
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
    Instances of PositionableStream allow positioning the read pointer.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
    The PositionableStream class also adds methods for source-chunk reading
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
    and writing, and for filing-in/out of source code.
3249
8401c3e42165 checkin to force re-checkout.
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
    42
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    43
    This is an abstract class.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
    44
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    45
    Compatibility Notice:
9434
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
    46
        In previous versions of ST/X, streams started with a 1-position (i.e. as in collections),
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
    47
        while ST-80 has always been using 0-based postions for streams and 1-based positions for collections.
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    48
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    49
    THIS CERTAINLY IS BAD.
9434
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
    50
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
    51
    Although this is confusing ST/X has been changed to now also use 0-based stream positioning.
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
    52
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
    53
    [author:]
9434
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
    54
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    55
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    56
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    57
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    58
!PositionableStream class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    59
10
claus
parents: 5
diff changeset
    60
initialize
15353
0a60d904c4c0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15348
diff changeset
    61
    ZeroPosition := 0.        "/ changed with stx rel5.1; 
0a60d904c4c0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15348
diff changeset
    62
                              "/ rel6.2: no longer used (i.e. 0 has now ben hardcoded)
0a60d904c4c0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15348
diff changeset
    63
                              "/ class variable to be eliminated.
7363
721c2a72449a stream position now 0-based
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
    64
8443
7bc4348c059e fileIn stuff moved to peekableStream
Claus Gittinger <cg@exept.de>
parents: 8363
diff changeset
    65
    InvalidPositionErrorSignal isNil ifTrue:[
7092
630807cd320f Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7054
diff changeset
    66
        InvalidPositionErrorSignal := PositionOutOfBoundsError.
630807cd320f Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7054
diff changeset
    67
        InvalidPositionErrorSignal notifierString:'position out of bounds: '.
10
claus
parents: 5
diff changeset
    68
    ]
claus
parents: 5
diff changeset
    69
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    71
!PositionableStream class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
on:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
    "return a new PositionableStream streaming on aCollection"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    75
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
    ^ (self basicNew) on:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
on:aCollection from:first to:last
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
    "return a new PositionableStream streaming on aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
     from first to last"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
369
claus
parents: 362
diff changeset
    83
    ^ (self basicNew) on:aCollection from:first to:last
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    84
!
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    85
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    86
with:aCollection
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    87
    "return a new PositionableStream streaming on aCollection,
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    88
     the stream is positioned to the end of the collection."
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    89
362
claus
parents: 360
diff changeset
    90
    ^ (self basicNew) with:aCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    91
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    92
3032
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    93
!PositionableStream class methodsFor:'Signal constants'!
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    94
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    95
invalidPositionErrorSignal
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    96
    "return the signal raised if positioning is attempted to an
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    97
     invalid position (i.e. before the begin of the stream or after
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    98
     the end)"
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    99
8320
229adaeaf183 Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents: 8318
diff changeset
   100
    ^ PositionOutOfBoundsError
3032
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   101
! !
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   102
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
   103
!PositionableStream class methodsFor:'constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   104
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   105
zeroPosition
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   106
    "return the number, which marks the initial position.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   107
     Compatibility Notice:
9434
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
   108
        In previous versions of ST/X, streams started with a 1-position (i.e. as in collections),
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
   109
        while ST-80 has always been using 0-based postions for streams and 1-based positions for collections.
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   110
9434
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
   111
     Although this is confusing ST/X has been changed to now also use 0-based stream positioning.
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
   112
    "
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   113
15353
0a60d904c4c0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15348
diff changeset
   114
    ^ 0
9434
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
   115
8700cca5c249 comment
Claus Gittinger <cg@exept.de>
parents: 9284
diff changeset
   116
    "Modified: / 13-07-2006 / 20:36:54 / cg"
360
claus
parents: 329
diff changeset
   117
! !
claus
parents: 329
diff changeset
   118
16186
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   119
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7226
diff changeset
   120
!PositionableStream methodsFor:'Compatibility-Dolphin'!
6413
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   121
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   122
endChunk
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   123
    self nextPutChunkSeparator
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   124
! !
dc8d492a39ff dolphin compatibility
Claus Gittinger <cg@exept.de>
parents: 6361
diff changeset
   125
9284
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   126
!PositionableStream methodsFor:'Compatibility-ST/V'!
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   127
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   128
skipTo:anElement
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   129
    "ST/V compatibility:
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   130
     skip for the element given by the argument, anElement;
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   131
     return nil if not found, self otherwise. 
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   132
     On a successful match, the next read will return the element after anElement."
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   133
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   134
    ^ self skipThrough:anElement
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   135
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   136
    "
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   137
     |s|
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   138
     s := ReadStream on:'12345678901234567890'.
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   139
     s skipTo:$5.
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   140
     s copyFrom:1 to:(s position).    
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   141
     s upToEnd      
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   142
    "
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   143
! !
6afd161ee43c +skipTo:
Claus Gittinger <cg@exept.de>
parents: 9283
diff changeset
   144
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   145
!PositionableStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   146
7686
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7619
diff changeset
   147
collection
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7619
diff changeset
   148
    ^ collection
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7619
diff changeset
   149
!
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7619
diff changeset
   150
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   151
contents
a27a279701f8 Initial revision
claus
parents:
diff changeset
   152
    "return the entire contents of the stream"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
a27a279701f8 Initial revision
claus
parents:
diff changeset
   154
    ^ collection
a27a279701f8 Initial revision
claus
parents:
diff changeset
   155
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   156
a27a279701f8 Initial revision
claus
parents:
diff changeset
   157
peek
a27a279701f8 Initial revision
claus
parents:
diff changeset
   158
    "look ahead for and return the next element"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   159
a27a279701f8 Initial revision
claus
parents:
diff changeset
   160
    |peekObject|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   161
a27a279701f8 Initial revision
claus
parents:
diff changeset
   162
    peekObject := self next.
10
claus
parents: 5
diff changeset
   163
    self backStep.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   164
    ^ peekObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   165
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
2432
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   167
peekForAll:aCollection
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   168
    "return true and advance if the next elements are the same
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   169
     as aCollection. 
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   170
     otherwise stay and let the position unchanged"
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   171
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   172
    |oldPos|
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   173
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   174
    oldPos := self position.
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   175
    (self next:(aCollection size)) = aCollection ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   176
	^ true
2432
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   177
    ].
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   178
    self position:oldPos.
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   179
    ^ false
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   180
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   181
    "Created: 1.3.1997 / 15:11:25 / cg"
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   182
!
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   183
3905
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   184
readLimit
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   185
    "return the read-limit; thats the position at which EOF is returned"
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   186
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   187
    ^ readLimit
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   188
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   189
    "Created: / 30.10.1998 / 16:47:04 / cg"
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   190
!
682fc38fd339 added read-access to readLimit.
Claus Gittinger <cg@exept.de>
parents: 3604
diff changeset
   191
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   192
readLimit:aNumber
369
claus
parents: 362
diff changeset
   193
    "set the read-limit; thats the position at which EOF is returned"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   194
a27a279701f8 Initial revision
claus
parents:
diff changeset
   195
    readLimit := aNumber
369
claus
parents: 362
diff changeset
   196
!
claus
parents: 362
diff changeset
   197
14934
5e273cddded7 setCollection: moved
Claus Gittinger <cg@exept.de>
parents: 13379
diff changeset
   198
setCollection:newCollection
5e273cddded7 setCollection: moved
Claus Gittinger <cg@exept.de>
parents: 13379
diff changeset
   199
    collection := newCollection
5e273cddded7 setCollection: moved
Claus Gittinger <cg@exept.de>
parents: 13379
diff changeset
   200
!
5e273cddded7 setCollection: moved
Claus Gittinger <cg@exept.de>
parents: 13379
diff changeset
   201
369
claus
parents: 362
diff changeset
   202
writeLimit:aNumber
claus
parents: 362
diff changeset
   203
    "set the writeLimit; thats the position after which writing is prohibited"
claus
parents: 362
diff changeset
   204
claus
parents: 362
diff changeset
   205
    writeLimit := aNumber
10592
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   206
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   207
    "
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   208
     |s|
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   209
     s := WriteStream on:String new.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   210
     s nextPutAll:'hello world'.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   211
     s contents.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   212
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   213
     |s|
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   214
     s := WriteStream on:String new.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   215
     s writeLimit:5.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   216
     s nextPutAll:'hello world'.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   217
     s contents.
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   218
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   219
    "
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   220
3957c03de6a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10577
diff changeset
   221
    "Modified: / 04-06-2007 / 17:21:55 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   222
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   223
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   224
!PositionableStream methodsFor:'positioning'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   225
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   226
backStep
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   227
    "move backward read position by one"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   228
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   229
    self position:(self position - 1)
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   230
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   231
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   232
position
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   233
    "return the read position (0-based)"
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   234
15348
f5677dc62dc0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15159
diff changeset
   235
    ^ position
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   236
!
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   237
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   238
position0Based
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   239
    <resource: #obsolete>
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   240
    "return the read position 0-based"
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   241
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   242
    ^ self position
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   243
!
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   244
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   245
position0Based:index0Based
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   246
    <resource: #obsolete>
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   247
    "set the read (or write) position"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   248
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   249
    self position:index0Based
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   250
!
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   251
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   252
position1Based
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   253
    <resource: #obsolete>
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   254
    "return the read position 1-based"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   255
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   256
    ^ self position + 1
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   257
!
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   258
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   259
position1Based:index1Based
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   260
    <resource: #obsolete>
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   261
    "set the read (or write) position"
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   262
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   263
    self position:(index1Based - 1)
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   264
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   265
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   266
     |s|
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   267
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   268
     s := '1234567890' readStream.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   269
     s next:5.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   270
     s position:1.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   271
     s next:7.       
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   272
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   273
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   274
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   275
     |s|
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   276
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   277
     s := '' writeStream.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   278
     s nextPutAll:'1234567890'.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   279
     s position:5.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   280
     s nextPutAll:'abcdefg'.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   281
     s contents 
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   282
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   283
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   284
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   285
     |s|
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   286
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   287
     s := '' writeStream.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   288
     s nextPutAll:'1234567890'.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   289
     s position:0.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   290
     s nextPutAll:'abcdefg'.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   291
     s contents 
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   292
    "
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   293
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   294
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   295
position:index0Based
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   296
    "set the read (or write) position"
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   297
15615
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   298
    ((index0Based > readLimit) or:[index0Based < 0]) ifTrue: [^ self positionError:index0Based].
f67e9f5cd22a class: PositionableStream
Stefan Vogel <sv@exept.de>
parents: 15357
diff changeset
   299
    position := index0Based
6626
f7b08d6bee3f #positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents: 6538
diff changeset
   300
!
f7b08d6bee3f #positionStartingAt0 and #positionStartingAt1
Stefan Vogel <sv@exept.de>
parents: 6538
diff changeset
   301
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   302
reset
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
    "set the read position to the beginning of the collection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
5308
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   305
    self resetPosition
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   306
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   307
    "
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   308
     |s|
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   309
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   310
     s := 'hello world' readStream.
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   311
     Transcript showCR:(s next:5).
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   312
     s reset.
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   313
     Transcript showCR:(s next:10).
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   314
    "
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   315
!
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   316
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   317
resetPosition
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   318
    "set the read position to the beginning of the collection"
8e8b5d2b3b8e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5302
diff changeset
   319
15348
f5677dc62dc0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15159
diff changeset
   320
    position := 0
4405
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   321
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   322
    "
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   323
     |s|
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   324
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   325
     s := 'hello world' readStream.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   326
     Transcript showCR:(s next:5).
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   327
     s reset.
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   328
     Transcript showCR:(s next:10).
247058206089 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 4325
diff changeset
   329
    "
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   330
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   331
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   332
setToEnd
11433
bf4acfe61ece changed #setToEnd
Stefan Vogel <sv@exept.de>
parents: 10592
diff changeset
   333
    "set the read position to the end of the collection.
bf4acfe61ece changed #setToEnd
Stefan Vogel <sv@exept.de>
parents: 10592
diff changeset
   334
     #next will return EOF, #nextPut: will append to the stream.
bf4acfe61ece changed #setToEnd
Stefan Vogel <sv@exept.de>
parents: 10592
diff changeset
   335
     (same Behavior as FileStream."
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   336
15348
f5677dc62dc0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15159
diff changeset
   337
    position := readLimit
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   338
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   339
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   340
skip:numberToSkip
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   341
    "skip the next numberToSkip elements"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   342
5774
dafe65be735b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5748
diff changeset
   343
    numberToSkip ~~ 0 ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6924
diff changeset
   344
	self position:(self position + numberToSkip)
5774
dafe65be735b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5748
diff changeset
   345
    ]
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   346
!
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   347
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   348
skipThroughAll:aCollection
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   349
    "skip for and through the sequence given by the argument, aCollection;
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   350
     return nil if not found, self otherwise. 
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   351
     On a successful match, the next read will return elements after aCollection;
2153
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   352
     if no match was found, the receiver will be positioned at the end.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   353
     This is redefined here, to make use of positioning."
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   354
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   355
    |buffer len first idx|
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   356
16186
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   357
    self isPositionable ifFalse:[
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   358
        "/ for non-positionable subclasses
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   359
        ^ super skipThroughAll:aCollection
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   360
    ].
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   361
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   362
    len := aCollection size.
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   363
    first := aCollection at:1.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   364
    [self atEnd] whileFalse:[
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   365
        buffer := self nextAvailable:len.
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   366
        buffer = aCollection ifTrue:[
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   367
            ^ self
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   368
        ].
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   369
        buffer size == len ifTrue:[
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   370
            "expect more input"
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   371
            idx := buffer indexOf:first startingAt:2.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   372
            idx == 0 ifFalse:[
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   373
                self position:(self position - len + idx - 1)
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   374
            ].
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   375
        ].
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   376
    ].
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   377
    ^ nil
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   378
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   379
    "
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   380
     |s|
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   381
     s := ReadStream on:'12345678901234567890a'.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   382
     s skipThroughAll:'90ab'.
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   383
     s upToEnd  
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   384
    "
2153
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   385
    "
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   386
     |s|
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   387
     s := ReadStream on:'12345678901234567890'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   388
     s skipThroughAll:'1234'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   389
     s upToEnd  
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   390
    "
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   391
    "
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   392
     |s|
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   393
     s := ReadStream on:'12345678901234567890'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   394
     s skipThroughAll:'999'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   395
     s atEnd  
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   396
    "
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   397
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   398
    "Created: 26.6.1996 / 09:35:35 / cg"
2154
89e96599e1e2 skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2153
diff changeset
   399
    "Modified: 11.1.1997 / 19:16:38 / cg"
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   400
!
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   401
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   402
skipToAll:aCollection
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   403
    "skip for the sequence given by the argument, aCollection;
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   404
     return nil if not found, self otherwise. 
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   405
     On a successful match, the next read will return elements of aCollection."
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   406
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   407
    |oldPos buffer len first idx|
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   408
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   409
    oldPos := self position.
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   410
    len := aCollection size.
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   411
    first := aCollection at:1.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   412
    [self atEnd] whileFalse:[
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   413
        buffer := self nextAvailable:len.
7054
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   414
        buffer = aCollection ifTrue:[
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   415
            self position:(self position - len).
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   416
            ^ self
685d359f9847 code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   417
        ].
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   418
        buffer size == len ifTrue:[
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   419
            "more input can be expected"
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   420
            idx := buffer indexOf:first startingAt:2.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   421
            idx == 0 ifFalse:[
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   422
                self position:(self position - len + idx - 1)
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   423
            ].
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   424
        ].
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   425
    ].
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   426
    self position:oldPos.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   427
    ^ nil
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   428
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   429
    "
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   430
     |s|
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   431
     s := ReadStream on:'12345678901234567890'.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   432
     s skipToAll:'901'.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   433
     s upToEnd  
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   434
    "
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   435
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   436
    "
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   437
     |s|
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   438
     s := ReadStream on:'1234567890'.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   439
     s skipToAll:'901'.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   440
     s upToEnd  
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   441
    "
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   442
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   443
    "
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   444
     |s|
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   445
     s := 'Makefile' asFilename readStream.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   446
     [
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   447
         (s skipToAll:'EDIT') notNil ifTrue:[
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   448
            s next:100.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   449
         ].
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   450
     ] ensure:[
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   451
        s close.
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   452
     ]
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   453
    "
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   454
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   455
    "Modified: 26.6.1996 / 09:28:27 / cg"
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   456
    "Created: 26.6.1996 / 09:35:06 / cg"
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   457
! !
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   458
10357
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   459
!PositionableStream methodsFor:'printing & storing'!
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   460
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   461
printOn:aStream
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   462
    aStream nextPutAll:self className; nextPutAll:'(on:'; nextPutAll:collection classNameWithArticle; nextPut:$)
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   463
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   464
    "
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   465
      '' readStream printString
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   466
      '' writeStream printString
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   467
    "
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   468
! !
66543e405aa4 Fix #skipToAll: (partial match at end of stream
Stefan Vogel <sv@exept.de>
parents: 10001
diff changeset
   469
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   470
!PositionableStream methodsFor:'private'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   471
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   472
contentsSpecies
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   473
    "return a class of which instances will be returned, when
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   474
     parts of the collection are asked for. 
15640
d5a8c24894e2 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15615
diff changeset
   475
     (see upTo-kind of methods in Stream)"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   476
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   477
    ^ collection species
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   478
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   479
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   480
on:aCollection
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   481
    "setup for streaming on aCollection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   482
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   483
    collection := aCollection.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   484
    readLimit := aCollection size.
13379
a4644dee3177 changed: #on:
sr
parents: 11434
diff changeset
   485
    readLimit == 0 ifTrue:[
a4644dee3177 changed: #on:
sr
parents: 11434
diff changeset
   486
        self assert:(aCollection isCollection)
a4644dee3177 changed: #on:
sr
parents: 11434
diff changeset
   487
    ].
15348
f5677dc62dc0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15159
diff changeset
   488
    position := 0
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   489
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   490
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   491
on:aCollection from:first to:last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   492
    "setup for streaming on aCollection from first to last"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   493
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   494
    collection := aCollection.
15348
f5677dc62dc0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15159
diff changeset
   495
    position := first - 1.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   496
    readLimit := last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   497
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   498
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   499
positionError
1998
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   500
    "{ Pragma: +optSpace }"
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   501
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
   502
    "report an error when positioning past the end
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
   503
     or before the beginning."
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   504
8320
229adaeaf183 Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents: 8318
diff changeset
   505
    ^ PositionOutOfBoundsError raiseRequestWith:nil
4452
3d050f505a0a Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents: 4416
diff changeset
   506
3d050f505a0a Raise proceedable signals proceedable.
Stefan Vogel <sv@exept.de>
parents: 4416
diff changeset
   507
    "Modified: / 26.7.1999 / 10:59:13 / stefan"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   508
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   509
6314
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   510
positionError:badPostition
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   511
    "{ Pragma: +optSpace }"
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   512
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   513
    "report an error when positioning past the end
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   514
     or before the beginning."
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   515
8320
229adaeaf183 Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents: 8318
diff changeset
   516
    ^ PositionOutOfBoundsError raiseRequestWith:badPostition
6314
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   517
!
e1aad938d629 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6230
diff changeset
   518
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   519
with:aCollection
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   520
    "setup for streaming to the end of aCollection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   521
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   522
    collection := aCollection.
11434
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   523
    readLimit := aCollection size.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   524
    self setToEnd
11434
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   525
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   526
    "
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   527
      (WriteStream with:#(1 2 3 4 5)) 
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   528
            nextPut:6;
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   529
            contents
525e70af011a changed #with:
Stefan Vogel <sv@exept.de>
parents: 11433
diff changeset
   530
    "
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   531
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   532
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   533
!PositionableStream methodsFor:'reading'!
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   534
9003
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   535
nextAvailable:count
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   536
    |end result|
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   537
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   538
    end := position + count.
15357
10a1cd767648 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15353
diff changeset
   539
    end >= readLimit ifTrue:[
9003
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   540
        end := readLimit.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   541
    ].
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   542
15348
f5677dc62dc0 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15159
diff changeset
   543
    result := collection copyFrom:position+1 to:end.
9003
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   544
    position := end.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   545
    ^ result.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   546
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   547
    "
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   548
        'abc' readStream nextAvailable:1.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   549
        'abc' readStream nextAvailable:2.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   550
        'abc' readStream nextAvailable:3.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   551
        'abc' readStream nextAvailable:4.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   552
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   553
        'abc' readStream nextAvailable:2; nextAvailable:2.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   554
        'abc' readStream nextAvailable:3; nextAvailable:3.
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   555
    "
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   556
!
baa2a9409c9d speed up #nextAvailable
Stefan Vogel <sv@exept.de>
parents: 8443
diff changeset
   557
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   558
upToAll:aCollection
16186
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   559
    "read until a subcollection consisisting of the elements in aCollection is encountered.
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   560
     Return everything read excluding the elements in aCollection.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   561
     The position is left before the collection; i.e. the next
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   562
     read operations will return those elements.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   563
     If no such subcollection is encountered, all elements up to the end 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   564
     are read and returned.
6494
5b3d8667c22a comment
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   565
     See also #throughAll: which also reads up to some objects
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   566
     but positions behind it and DOES include it in the returned
3184
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   567
     collection.
6494
5b3d8667c22a comment
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   568
     See also #upToAllExcluding:, which returns the same, but leaves the
5b3d8667c22a comment
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   569
     read pointer after the matched subcollection.
3184
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   570
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   571
     Note: this behavior is inconsistent with the other upTo.. methods,
15159
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   572
           which position after the found item. We implement the method
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   573
           this way for the sake of ST80-compatibility."
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   574
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   575
    |answerStream element last rslt|
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   576
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   577
    last := aCollection last.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   578
    answerStream := WriteStream on:(self contentsSpecies new).
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   579
    [self atEnd] whileFalse:[
15159
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   580
        element := self next.
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   581
        answerStream nextPut:element.
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   582
        element == last ifTrue:[
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   583
            ((rslt := answerStream contents) endsWith:aCollection) ifTrue:[
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   584
                self position:(self position - aCollection size).
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   585
                ^ rslt copyButLast:aCollection size
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   586
            ]
b94bdee97afa Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 14934
diff changeset
   587
        ].
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   588
    ].
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   589
    ^ answerStream contents
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   590
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   591
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   592
     |s|
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   593
     s := ReadStream on:'hello world'.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   594
     Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. 
6494
5b3d8667c22a comment
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   595
     Transcript showCR:s atEnd.
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   596
     Transcript show:'<'; show:(s upToEnd); showCR:'>'. 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   597
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   598
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   599
     |s|
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   600
     s := ReadStream on:'hello world'.
16186
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   601
     Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. 
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   602
     Transcript showCR:s atEnd.
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   603
     Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. 
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   604
    "
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   605
    "
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   606
     |s|
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   607
     s := ReadStream on:'hello world'.
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   608
     Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   609
     Transcript showCR:s atEnd.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   610
     Transcript show:'<'; show:(s upToEnd); showCR:'>'. 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   611
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   612
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   613
    "Modified: / 12.1.1998 / 22:06:42 / cg"
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   614
    "Created: / 12.1.1998 / 22:07:01 / cg"
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   615
! !
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   616
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   617
!PositionableStream methodsFor:'testing'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   618
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   619
atEnd
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   620
    "return true, if the read-position is at the end"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   621
15357
10a1cd767648 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15353
diff changeset
   622
    ^ position >= readLimit
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   623
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   624
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   625
isEmpty
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   626
    "return true, if the contents of the stream is empty"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   627
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   628
    ^ readLimit == 0
9006
e5509951529d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 9003
diff changeset
   629
!
e5509951529d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 9003
diff changeset
   630
10577
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   631
isInternalByteStream
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   632
    "return true, if the stream is an internal stream reading bytes"
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   633
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   634
    ^ collection class isBytes
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   635
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   636
    "Created: / 30-05-2007 / 16:16:12 / cg"
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   637
!
3a97ef89ffb1 +isInternalByteStream
Claus Gittinger <cg@exept.de>
parents: 10357
diff changeset
   638
9006
e5509951529d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 9003
diff changeset
   639
isPositionable
e5509951529d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 9003
diff changeset
   640
    "return true, if the stream supports positioning (this one is)"
e5509951529d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 9003
diff changeset
   641
e5509951529d *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 9003
diff changeset
   642
    ^ true
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   643
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   644
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
   645
!PositionableStream class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   646
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   647
version
16186
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   648
    ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.162 2014-03-01 22:09:26 cg Exp $'
13379
a4644dee3177 changed: #on:
sr
parents: 11434
diff changeset
   649
!
a4644dee3177 changed: #on:
sr
parents: 11434
diff changeset
   650
a4644dee3177 changed: #on:
sr
parents: 11434
diff changeset
   651
version_CVS
16186
dae8e43ccc46 class: PositionableStream
Claus Gittinger <cg@exept.de>
parents: 15640
diff changeset
   652
    ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.162 2014-03-01 22:09:26 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   653
! !
6777
5efddf5358b2 currentFileInDirectory query
Claus Gittinger <cg@exept.de>
parents: 6707
diff changeset
   654
14934
5e273cddded7 setCollection: moved
Claus Gittinger <cg@exept.de>
parents: 13379
diff changeset
   655
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   656
PositionableStream initialize!