WriteStream.st
author convert-repo
Thu, 05 Jul 2018 03:33:35 +0000
changeset 23197 823c765c176d
parent 23011 0b537ee77cf1
child 24032 a89bc30b9339
permissions -rw-r--r--
update tags
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23011
0b537ee77cf1 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22645
diff changeset
     1
"{ Encoding: utf8 }"
0b537ee77cf1 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22645
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1989 by Claus Gittinger
252
claus
parents: 95
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
    14
"{ Package: 'stx:libbasic' }"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
    15
17305
323279fd2cdf class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17208
diff changeset
    16
"{ NameSpace: Smalltalk }"
323279fd2cdf class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17208
diff changeset
    17
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
PositionableStream subclass:#WriteStream
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    19
	instanceVariableNames:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    20
	classVariableNames:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    21
	poolDictionaries:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    22
	category:'Streams'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
1965
4ca38574df3b Fix typo.
Stefan Vogel <sv@exept.de>
parents: 1584
diff changeset
    25
!WriteStream class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 COPYRIGHT (c) 1989 by Claus Gittinger
252
claus
parents: 95
diff changeset
    30
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
68
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
    41
documentation
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
    42
"
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    43
    Streams for writing into.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    44
    WriteStreams are especially useful, if big strings are to be constructed
