Stream API Functions: Unterschied zwischen den Versionen

Aus expecco Wiki (Version 2.x)
Zur Navigation springen Zur Suche springen
Zeile 32: Zeile 32:
PipeStream <code>readingFrom:</code>''OS-command'' => PipeStream
PipeStream <code>readingFrom:</code>''OS-command'' => PipeStream
:: returns a stream reading the output from an OS-command
:: returns a stream reading the output from an OS-command

=== Testing ===
''aStream'' <code>atEnd</code> => Boolean
:: returns true if no more elements are to be read


=== Reading ===
=== Reading ===


''aStream'' <code>next</code> => Character | nil
===== next =====
<br>''aStream''.<code>next()</code> [JS]
Returns the next element from the stream.
:: returns the next character (as character object)

''aStream'' '''next'''
''aStream''.'''next'''() [JS]


Example:
Example:
Zeile 47: Zeile 48:
=> character
=> character


''aStream'' <code>next:</code>''count'' => String
===== next: =====
<br>''aStream''.<code>next(</code>''count''<code>)</code> [JS]
Returns the next n elements from the stream.
:: returns the next count characters (as a string)

''aStream'' '''next:''' ''count''
''aStream''.'''next'''(''count'') [JS]


Example:
Example:
Zeile 59: Zeile 57:
=> string-of-5-chars
=> string-of-5-chars


===== nextByte =====
''aStream'' nextByte => Integer | nil
Returns the next character as a byte valued integer.
:: returns the next byte (as an integer)
Only valid for character streams.


===== nextBytes: =====
''aStream'' nextBytes: ''count'' => ByteArray
Returns the next n characters as a byteArray.
:: returns the next count bytes (as a byte array)
Only valid for character streams.


=== Writing===
=== Writing===

Version vom 25. September 2020, 22:51 Uhr

This document lists most useful (and most often needed) functions. Be aware, that there are many more to be found in either the class references or via the builtin class browser.

Reference: Stream and ExternalStream and Socket

Back to Useful API Functions

Creation[Bearbeiten]

Internal Streams[Bearbeiten]

aCollection readStream => Stream
aString readStream => Stream

returns a stream to read from a general collection or especially from a string (which is a collection of characters)

aCollection writeStream
aString writeStream

returns a stream to write to a general collection or especially a string stream.
External Streams[Bearbeiten]

pathString asFilename readStream => Stream
pathString asFilename writeStream => Stream
pathString asFilename appendingWriteStream => Stream

returns a stream to read / write the file named aFilenameString

Socket newTCPclientToHost:hostNameOrAddress port:aPortOrServiceName => SocketStream

returns a connected socket for reading and writing

PipeStream readingFrom:OS-command => PipeStream

returns a stream reading the output from an OS-command

Testing[Bearbeiten]

aStream atEnd => Boolean

returns true if no more elements are to be read

Reading[Bearbeiten]

aStream next => Character | nil
aStream.next() [JS]

returns the next character (as character object)

Example:

 s := 'data.txt' asFilename readStream.
 s next.
 => character

aStream next:count => String
aStream.next(count) [JS]

returns the next count characters (as a string)

Example:

 s := 'data.txt' asFilename readStream.
 s next:5.
 => string-of-5-chars

aStream nextByte => Integer | nil

returns the next byte (as an integer)

aStream nextBytes: count => ByteArray

returns the next count bytes (as a byte array)

Writing[Bearbeiten]

nextPut:[Bearbeiten]

Appends (writes) an element to the stream.

aStream nextPut: someElement

aStream.nextPut (someElement) [JS]

Example:

 s := 'data.txt' asFilename writeStream.
 s nextPut: $a.
 s nextPut: $b.
 s close.

Example:

 s := #() writeStream.
 s nextPut: 1.
 s nextPut: 'two'.
 s nextPut: 3.14159.
 s contents
 -> #( 1 'two' 3.14159 )
nextPutAll:[Bearbeiten]

Appends (writes) a number of elements to the stream.

aStream nextPutAll: aCollectionOfElements

aStream.nextPutAll (aCollectionOfElements) [JS]

Example:

 s := 'data.txt' asFilename writeStream.
 s nextPutAll: 'abc'.
 s close.
nextPutByte:[Bearbeiten]

Appends a byte valued integer to the stream. Only valid for character streams.



Copyright © 2014-2024 eXept Software AG