ReadStream.st
changeset 17604 1e1d9d9f1d2e
parent 17597 a78c4a2bf366
child 17612 368b5e4da6c9
--- a/ReadStream.st	Thu Mar 12 14:52:37 2015 +0100
+++ b/ReadStream.st	Thu Mar 12 18:10:39 2015 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1988 by Claus Gittinger
 	      All Rights Reserved
@@ -11,6 +13,8 @@
 "
 "{ Package: 'stx:libbasic' }"
 
+"{ NameSpace: Smalltalk }"
+
 PositionableStream subclass:#ReadStream
 	instanceVariableNames:''
 	classVariableNames:''
@@ -71,6 +75,33 @@
     ^ super with:aCollection
 ! !
 
+!ReadStream methodsFor:'Compatibility-Squeak'!
+
+next: n into: aCollection startingAt: startIndex
+    "Read n objects into the given collection.
+    Return aCollection or a partial copy if less than
+    n elements have been read."
+
+    | max |
+
+    collection notNil ifTrue:[
+        max := (readLimit - position) min: n.
+        aCollection
+            replaceFrom: startIndex
+            to: startIndex+max-1
+            with: collection
+            startingAt: position+1.
+        position := position + max.
+        max = n
+            ifTrue:[^ aCollection]
+            ifFalse:[^ aCollection copyFrom: 1 to: startIndex+max-1].
+    ].
+
+    ^ super next:n into:aCollection startingAt:startIndex.
+
+
+    "Modified: / 12-09-2010 / 13:06:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
 
 !ReadStream methodsFor:'converting'!
 
@@ -117,6 +148,35 @@
     "Modified: 15.5.1996 / 17:30:33 / cg"
 ! !
 
+!ReadStream methodsFor:'misc functions'!
+
+copyToEndInto:aWriteStream bufferSize:bufferSize
+    "read from the receiver, and write all data up to the end to another stream.
+     Return the number of bytes which have been transferred.
+     Redefined here to avoid intermediate buffers/garbage.
+     bufferSize does not matter here."
+
+    |cnt|
+
+    collection notNil ifTrue:[
+        aWriteStream nextPutAll:collection startingAt:position+1 to:readLimit.
+        cnt := readLimit - position.
+        position := readLimit.
+        ^ cnt.
+    ].
+    ^ super copyToEndInto:aWriteStream bufferSize:bufferSize.
+
+    "
+     |rs ws|
+
+     ws := #() writeStream.
+     rs := #( 1 2 3 4 ) readStream.
+     rs next.
+     rs copyToEndInto:ws bufferSize:0.
+     ws contents.
+    "
+! !
+
 !ReadStream methodsFor:'queries'!
 
 collectionSize
@@ -920,9 +980,10 @@
 !ReadStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.79 2015-03-09 17:46:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.80 2015-03-12 17:10:39 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.79 2015-03-09 17:46:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.80 2015-03-12 17:10:39 stefan Exp $'
 ! !
+