16201
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
    45
    from pieces - create a writeStream, add the pieces (with #nextPut: or
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
    46
    #nextPutAll:) and finally fetch the concatenated string via #contents.
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    47
    This is much better than constructing the big string by concatenating via
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    48
    the comma (,) operator, since less intermediate garbage objects are created.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    49
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
    50
    This implementation currently DOES change the
20271
2ee56cbd6cfc #DOCUMENTATION by mawalch
mawalch
parents: 19887
diff changeset
    51
    identity of the streamed-upon collection IF it cannot grow easily.
261
afdf1e7184ad *** empty log message ***
claus
parents: 260
diff changeset
    52
    Collections which cannot grow easily are for example: Array, ByteArray and String.
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
    53
    Thus it is slightly incompatible to ST-80 since 'aStream contents' does
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    54
    not always return the original collection. This may change.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    55
17557
6726d49ecf7b class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17550
diff changeset
    56
    [caveat:]
20271
2ee56cbd6cfc #DOCUMENTATION by mawalch
mawalch
parents: 19887
diff changeset
    57
        Basing capabilities like readability/writability/positionability/peekability on inheritance makes
2ee56cbd6cfc #DOCUMENTATION by mawalch
mawalch
parents: 19887
diff changeset
    58
        the class hierarchy ugly and leads to strange and hard to teach redefinitions (aka. NonPositionableStream
2ee56cbd6cfc #DOCUMENTATION by mawalch
mawalch
parents: 19887
diff changeset
    59
        below PositionableStream or ExternalReadStream under WriteStream)
17557
6726d49ecf7b class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17550
diff changeset
    60
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    61
    [author:]
20271
2ee56cbd6cfc #DOCUMENTATION by mawalch
mawalch
parents: 19887
diff changeset
    62
        Claus Gittinger
10281
47dd93edcfa5 comment
Claus Gittinger <cg@exept.de>
parents: 10070
diff changeset
    63
47dd93edcfa5 comment
Claus Gittinger <cg@exept.de>
parents: 10070
diff changeset
    64
    [see also:]
20271
2ee56cbd6cfc #DOCUMENTATION by mawalch
mawalch
parents: 19887
diff changeset
    65
        CharacterWriteStream (if streaming for a unicode string)
68
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
    66
"
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    67
!
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    68
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    69
examples
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    70
"
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    71
								[exBegin]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    72
     |s|
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    73
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    74
     s := WriteStream on:''.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    75
     s nextPutAll:'hello';
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    76
       space;
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    77
       nextPutAll:'world'.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    78
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    79
     s contents inspect
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    80
								[exEnd]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    81
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    82
								[exBegin]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    83
     |s|
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    84
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    85
     s := WriteStream on:''.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    86
     s nextPutAll:'hello';
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    87
       space;
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    88
       nextPutAll:'world'.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    89
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    90
     Transcript nextPutLine:(s contents)
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    91
								[exEnd]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    92
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    93
								[exBegin]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    94
     |s|
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    95
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    96
     s := '' writeStream.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    97
     s nextPutAll:'hello';
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    98
       space;
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    99
       nextPutAll:'world'.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   100
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   101
     Transcript nextPutLine:(s contents)
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   102
								[exEnd]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   103
"
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   104
345
claus
parents: 329
diff changeset
   105
! !
claus
parents: 329
diff changeset
   106
22569
3f6ffe519140 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22553
diff changeset
   107
!WriteStream methodsFor:'Compatibility-Squeak'!
3f6ffe519140 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22553
diff changeset
   108
3f6ffe519140 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22553
diff changeset
   109
resetContents
3f6ffe519140 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22553
diff changeset
   110
    "Squeak compatibility"
3f6ffe519140 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22553
diff changeset
   111
3f6ffe519140 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22553
diff changeset
   112
    self reset
3f6ffe519140 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22553
diff changeset
   113
! !
3f6ffe519140 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22553
diff changeset
   114
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   115
!WriteStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   116
15179
3f99524b54cb class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 14935
diff changeset
   117
clear
3f99524b54cb class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 14935
diff changeset
   118
    "for compatibility with Transcript"
3f99524b54cb class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 14935
diff changeset
   119
3f99524b54cb class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 14935
diff changeset
   120
    self reset
3f99524b54cb class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 14935
diff changeset
   121
!
3f99524b54cb class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 14935
diff changeset
   122
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   123
contents
345
claus
parents: 329
diff changeset
   124
    "return the current contents (a collection) of the stream.
claus
parents: 329
diff changeset
   125
     Currently, this returns the actual collection if possible
claus
parents: 329
diff changeset
   126
     (and reset is implemented to create a new one) in contrast to
claus
parents: 329
diff changeset
   127
     ST80, where contents returns a copy and reset only sets the writePointer.
claus
parents: 329
diff changeset
   128
     The ST/X behavior creates less temporary garbage in the normal case
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   129
     (where things are written for the contents only) but may be incompatible
345
claus
parents: 329
diff changeset
   130
     with some applications. Time will show, if this is to be changed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   131
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   132
    |lastIndex|
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   133
15347
bf763ed0a879 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 15179
diff changeset
   134
    lastIndex := position.
22645
d69fae162db9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22569
diff changeset
   135
    collection size ~~ lastIndex ifTrue:[
d69fae162db9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22569
diff changeset
   136
        collection isFixedSize ifTrue:[
d69fae162db9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22569
diff changeset
   137
            "
d69fae162db9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22569
diff changeset
   138
             grow is expensive - return a copy.
d69fae162db9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22569
diff changeset
   139
             (is this what users of writeStream expect ?)
d69fae162db9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22569
diff changeset
   140
            "
d69fae162db9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22569
diff changeset
   141
            collection := collection copyFrom:1 to:lastIndex
d69fae162db9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22569
diff changeset
   142
        ] ifFalse:[
d69fae162db9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22569
diff changeset
   143
            collection grow:lastIndex
d69fae162db9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22569
diff changeset
   144
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   145
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   146
    ^ collection
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   147
22645
d69fae162db9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22569
diff changeset
   148
    "Modified: / 30-10-1997 / 16:21:23 / cg"
d69fae162db9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22569
diff changeset
   149
    "Modified: / 20-03-2018 / 16:34:29 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   150
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   151
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   152
last
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   153
    "return the last element - report an error if the stream is empty"
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   154
16201
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   155
    ^ collection at:position.
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   156
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   157
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   158
     |s|
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   159
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   160
     s := '' writeStream.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   161
     s nextPut:$a.
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   162
     s last.
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   163
     s nextPut:$b.
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   164
     s last.
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   165
     s nextPut:$c.
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   166
     s last.
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   167
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   168
!
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   169
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   170
last:n
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   171
    "return the last n elements as species of the underlying collection;
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   172
     Report an error if the stream is empty"
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   173
17181
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   174
    ^ collection copyFrom:(position - n + 1) to:position.
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   175
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   176
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   177
     |s|
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   178
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   179
     s := '' writeStream.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   180
     s nextPut:$a.
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   181
     s last:1.
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   182
     s nextPut:$b.
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   183
     s last:1.
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   184
     s last:2.
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   185
     s nextPut:$c.
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   186
     s last:1.
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   187
     s last:2.
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   188
     s last:3.
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   189
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   190
!
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   191
22553
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   192
readStream
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   193
    "return a readstream on the current contents;
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   194
     that is: if more is written to the stream in the meantime,
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   195
     the readStream will NOT show it.
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   196
     To avoid copying the contents, a readStream with a readLimit
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   197
     is created. In the hope, that noone repositions and rewrites the
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   198
     underlying writeStream.
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   199
     If that leads to problems, you should use contents readStream."
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   200
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   201
    ^ ReadStream on:collection from:1 to:self position.
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   202
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   203
    "
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   204
     |w r|
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   205
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   206
     w := WriteStream on:(String new).
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   207
     w nextPutAll:'12345'.
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   208
     r := w readStream.
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   209
     w nextPutAll:'abc'.
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   210
     w nextPutAll:(r upToEnd).
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   211
     w nextPutAll:'def'.
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   212
     w contents.
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   213
    "
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   214
!
fb78e910d191 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22152
diff changeset
   215
329
claus
parents: 293
diff changeset
   216
reset
345
claus
parents: 329
diff changeset
   217
    "reset the stream; write anew.
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   218
     See the comment in WriteStream>>contents"
329
claus
parents: 293
diff changeset
   219
claus
parents: 293
diff changeset
   220
    collection := collection species new:(collection size).
19887
95f3969f810d #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19828
diff changeset
   221
    position := 0.
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   222
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   223
    "Modified: 19.2.1997 / 08:57:00 / stefan"
22150
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   224
! !
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   225
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   226
!WriteStream methodsFor:'positioning'!
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   227
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   228
position:index0Based
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   229
    "redefined to allow positioning past the readLimit"
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   230
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   231
    ((index0Based > collection size) or:[index0Based < 0]) ifTrue: [^ self positionError].
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   232
    position := index0Based
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   233
!
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   234
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   235
skip:count
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   236
    "redefined to allow positioning back over already written characters"
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   237
0d64aa6cdf34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22149
diff changeset
   238
    self position:(self position + count).
22149
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   239
!
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   240
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   241
truncateTo:givenMax
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   242
    "if the streamed contents is larger than maxSize,
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   243
     reset the write position back to this size.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   244
     Otherwise do nothing."
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   245
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   246
    self size > givenMax ifTrue:[
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   247
        self position:givenMax.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   248
    ].    
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   249
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   250
    "
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   251
     |s|
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   252
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   253
     s := '' writeStream.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   254
     s nextPutAll:'123456'.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   255
     s truncateTo:4.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   256
     s nextPutAll:'abc'.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   257
     s contents
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   258
    "
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   259
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   260
    "
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   261
     |s|
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   262
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   263
     s := '' writeStream.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   264
     s nextPutAll:'1234'.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   265
     s truncateTo:4.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   266
     s nextPutAll:'abc'.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   267
     s contents
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   268
    "
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   269
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   270
    "
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   271
     |s|
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   272
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   273
     s := '' writeStream.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   274
     s nextPutAll:'123'.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   275
     s truncateTo:4.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   276
     s nextPutAll:'abc'.
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   277
     s contents
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   278
    "
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   279
22152
f19b33cfb222 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22150
diff changeset
   280
    "
f19b33cfb222 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22150
diff changeset
   281
     |s|
f19b33cfb222 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22150
diff changeset
   282
f19b33cfb222 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22150
diff changeset
   283
     s := 'testFile' asFilename writeStream.
f19b33cfb222 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22150
diff changeset
   284
     s nextPutAll:'123456'.
f19b33cfb222 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22150
diff changeset
   285
     s truncateTo:4.
f19b33cfb222 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22150
diff changeset
   286
     s nextPutAll:'abc'.
f19b33cfb222 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22150
diff changeset
   287
     s close.
f19b33cfb222 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22150
diff changeset
   288
     'testFile' asFilename contents
f19b33cfb222 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22150
diff changeset
   289
    "
f19b33cfb222 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22150
diff changeset
   290
22149
35844a157ae2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21814
diff changeset
   291
    "Created: / 02-08-2017 / 09:24:58 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   292
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   293
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   294
!WriteStream methodsFor:'private'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   295
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
growCollection
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   297
    "grow the streamed collection to at least 10 elements"
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   298
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   299
    self growCollection:10
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   300
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   301
    "Modified: 19.8.1997 / 17:53:28 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   302
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
growCollection:minNewSize
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   305
    "grow the streamed collection to at least minNewSize"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   306
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   307
    |oldSize newSize newColl|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   308
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   309
    oldSize := collection size.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   310
    (oldSize == 0) ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   311
	newSize := minNewSize
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   312
    ] ifFalse:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   313
	newSize := oldSize * 2.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   314
	(newSize < minNewSize) ifTrue:[newSize := minNewSize].
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   315
    ].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   316
    collection isFixedSize ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   317
	newColl := collection species new:newSize.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   318
	newColl replaceFrom:1 to:oldSize with:collection startingAt:1.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   319
	collection := newColl
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   320
    ] ifFalse:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   321
	collection grow:newSize
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
    ].
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   323
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   324
    "Modified: 19.8.1997 / 17:53:11 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   325
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   326
7260
edfa8d6a6046 method category rename
Claus Gittinger <cg@exept.de>
parents: 7113
diff changeset
   327
