--- a/CharacterWriteStream.st Thu May 19 07:07:52 2016 +0200
+++ b/CharacterWriteStream.st Fri May 20 06:45:01 2016 +0200
@@ -89,9 +89,10 @@
"reset the stream, to write again over the existing (or already written) contents.
See the comment in WriteStream>>contents"
+ "start with 8-bit String again"
collection := String new:collection size.
currentCharacterSize := collection bitsPerCharacter.
- super resetPosition.
+ position := 0.
! !
!CharacterWriteStream methodsFor:'private'!
--- a/Class.st Thu May 19 07:07:52 2016 +0200
+++ b/Class.st Fri May 20 06:45:01 2016 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
@@ -2257,17 +2255,17 @@
|rv pkg|
UpdateChangeFileQuerySignal query ifTrue:[
- rv := aClass revision.
- rv isNil ifTrue:[rv := '???'].
- pkg := aClass package.
-
- self
- writingChangeWithTimeStamp:false
- perform:#addInfoRecord:to:
- with:('checkin %1 into %2 (%3)'
- bindWith:aClass name
- with:pkg
- with:rv).
+ rv := aClass revision.
+ rv isNil ifTrue:[rv := '???'].
+ pkg := aClass package.
+
+ self
+ writingChangeWithTimeStamp:false
+ perform:#addInfoRecord:to:
+ with:('checkin %1 (%2) into %3'
+ bindWith:aClass name
+ with:rv
+ with:pkg).
]
"Created: / 18.11.1995 / 17:04:58 / cg"
--- a/Message.st Thu May 19 07:07:52 2016 +0200
+++ b/Message.st Fri May 20 06:45:01 2016 +0200
@@ -196,8 +196,9 @@
arguments
"return the arguments of the message"
-
- ^ args ? #()
+
+ args isNil ifTrue:[^ #()].
+ ^ args.
!
arguments:argArray
@@ -280,6 +281,6 @@
!Message class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Message.st,v 1.35 2015-02-20 21:27:06 cg Exp $'
+ ^ '$Header$'
! !
--- a/PositionableStream.st Thu May 19 07:07:52 2016 +0200
+++ b/PositionableStream.st Fri May 20 06:45:01 2016 +0200
@@ -282,6 +282,57 @@
!PositionableStream methodsFor:'misc functions'!
+copy:numberOfBytes into:aWriteStream
+ "read from the receiver, and write numberOfBytes data to another aWriteStream.
+ Return the number of bytes which have been transferred.
+ Redefined here to avoid intermediate buffers/garbage."
+
+ |endPosition cnt|
+
+ collection notNil ifTrue:[
+ endPosition := (position+numberOfBytes) min:readLimit.
+ aWriteStream nextPutAll:collection startingAt:position+1 to:endPosition.
+ cnt := endPosition - position.
+ position := endPosition.
+ ^ cnt.
+ ].
+
+ ^ super copy:numberOfBytes into:aWriteStream.
+
+
+ "
+ 'hello world' readStream copy:5 into:'/tmp/mist' asFilename writeStream.
+ 'hello world' readStream
+ copy:5 into:Transcript;
+ copy:20 into:Transcript.
+ 'hello world' readStream copy:5 into:'' writeStream inspect.
+ #[1 2 3 4 5 6 7] readStream copy:2 into:'/tmp/mist' asFilename writeStream binary.
+ #[1 2 3 4 5 6 7] readStream copy:3 into:#[] writeStream.
+ "
+
+ "
+ |rs ws cnt|
+
+ ws := #() writeStream.
+ rs := #( 1 2 3 4 a nil true) readWriteStream.
+ rs next.
+ cnt := rs copyToEndInto:ws bufferSize:0.
+ Transcript show:cnt; show:' '; showCR:ws contents.
+ "
+!
+
+copy:numberOfBytes into:aWriteStream bufferSize:bufferSize
+ "read from the receiver, and write numberOfBytes data to another aWriteStream.
+ Return the number of bytes which have been transferred.
+ Redefined here to avoid intermediate buffers/garbage.
+ bufferSize does not matter here."
+
+ collection notNil ifTrue:[
+ ^ self copy:numberOfBytes into:aWriteStream.
+ ].
+ ^ super copy:numberOfBytes into:aWriteStream bufferSize:bufferSize.
+!
+
copyToEndInto:aWriteStream
"read from the receiver, and write all data up to the end to another stream.
Return the number of bytes which have been transferred.
@@ -439,7 +490,7 @@
reset
"set the read position to the beginning of the collection"
- self resetPosition
+ position := 0.
"
|s|
@@ -452,6 +503,7 @@
!
resetPosition
+ <resource: #obsolete>
"set the read position to the beginning of the collection"
position := 0
--- a/ReadWriteStream.st Thu May 19 07:07:52 2016 +0200
+++ b/ReadWriteStream.st Fri May 20 06:45:01 2016 +0200
@@ -121,6 +121,13 @@
!ReadWriteStream methodsFor:'accessing'!
+clear
+ "re-initialize the stream to write to the beginning and
+ to not read any data."
+
+ position := readLimit := 0.
+!
+
contents
"return the contents as written so far;
redefined to prevent confusion resulting due to
@@ -136,19 +143,22 @@
!
reset
- "set the read position to the beginning of the collection"
-
- self resetPosition
-
-!
-
-resetPosition
"set the read position to the beginning of the collection.
Because I am a read/write stream, the readLimit is set to the current write position.
Thus, the just written data can be read back."
readLimit := position max:readLimit.
- super resetPosition
+ position := 0.
+!
+
+resetPosition
+ <resource: #obsolete>
+ "set the read position to the beginning of the collection.
+ Because I am a read/write stream, the readLimit is set to the current write position.
+ Thus, the just written data can be read back."
+
+ readLimit := position max:readLimit.
+ position := 0.
! !
!ReadWriteStream methodsFor:'converting'!
@@ -196,10 +206,10 @@
!ReadWriteStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ReadWriteStream.st,v 1.39 2015-03-12 19:27:01 stefan Exp $'
+ ^ '$Header$'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/ReadWriteStream.st,v 1.39 2015-03-12 19:27:01 stefan Exp $'
+ ^ '$Header$'
! !
--- a/Stream.st Thu May 19 07:07:52 2016 +0200
+++ b/Stream.st Fri May 20 06:45:01 2016 +0200
@@ -691,15 +691,26 @@
!Stream methodsFor:'misc functions'!
-copy:numberOfBytes into:outStream bufferSize:bufferSize
- "read from the receiver, and write all data up to count or the end to another stream.
- Return the number of bytes which have been transferred"
-
- |bufferSpecies buffer bytesWritten readCount writeCount count freeBuffer remaining|
-
- bytesWritten := 0.
+copy:numberOfBytes into:outStream
+ "read from the receiver, and write numberOfBytes data to another aWriteStream.
+ Return the number of bytes which have been transferred."
+
+ ^ self copy:numberOfBytes into:outStream bufferSize:(128*1024)
+!
+
+copy:numberOfBytes into:aWriteStream bufferSize:bufferSizeArg
+ "read from the receiver, and write numberOfBytes data to another aWriteStream.
+ Return the number of bytes which have been transferred."
+
+ |bufferSpecies bufferSize bytesLeft buffer countWritten freeBuffer|
+
+ countWritten := 0.
bufferSpecies := self contentsSpecies.
+ bytesLeft := numberOfBytes.
+ bufferSize := bufferSizeArg min:numberOfBytes.
+
bufferSpecies == ByteArray ifTrue:[
+ "an ExternalBytes buffer is faster when writing to a windows ExternalStream"
buffer:= ExternalBytes unprotectedNew:bufferSize.
freeBuffer := true.
] ifFalse:[
@@ -707,39 +718,42 @@
freeBuffer := false.
].
- remaining := numberOfBytes.
- "Note: atEnd will block if reading from an empty pipe or socket"
- [remaining ~~ 0 and:[self atEnd]] whileFalse:[
- readCount := self nextAvailableBytes:(bufferSize min:remaining) into:buffer startingAt:1.
+ "read loop: read required bytes"
+ [
+ |readCount|
+
+ readCount := self nextAvailable:bytesLeft into:buffer startingAt:1.
+ bytesLeft := bytesLeft - readCount.
+
readCount > 0 ifTrue:[
+ |writeCount|
+
writeCount := 0.
+ "write loop: write until all is written"
[
- count := outStream nextPutBytes:readCount-writeCount
- from:buffer
- startingAt:writeCount+1.
- bytesWritten := bytesWritten + count.
+ |count|
+
+ count := aWriteStream
+ nextPutAll:readCount-writeCount
+ from:buffer
+ startingAt:writeCount+1.
writeCount := writeCount + count.
writeCount < readCount ifTrue:[
- outStream writeWait.
+ aWriteStream writeWait.
true.
] ifFalse:[
false
].
] whileTrue.
- remaining := remaining - writeCount.
- ].
- ].
+ countWritten := countWritten + writeCount.
+ ].
+ "Note: atEnd will block if reading from an empty pipe or socket.
+ avoid atEnd if possible, because it reads a single byte."
+ bytesLeft ~~ 0 or:[self atEnd not]
+ ] whileTrue.
+
freeBuffer ifTrue:[ buffer free ].
- ^ bytesWritten
-
- "
- 'hello world' readStream copyToEndInto:'/tmp/mist' asFilename writeStream.
- 'hello world' readStream copyToEndInto:#[] writeStream.
- ('/tmp/mist' asFilename readStream binary; yourself) copyToEndInto:#[] writeStream
- #[1 2 3 4 5 6 7] readStream copyToEndInto:'/tmp/mist' asFilename writeStream.
- #[1 2 3 4 5 6 7] readStream copyToEndInto:'' writeStream.
-
- "
+ ^ countWritten.
!
copyToEndFrom:inStream
@@ -3465,7 +3479,7 @@
(answerStream contents endsWith:aCollection) ifTrue:[
|pos|
pos := answerStream position.
- answerStream resetPosition.
+ answerStream reset.
^ answerStream next:pos-aCollection size.
]
].
--- a/WriteStream.st Thu May 19 07:07:52 2016 +0200
+++ b/WriteStream.st Fri May 20 06:45:01 2016 +0200
@@ -184,7 +184,7 @@
See the comment in WriteStream>>contents"
collection := collection species new:(collection size).
- super reset
+ position := 0.
"Modified: 19.2.1997 / 08:57:00 / stefan"
! !