!WriteStream methodsFor:'private-accessing'!
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   328
11794
ad5fcc151a09 #on: - set readLimit to 0, so that setToEnd positions to end of written
Stefan Vogel <sv@exept.de>
parents: 11324
diff changeset
   329
on:aCollection
ad5fcc151a09 #on: - set readLimit to 0, so that setToEnd positions to end of written
Stefan Vogel <sv@exept.de>
parents: 11324
diff changeset
   330
    super on:aCollection.
ad5fcc151a09 #on: - set readLimit to 0, so that setToEnd positions to end of written
Stefan Vogel <sv@exept.de>
parents: 11324
diff changeset
   331
    readLimit := 0.
ad5fcc151a09 #on: - set readLimit to 0, so that setToEnd positions to end of written
Stefan Vogel <sv@exept.de>
parents: 11324
diff changeset
   332
!
ad5fcc151a09 #on: - set readLimit to 0, so that setToEnd positions to end of written
Stefan Vogel <sv@exept.de>
parents: 11324
diff changeset
   333
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   334
on:aCollection from:start to:last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   335
    "create and return a new stream for writing onto aCollection, where
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   336
     writing is limited to the elements in the range start to last."
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   337
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   338
    super on:aCollection from:start to:last.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   339
    writeLimit := last.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   340
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   341
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   342
!WriteStream methodsFor:'queries'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   343
21132
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   344
endsWith:aCollection
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   345
    "Answer true, if the contents of the stream ends with aCollection.
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   346
     Speedup for upToAll:, throughAll etc."
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   347
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   348
    |sz start "{ Class: SmallInteger }"|
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   349
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   350
    collection isNil ifTrue:[
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   351
        "only supported for internal streams"
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   352
        self shouldNotImplement.
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   353
    ].
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   354
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   355
    sz := aCollection size.
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   356
    start := position + 1 - sz.
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   357
    ^ start > 0 and:[(collection copyFrom:position+1-sz to:position) endsWith:aCollection].
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   358
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   359
    "
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   360
        (WriteStream with:'abcdef') endsWith:'def'
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   361
        (WriteStream with:'def') endsWith:'def'
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   362
        (WriteStream with:'abc') endsWith:'def'
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   363
        (WriteStream with:'ef') endsWith:'def'
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   364
false    "
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   365
!
48e561eba578 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20432
diff changeset
   366
3031
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   367
size
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   368
    "return the current size"
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   369
15347
bf763ed0a879 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 15179
diff changeset
   370
    ^ position
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   371
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   372
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   373
!WriteStream methodsFor:'reading'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   374
a27a279701f8 Initial revision
claus
parents:
diff changeset
   375
next
10
claus
parents: 5
diff changeset
   376
    "catch read access to write stream - report an error"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   377
10
claus
parents: 5
diff changeset
   378
    self shouldNotImplement
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   379
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   380
a27a279701f8 Initial revision
claus
parents:
diff changeset
   381
peek
10
claus
parents: 5
diff changeset
   382
    "catch read access to write stream - report an error"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   383
10
claus
parents: 5
diff changeset
   384
    self shouldNotImplement
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   385
! !
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   386
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   387
!WriteStream methodsFor:'testing'!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   388
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   389
isEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   390
    "return true, if the contents of the stream is empty"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   391
15617
14d7a49d826f class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15478
diff changeset
   392
    ^ self position == 0
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   393
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   394
    "Created: 14.10.1997 / 20:44:37 / cg"
16201
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   395
!
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   396
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   397
isReadable
20432
e7056f247cd9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20271
diff changeset
   398
    "return true if the receiver supports reading - that's not true"
16201
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   399
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   400
    ^ false
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   401
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   402
    "Created: / 8.11.1997 / 14:06:07 / cg"
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   403
!
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   404
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   405
isWritable
19437
a769ab315e75 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18294
diff changeset
   406
    "return true, if writing is supported by the receiver.
16201
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   407
     Always return true here"
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   408
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   409
    ^ true
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   410
0b2ca38fc441 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15653
diff changeset
   411
    "Modified: 16.5.1996 / 14:44:49 / cg"
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   412
! !
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   413
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   414
!WriteStream methodsFor:'writing'!
369
claus
parents: 359
diff changeset
   415
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   416
next:count put:anObject
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   417
    "append anObject count times to the receiver.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   418
     Redefined to avoid count grows of the underlying collection -
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   419
     instead a single grow on the final size is performed."
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   420
17181
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   421
    |final|
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   422
17062
ff920d3c1c59 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 16793
diff changeset
   423
    count == 0 ifTrue:[^ self].
ff920d3c1c59 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 16793
diff changeset
   424
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   425
    (collection isNil or:[writeLimit notNil]) ifTrue:[
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   426
        super next:count put:anObject.
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   427
        ^ self.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   428
    ].
369
claus
parents: 359
diff changeset
   429
17181
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   430
    final := position + count.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   431
    (final > collection size) ifTrue:[
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   432
        self growCollection:final
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   433
    ].
369
claus
parents: 359
diff changeset
   434
17181
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   435
    collection from:position + 1 to:final put:anObject.
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   436
    position := position + count.
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   437
    (position > readLimit) ifTrue:[readLimit := position].
12131
0d83d34cdebc changed:
Claus Gittinger <cg@exept.de>
parents: 12130
diff changeset
   438
    "/ ^ anObject -- return self
16793
5e482c02db86 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 16201
diff changeset
   439
5e482c02db86 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 16201
diff changeset
   440
    "
5e482c02db86 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 16201
diff changeset
   441
     '' writeStream next:10 put:$*
5e482c02db86 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 16201
diff changeset
   442
    "
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   443
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   444
a27a279701f8 Initial revision
claus
parents:
diff changeset
   445
nextPut:anObject
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   446
    "append the argument, anObject to the stream.
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   447
     Specially tuned for appending to String, ByteArray and Array streams."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   448
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   449
%{  /* NOCONTEXT */
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   450
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   451
#ifndef NO_PRIM_STREAM
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   452
    REGISTER int pos;
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   453
    unsigned ch;
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   454
    OBJ coll;
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   455
    OBJ p, wL, rL;
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   456
    int __readLimit = -1;
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   457
1136
898af060dfde underline cleanup
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
   458
    coll = __INST(collection);
898af060dfde underline cleanup
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
   459
    p = __INST(position);
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   460
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   461
    if (__isNonNilObject(coll) && __isSmallInteger(p)) {
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   462
        pos = __intVal(p);
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   463
        /* make 1-based */
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   464
        pos = pos + 1;
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   465
        wL = __INST(writeLimit);
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   466
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   467
        if ((wL == nil)
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   468
         || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   469
            OBJ cls;
252
claus
parents: 95
diff changeset
   470
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   471
            cls = __qClass(coll);
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   472
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   473
            rL = __INST(readLimit);
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   474
            if (__isSmallInteger(rL)) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   475
                __readLimit = __intVal(rL);
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   476
            }
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   477
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   478
            if (cls == @global(String)) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   479
                if (__isCharacter(anObject)
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   480
                 && ((ch = __intVal(__characterVal(anObject))) <= 255) /* ch is unsigned */
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   481
                 && (pos <= __stringSize(coll))) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   482
                    __StringInstPtr(coll)->s_element[pos-1] = ch;
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   483
advancePositionAndReturn: ;
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   484
                    if ((__readLimit >= 0) && (pos > __readLimit)) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   485
                        __INST(readLimit) = __mkSmallInteger(pos);
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   486
                    }
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   487
                    __INST(position) = __mkSmallInteger(pos);
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   488
                    RETURN ( anObject );
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   489
                }
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   490
            } else if (cls == @global(ByteArray)) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   491
                if (__isSmallInteger(anObject)
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   492
                 && ((ch = __intVal(anObject)) <= 0xFF) /* ch is unsigned */
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   493
                 && (pos <= __byteArraySize(coll))) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   494
                    __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   495
                    goto advancePositionAndReturn;
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   496
                }
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   497
            } else if (cls == @global(Array)) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   498
                if (pos <= __arraySize(coll)) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   499
                     __ArrayInstPtr(coll)->a_element[pos-1] = anObject;
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   500
                    __STORE(coll, anObject);
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   501
                    goto advancePositionAndReturn;
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   502
                }
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   503
            } else if (cls == @global(Unicode16String)) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   504
                if (__isCharacter(anObject)
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   505
                 && ((ch = __intVal(__characterVal(anObject))) <= 0xFFFF) /* ch is unsigned */
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   506
                 && (pos <= __unicode16StringSize(coll))) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   507
                     __Unicode16StringInstPtr(coll)->s_element[pos-1] = ch;
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   508
                    goto advancePositionAndReturn;
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   509
                }
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   510
            } else if (cls == @global(Unicode32String)) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   511
                if (__isCharacter(anObject)
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   512
                 && (pos <= __unicode32StringSize(coll))) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   513
                     __Unicode32StringInstPtr(coll)->s_element[pos-1] = __intVal(__characterVal(anObject));
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   514
                    goto advancePositionAndReturn;
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   515
                }
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   516
            }
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   517
        }
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   518
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2883
diff changeset
   519
#endif
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   520
%}.
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   521
    (writeLimit isNil
15347
bf763ed0a879 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 15179
diff changeset
   522
    or:[(position + 1) <= writeLimit]) ifTrue:[
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   523
        (position >= collection size) ifTrue:[self growCollection].
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   524
        collection at:(position + 1) put:anObject.
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   525
        position := position + 1.
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   526
        (position > readLimit) ifTrue:[readLimit := position].
838
67a53cceaab1 no global refs
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   527
    ] ifFalse:[
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   528
        WriteError raiseErrorString:'write beyond writeLimit'
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   529
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   530
    ^anObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   531
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   532
a27a279701f8 Initial revision
claus
parents:
diff changeset
   533
nextPutAll:aCollection
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   534
    "append all elements of the argument, aCollection to the stream.
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   535
     Redefined to avoid count grows of the underlying collection -
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   536
     instead a single grow on the final size is performed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   537
17181
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   538
    |nMore "{ Class: SmallInteger }"
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   539
     final "{ Class: SmallInteger }" |
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   540
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   541
    (collection notNil and:[aCollection isSequenceable]) ifFalse:[
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   542
        "/ fallback
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   543
        super nextPutAll:aCollection.
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   544
        ^ self.
13628
1300284a66af changed: #nextPutAll:
Claus Gittinger <cg@exept.de>
parents: 12131
diff changeset
   545
    ].
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   546
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   547
    nMore := aCollection size.
9499
01ee6017569e check for non-colelction in nextPutAll:
fm
parents: 9311
diff changeset
   548
    nMore == 0 ifTrue:[
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   549
        "/ for the programmer..
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   550
        aCollection isCollection ifFalse:[
23011
0b537ee77cf1 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22645
diff changeset
   551
            self proceedableError:'invalid argument (not a collection)'.
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   552
        ].
9499
01ee6017569e check for non-colelction in nextPutAll:
fm
parents: 9311
diff changeset
   553
    ].
01ee6017569e check for non-colelction in nextPutAll:
fm
parents: 9311
diff changeset
   554
17181
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   555
    final := position + nMore.
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   556
    (writeLimit notNil
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   557
    and:[final > writeLimit]) ifTrue:[
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   558
        final := writeLimit.
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   559
        nMore := final - position
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   560
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   561
    (final > collection size) ifTrue:[
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   562
        self growCollection:final
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   563
    ].
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   564
    collection
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   565
        replaceFrom:(position + 1)
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   566
        to:final
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   567
        with:aCollection
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   568
        startingAt:1.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   569
17181
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   570
    position := position + nMore.
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   571
    (position > readLimit) ifTrue:[readLimit := position].
12130
5af9bdd94754 changed: #nextPutAll:
Claus Gittinger <cg@exept.de>
parents: 11794
diff changeset
   572
    "/ ^ aCollection -- self
13628
1300284a66af changed: #nextPutAll:
Claus Gittinger <cg@exept.de>
parents: 12131
diff changeset
   573
1300284a66af changed: #nextPutAll:
Claus Gittinger <cg@exept.de>
parents: 12131
diff changeset
   574
    "Modified: / 04-09-2011 / 20:03:32 / cg"
23011
0b537ee77cf1 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22645
diff changeset
   575
    "Modified: / 24-05-2018 / 21:05:56 / Claus Gittinger"
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   576
!
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   577
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   578
nextPutAll:aCollection startingAt:pos1 to:pos2
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   579
    "append some elements of the argument, aCollection to the stream.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   580
     Redefined to avoid count grows of the underlying collection -
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   581
     instead a single grow on the final size is performed."
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   582
17181
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   583
    |nMore final|
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   584
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   585
    collection isNil ifTrue:[
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   586
        ^ super nextPutAll:aCollection startingAt:pos1 to:pos2
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   587
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   588
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   589
    nMore := pos2 - pos1 + 1.
17181
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   590
    final := position + nMore.
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   591
    (writeLimit notNil
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   592
    and:[final > writeLimit]) ifTrue:[
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   593
        final := writeLimit.
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   594
        nMore := final - position
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   595
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   596
    (final > collection size) ifTrue:[
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   597
        self growCollection:final
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   598
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   599
17181
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   600
    collection replaceFrom:position + 1
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   601
                        to:final
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   602
                      with:aCollection
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   603
                startingAt:pos1.
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   604
17181
a44508e113b6 class: WriteStream
Claus Gittinger <cg@exept.de>
parents: 17062
diff changeset
   605
    position := position + nMore.
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   606
    (position > readLimit) ifTrue:[readLimit := position].
12131
0d83d34cdebc changed:
Claus Gittinger <cg@exept.de>
parents: 12130
diff changeset
   607
    "/ ^ aCollection -- return self
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   608
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   609
    "
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   610
     |s|
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   611
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   612
     s := '' writeStream.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   613
     s nextPutAll:'hello '.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   614
     s nextPutAll:'1234world012345' startingAt:5 to:9.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   615
     s contents
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   616
    "
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   617
1541
6ed5feddc4ed checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1539
diff changeset
   618
    "Modified: 12.7.1996 / 10:31:36 / cg"
8361
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   619
!
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   620
11324
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   621
nextPutAllUnicode:aString
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   622
    "normal streams can not handle multi-byte characters, so convert them to utf8"
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   623
15653
197b5c750d10 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15646
diff changeset
   624
    "this code is not perfect if you use both #nextPutAll: and #nextPutAllUnicode:
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   625
     with the same stream, since 8-bit characters (with the highest bits set)
15653
197b5c750d10 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15646
diff changeset
   626
     are not stored as UTF, so we get some inconsistent string"
197b5c750d10 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15646
diff changeset
   627
197b5c750d10 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15646
diff changeset
   628
    collection isString ifTrue:[
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   629
	collection bitsPerCharacter == 16 ifTrue:[
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   630
	    self nextPutAllUtf16:aString.
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   631
	] ifFalse:[
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   632
	    self nextPutAllUtf8:aString.
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   633
	].
11324
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   634
    ] ifFalse:[
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   635
	self nextPutAll:aString
11324
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   636
    ].
13738
e11fccebb0c3 changed: #nextPutAllUnicode:
Claus Gittinger <cg@exept.de>
parents: 13628
diff changeset
   637
e11fccebb0c3 changed: #nextPutAllUnicode:
Claus Gittinger <cg@exept.de>
parents: 13628
diff changeset
   638
    "Modified: / 28-09-2011 / 16:15:52 / cg"
11324
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   639
!
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   640
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   641
nextPutByte:anObject
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   642
    "append the argument, anObject to the stream.
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   643
     Specially tuned for appending to String and ByteArray streams."
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   644
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   645
%{  /* NOCONTEXT */
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   646
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   647
#ifndef NO_PRIM_STREAM
19828
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   648
    OBJ coll = __INST(collection);
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   649
    OBJ p = __INST(position);
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   650
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   651
    if (__isNonNilObject(coll) && __isSmallInteger(p) && __isSmallInteger(anObject)) {
19828
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   652
        OBJ wL  = __INST(writeLimit);
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   653
        INT pos = __intVal(p) + 1;    /* make 1-based and usable for update below */
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   654
        unsigned int ch = __intVal(anObject);
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   655
19828
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   656
        if (ch <= 0xFF &&  /* ch is unsigned */
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   657
            ((wL == nil) || (__isSmallInteger(wL) && (pos <= __intVal(wL))))) {
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   658
            OBJ cls = __qClass(coll);
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   659
            OBJ rL = __INST(readLimit);
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   660
            INT __readLimit = -1;
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   661
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   662
            if (__isSmallInteger(rL)) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   663
                __readLimit = __intVal(rL);
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   664
            }
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   665
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   666
            if (cls == @global(String)) {
19828
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   667
                if (pos <= __stringSize(coll)) { 
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   668
                    __StringInstPtr(coll)->s_element[pos-1] = ch;
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   669
    advancePositionAndReturn: ;
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   670
                    if ((__readLimit >= 0) && (pos > __readLimit)) {
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   671
                        __INST(readLimit) = __mkSmallInteger(pos);
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   672
                    }
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   673
                    __INST(position) = __mkSmallInteger(pos);
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   674
                    RETURN ( anObject );
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   675
                }
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   676
            } else if (cls == @global(ByteArray)) {
19828
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   677
                if (pos <= __byteArraySize(coll)) { 
19643
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   678
                    __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   679
                    goto advancePositionAndReturn;
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   680
                }
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   681
            }
98714992ae69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19437
diff changeset
   682
        }
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   683
    }
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   684
#endif
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   685
%}.
19828
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   686
    ((writeLimit isNil or:[(position + 1) <= writeLimit])
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   687
      and:[position >= collection size]) ifTrue:[
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   688
        self growCollection.
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   689
        ^ self nextPutByte:anObject.  "try again"                    
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   690
    ] ifFalse:[
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   691
        ^ super nextPutByte:anObject
03328e922f12 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 19643
diff changeset
   692
    ].
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   693
!
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   694
8361
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   695
nextPutBytes:count from:anObject startingAt:start
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   696
    "write count bytes from an object starting at index start.
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   697
     Return the number of bytes written.
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   698
     The object must have non-pointer indexed instvars
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   699
     (i.e. be a ByteArray, String, Float- or DoubleArray).
8361
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   700
     Use with care - non object oriented i/o.
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   701
     This is provided for compatibility with externalStream;
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   702
     to support binary storage"
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   703
11794
ad5fcc151a09 #on: - set readLimit to 0, so that setToEnd positions to end of written
Stefan Vogel <sv@exept.de>
parents: 11324
diff changeset
   704
    anObject isByteCollection ifTrue:[
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   705
	self nextPutAll:anObject startingAt:start to:(start + count - 1).
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   706
	^ count.
8361
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   707
    ].
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   708
    ^ super nextPutBytes:count from:anObject startingAt:start
11324
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   709
!
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   710
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   711
nextPutUnicode:aCharacter
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   712
    "normal streams can not handle multi-byte characters, so convert them to utf8"
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   713
15653
197b5c750d10 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15646
diff changeset
   714
    "this code is not perfect if you use both #nextPut: and #nextPutUnicode:
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   715
     with the same stream, since 8-bit characters (with the highest bits set)
15653
197b5c750d10 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15646
diff changeset
   716
     are not stored as UTF, so we get some inconsistent string"
197b5c750d10 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15646
diff changeset
   717
197b5c750d10 class: WriteStream
Stefan Vogel <sv@exept.de>
parents: 15646
diff changeset
   718
    collection isString ifTrue:[
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   719
	collection bitsPerCharacter == 16 ifTrue:[
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   720
	    self nextPutUtf16:aCharacter.
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   721
	] ifFalse:[
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   722
	    self nextPutUtf8:aCharacter.
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   723
	].
11324
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   724
    ] ifFalse:[
18294
5c7b472ab445 eliminated a not message
Claus Gittinger <cg@exept.de>
parents: 18163
diff changeset
   725
	self nextPut:aCharacter.
11324
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   726
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   727
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   728
1965
4ca38574df3b Fix typo.
Stefan Vogel <sv@exept.de>
parents: 1584
diff changeset
   729
!WriteStream class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   730
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   731
version
19437
a769ab315e75 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18294
diff changeset
   732
    ^ '$Header$'
12130
5af9bdd94754 changed: #nextPutAll:
Claus Gittinger <cg@exept.de>
parents: 11794
diff changeset
   733
!
5af9bdd94754 changed: #nextPutAll:
Claus Gittinger <cg@exept.de>
parents: 11794
diff changeset
   734
5af9bdd94754 changed: #nextPutAll:
Claus Gittinger <cg@exept.de>
parents: 11794
diff changeset
   735
version_CVS
19437
a769ab315e75 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18294
diff changeset
   736
    ^ '$Header$'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   737
! !
19437
a769ab315e75 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18294
diff changeset
   738