eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ExternalStream':

Home

everywhere
www.exept.de
for:
[back]

Class: ExternalStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--PeekableStream
         |
         +--PositionableStream
            |
            +--WriteStream
               |
               +--ReadWriteStream
                  |
                  +--ExternalStream
                     |
                     +--ExternalReadStream
                     |
                     +--ExternalWriteStream
                     |
                     +--FileStream
                     |
                     +--NonPositionableExternalStream

Package:
stx:libbasic
Category:
Streams-External
Version:
rev: 1.341 date: 2010/04/12 19:27:17
user: stefan
file: ExternalStream.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger
Stefan Vogel (many, many fixes ...)

Description:


ExternalStream defines protocol common to Streams which have a file-descriptor and
represent some file or communicationChannel of the underlying OperatingSystem.
ExternalStream is abstract; concrete classes are FileStream, PipeStream etc.

ExternalStreams can be in two modes: text- (the default) and binary-mode.
In text-mode, the elements read/written are characters;
while in binary-mode the basic elements are bytes which read/write as SmallIntegers
in the range 0..255.

Also, the stream can be either in buffered or unbuffered mode. In buffered mode,
data is not written until either a cr is written (in text mode) or a synchronizeOutput
is sent (in both modes).

The underlying OperatingSystem streams may either be closed explicitely (sending a close)
or just forgotten - in this case, the garbage collector will eventually collect the
object AND a close will be performed automatically (but you will NOT know when this
happens - so it is recommended, that you close your files when no longer needed).
Closing is also suggested, since if smalltalk is finished (be it by purpose, or due to
some crash) the data will not be in the file, if unclosed.
All streams understand the close message, so it never hurts to use it (it is defined as
a noop in one of the superclasses).

Most of the methods found here redefine inherited methods for better performance,
since I/O from/to files should be fast.

Recovering a snapshot:
  not all streams can be restored to the state they had before - see the implementation of
  reOpen in subclasses for more information.
  For streams sitting on some communication channel (i.e. Pipes and Sockets) you should
  reestablish the stream upon image restart (make someone dependent on ObjectMemory).
  FileStreams are reopened and positioned to their offset they had at snapshot time.
  This may fail, if the file was removed or renamed - or lead to confusion
  if the contents changed in the meantime.
  Therefore, it is a good idea to reopen files and check for these things at restart time.

[Instance variables:]

    handleType      <Symbol>        desribes what handle is:
                                        win32: #fileHandle, #socketHandle,
                                               #socketFileDescriptor
                                               #filePointer, #socketFilePointer, #pipeFilePointer
                                        unix: #filePointer, #socketFilePointer, #pipeFilePointer
                                    needed for win32, which uses different APIs for the different handles (sigh)
    handle          <Integer>       used to be always a filePointer somehow mapped to an integer (FILE* - not the fd);
                                    now, either a filePointer or a handle (win32)
    mode            <Symbol>        #readwrite, #readonly or #writeonly
    buffered        <Boolean>       true, if buffered (i.e. collects characters - does
                                    not output immediately)
    binary          <Boolean>       true if in binary mode (reads bytes instead of chars)
    eolMode         <Symbol>        one of nil, #cr or #crlf.
                                    determines how lines should be terminated.
                                    nil -> newLine (as in Unix);
                                    #crlf -> with cr-lf (as in MSDOS)
                                    #cr -> with cr (as in VMS)
    hitEOF          <Boolean>       true, if EOF was reached

    lastErrorNumber <Integer>       the value of errno (only valid right after the error -
                                    updated with next i/o operation)

[Class variables:]
    Lobby           <Registry>      keeps track of used ext-streams (to free up FILE*'s)

    StreamErrorSignal       <Signal> parent of all stream errors (see Stream class)
    InvalidReadSignal       <Signal> raised on read from writeonly stream
    InvalidWriteSignal      <Signal> raised on write to readonly stream
    InvalidModeSignal       <Signal> raised on text I/O with binary-stream
                                     or binary I/O with text-stream
    OpenErrorSignal         <Signal> raised if open fails
    StreamNotOpenSignal     <Signal> raised on I/O with non-open stream

Additional notes:
  This class is implemented using the underlying stdio-c library package, which
  has both advantages and disadvantages: since it is portable (posix defined), porting
  ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library
  has big problems handling unbounded Streams, since the EOF handling in stdio is
  not prepared for data to arrive after EOF has been reached - time will show, if we need
  a complete rewrite for UnboundedStream ...

  Also, depending on the system, the stdio library behaves infriendly when signals
  occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal
  is handled transparently - on SYS5.3 (i.e. non unixes :-) the read operation returns
  an error and errno is set to EINTR.
  Thats what the ugly code around all getc-calls is for ...
  Since things get more and more ugly - we will rewrite ExternalStream
  completely, to NOT use any stdio stuff (and do its buffering itself).

  Notice that typical stdio's use a single errno global variable to return an error code,
  this was bad design in the stdio lib (right from the very beginning), since its much
  harder to deal with this in the presence of lightweight processes, where errno gets
  overwritten by an I/O operation done in another thread. (stdio should have been written
  to return errno as a negative number ...).
  To deal with this, the scheduler treats errno like a per-thread private variable,
  and saves/restores the errno setting when switching to another thread.
  (Notice that some thread packages do this also, but ST/X's thread implementation
  does not depend on those, but instead uses a portable private package).

  Finally, if an stdio-stream is open for both reading and writing, we have to call
  fseek whenever we are about to read after write and vice versa.
  Two macros (__READING__ and __WRITING__) have been defined to be used before every
  fread/fgetc and fwrite/putc respectively.


Related information:

    FileStream
    Socket
    PipeStream
    Filename
    OperatingSystem

Class protocol:

Signal constants
o  inaccessibleSignal
ST-80 compatibility: return openErrorSignal

o  invalidModeSignal
return the signal raised when doing text-I/O with a binary stream
or binary-I/O with a text stream

o  invalidOperationSignal
return the signal raised when an unsupported or invalid
I/O operation is attempted

o  invalidReadSignal
return the signal raised when reading from writeonly streams

o  invalidWriteSignal
return the signal raised when writing to readonly streams

o  openErrorSignal
return the signal raised when a file open failed

o  streamIOErrorSignal
return the signal raised when an I/O error occurs.
(for example, a device-IO-error, or reading an NFS-dir,
which is no longer available and has been mounted soft)

o  streamNotOpenSignal
return the signal raised on I/O with closed streams

error handling
o  errorReporter
I know about error codes

o  lastErrorNumber
return the errno of the last error

o  lastErrorString
return a message string describing the last error

o  reportOn: anErrorSymbolOrNumber
an error occured.
Report it via an Exception

initialization
o  initDefaultEOLMode

o  initModeStrings
initialize modeStrings which are passed down to the underlying
fopen/fdopen functions.

o  initialize

o  reOpenFiles
reopen all files (if possible) after a snapShot load.
This is invoked via the #earlyRestart change notification.

o  update: something with: aParameter from: changedObject
have to reopen files when returning from snapshot

instance creation
o  forFileDescriptor: aFileDescriptor mode: modeSymbol
given a fileDescriptor, create an ExternalStream object
to operate on this fd.
The modeSymbol-argument is #readonly, #readwrite, ....
This may be used to wrap fd's as returned by user
primitive code, or to wrap pipe-fds into externalStreams.

o  forFileDescriptor: aFileDescriptor mode: modeSymbol buffered: buffered handleType: handleTypeSymbol
given a fileDescriptor, create an ExternalStream object
to operate on this fd.
The modeSymbol-argument is #readonly, #readwrite, ....
This may be used to wrap fd's as returned by user
primitive code, or to wrap pipe-fds into externalStreams.

o  forReadWriteToFileDescriptor: aFileDescriptor
given a fileDescriptor, create an ExternalStream object
to read/write from/to this fd. This may be used to wrap fd's
as returned by user primitive code, or to wrap pipe-
filedescriptors into externalStreams.

o  forReadingFromFileDescriptor: aFileDescriptor
given a fileDescriptor, create an ExternalStream object
to read from this fd. This may be used to wrap fd's
as returned by user primitive code, or to wrap pipe-
filedescriptors into externalStreams.

o  forWritingToFileDescriptor: aFileDescriptor
given a fileDescriptor, create an ExternalStream object
to write to this fd. This may be used to wrap fd's
as returned by user primitive code, or to wrap pipe-
filedescriptors into externalStreams.

o  new

obsolete
o  makePTYPair
obsolete since 12-07-2003

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  makePipe
obsolete since 12-07-2003

** This is an obsolete interface - do not use it (it may vanish in future versions) **


Instance protocol:

Compatibility-Dolphin
o  beText

Compatibility-Squeak
o  nextInto: aByteArrayOrString
read elements into the argument, whose size determines the amount
of bytes to read. If not enough elements could be read, return
a copy of the argument; otherwise, return the filled argument.

o  readInto: aContainer startingAt: index count: nElements
same as #nextBytes:into:startingAt: for ByteArrays;
for LongArrays, nelements longs are read.
Squeak compatibility.

o  readOnly
Squeak compatibility: make the stream readOnly

Signal constants
o  invalidReadSignal

o  invalidWriteSignal

accessing
o  binary
switch to binary mode - default is text

o  buffered: aBoolean
turn buffering on or off - default is on

o  contents
return the contents of the file from the current position up-to
the end. If the stream is in binary mode, a ByteArray containing
the byte values is returned.
In text-mode, a collection of strings, each representing one line,
is returned.

o  contentsAsString
to compensate for the bad naming, use this to make things explicit.
See also #contents, which returns the lines as stringCollection for textFiles.

o  contentsOfEntireFile
ST-80 compatibility: return contents as a String (or byteArray, if in binary mode).
See also #contents, which returns the lines as stringCollection for text files.

o  contentsSpecies
return the kind of object to be returned by sub-collection builders
(such as upTo)

o  eolMode: aSymbolOrNil
specify how end-of-line (EOL) is to be marked.
The argument may be one of:
#crlf -> add a CR-NL, as in MSDOS
#cr -> add a CR, as in VMS
#nl -> add a NL, as in Unix
anyOther -> like #nl

o  fileDescriptor
return the fileDescriptor of the receiver -
notice: this one returns the underlying OSs fileDescriptor -
this may not be available on all platforms (i.e. non unix systems).

o  fileDescriptorOfFile: handle
for migration to rel5 only:
return the fileDescriptor of the argument handle -
notice: this one returns the underlying OSs fileDescriptor -
this may not be available on all platforms (i.e. non unix systems).

o  fileHandle
return the fileHandle of the receiver.
Under unix, this is the fileDescriptor; under windows, this is the Handle.

o  filePointer
return the filePointer of the receiver -
notice: for portability stdio is used; this means you will get
a FILE * - not a fileDescriptor.
(what you really get is a corresponding integer).
You cannot do much with the returned value
- except passing it to a primitive, for example.

o  lineEndCRLF

o  lineEndTransparent

o  pathName
answer the pathName of the stream.
Only FileStreams know the pathName, so we return an empty string here

o  readonly
set access mode to readonly

o  readwrite
set access mode to readwrite

o  text
switch to text mode - default is text

o  useCRLF: aBoolean
turn on or off CRLF sending (instead of LF only) - default is off.
This method is provided for backward compatibility - see #eolMode:
which offers another choice.

o  writeonly
set access mode to writeonly

closing
o  close
close the stream - tell operating system

o  shutDown
close the stream - added for protocol compatibility with PipeStream.
see comment there

copying
o  copy
answer a copy of myself.
Have to dup the filedescriptor

error handling
o  argumentMustBeCharacter
report an error, that the argument must be a character in 0..FF

o  argumentMustBeInteger
report an error, that the argument must be an integer

o  argumentMustBeString
report an error, that the argument must be a string

o  errorAlreadyOpen
report an error, that the stream is already opened

o  errorBinary
report an error, that the stream is in binary mode

o  errorNotBinary
report an error, that the stream is not in binary mode

o  errorNotBuffered
report an error, that the stream is not in buffered mode

o  errorNotOpen
report an error, that the stream has not been opened

o  errorReadOnly
report an error, that the stream is a readOnly stream

o  errorReporter
ST-80 mimicry.

o  errorUnsupportedOperation
report an error, that some unsupported operation was attempted

o  errorWriteOnly
report an error, that the stream is a writeOnly stream

o  ioError
report an error, that some I/O error occured.
(for example, a device-IO-error, or reading an NFS-dir,
which is no longer available and has been mounted soft)

o  lastErrorNumber
return the last error

o  lastErrorString
return a message string describing the last error

o  lastErrorSymbol
return an error symbol describing the last error

o  openError
report an error, that the open failed

o  openError: errorNumber
report an error, that the open failed

o  readError
report an error, that some read error occured

o  writeError
report an error, that some write error occured

finalization
o  finalizationLobby
answer the registry used for finalization.
ExternalStreams have their own Registry

o  finalize
some Stream has been collected - close the file if not already done

instance release
o  executor
return a copy for finalization-registration;
since all we need at finalization time is the fileDescriptor,
a cheaper copy is possible.

line reading/writing
o  nextLine
read the next line (characters up to newline).
Return a string containing those characters excluding the newline.
If the previous-to-last character is a cr, this is also removed,
so its possible to read alien (i.e. ms-dos) text as well.
The line must be shorter than 32K characters - otherwise an error is signalled.

o  nextPutLine: aString
write the characters in aString and append an end-of-Line marker
(LF, CR or CRLF - depending in the setting of eolMode)

o  nextPutLinesFrom: aStream upToLineStartingWith: aStringOrNil
read from aStream up to and including a line starting with aStringOrNil
and append all lines to self.
Can be used to copy/create large files or copy from a pipe/socket.

If aStringOrNil is nil or not matched, copy proceeds to the end.

o  peekForLineStartingWith: aString
read ahead for next line starting with aString;
return the line-string if found, or nil if EOF is encountered.
If matched, do not advance position beyond that line
i.e. nextLine will read the matched line.
If not matched, reposition to original position for further reading.

o  peekForLineStartingWithAny: aCollectionOfStrings
read ahead for next line starting with any of aCollectionOfStrings;
return the index in aCollection if found, nil otherwise..
If no match, do not change position; otherwise advance right before the
matched line so that nextLine will return this line.

misc functions
o  async: aBoolean
set/clear the async attribute - if set, the availability of data on
the receiver will trigger an ioInterrupt.
If cleared (which is the default) no special notification is made.
Notice:
not every OS supports this
- check with OS>>supportsIOInterrupts before using

o  blocking: aBoolean
set/clear the blocking attribute - if set (which is the default)
a read (using next) on the receiver will block until data is available.
If cleared, a read operation will immediately return with a value of
nil.
Turning off blocking is useful when reading from PipeStreams
or Sockets, and the amount of data to be read is not known
in advance. However, the data must then be read using #nextBytes:
methods, in order to avoid other (pastEndRead) exceptions.

o  copyToEndInto: outStream
copy the data into another stream.

o  create
create the stream
- this must be redefined in subclass

** This method raises an error - it must be redefined in concrete classes **

o  ioctl: ioctlNumber
to provide a simple ioctl facility - an ioctl is performed
on the underlying file; no arguments are passed.

o  ioctl: ioctlNumber with: arg
to provide a simple ioctl facility - an ioctl is performed
on the underlying file; the argument is passed as argument.
This is not used by ST/X, but provided for special situations
- for example, to control proprietrary I/O devices.

Since the type of the argument depends on the ioctl being
performed, different arg types are allowed here.
If the argument is nil, an ioctl without argument is performed.
If the argument is an integral number, its directly passed;
if its a kind of ByteArray (ByteArray, String or Structure),
or external data (ExternalBytes or ExternalAddress),
a pointer to the data is passed.
This allows performing most ioctls
- however, it might be tricky to setup the buffer.
Be careful in what you pass - ST/X cannot validate its correctness.

o  reset
set the read position to the beginning of the collection

o  setToEnd
redefined since it must be implemented differently

** This method raises an error - it must be redefined in concrete classes **

o  sync
make sure, that the OS writes cached data to the disk

o  syncData
make sure, that the OS writes cached data to the disk.
In this case, metadata is only written, if it is
required to read the file's data (so metadata will not be written,
if only access/modification time has changed).

o  truncateTo: newSize
truncate the underlying OS file to newSize.
Warning: this may not be implemented on all platforms.

non homogenous reading
o  nextAvailable: count
return the next count elements of the stream as aCollection.
If the stream reaches the end before count elements have been read,
return what is available. (i.e. a shorter collection).
The type of collection is specified in #contentsSpecies.

o  nextAvailableBytes: count into: anObject startingAt: start
read the next count bytes into an object and return the number of
bytes read or the number of bytes read, if EOF is encountered before,
or no more bytes are available for reading (from the pipe/socket).

If the receiver is some socket/pipe-like stream, an exception
is raised if the connection is broken.

Notice, that in contrast to other methods,
this does NOT return nil on EOF, but the actual count.
Thus allowing read of partial blocks.

The object must have non-pointer indexed instvars
(i.e. it must be a ByteArray, String, Float- or DoubleArray).
If anObject is a string or byteArray and reused, this provides the
fastest possible physical I/O (since no new objects are allocated).

Use with care - non object oriented I/O.
Warning: in general, you cannot use this method to pass data from other
architectures since it does not care for byte order or float representation.

o  nextByte
read the next byte and return it as an Integer; return nil on error.
This is allowed in both text and binary modes, always returning the
bytes binary value as an integer in 0..255.

o  nextBytes: count into: anObject startingAt: start
read the next count bytes into an object and return the number of
bytes read or the number of bytes read, if EOF is encountered before.
If the receiver is some socket/pipe-like stream, an exception
is raised if the connection is broken.

Warning: if used with a pipe/socket, this blocks until the requested number
of bytes have been read. See #nextAvailableBytes:into:startingAt:
to only read whats there.

Notice, that in contrast to other methods,
this does NOT return nil on EOF, but the actual count.
Thus allowing read of partial blocks.

The object must have non-pointer indexed instvars
(i.e. it must be a ByteArray, String, Float- or DoubleArray),
or an externalBytes object (with known size).
If anObject is a string or byteArray and reused, this provides the
fastest possible physical I/O (since no new objects are allocated).

Use with care - non object oriented I/O.
Warning: in general, you cannot use this method to pass data from other
architectures (unless you prepared the buffer with care),
since it does not care for byte order or float representation.

o  nextLong
Read four bytes (msb-first) and return the value as a 32-bit signed Integer.
The returned value may be a LargeInteger.
(msb-first for compatibility with other smalltalks)

o  nextLongMSB: msbFlag
Read four bytes and return the value as a 32-bit signed Integer,
which may be a LargeInteger.
If msbFlag is true, value is read with most-significant byte first,
otherwise least-significant byte comes first.
A nil is returned, if EOF is hit before all 4 bytes have been read.
Works in both binary and text modes.

o  nextShortMSB: msbFlag
Read two bytes and return the value as a 16-bit signed Integer.
If msbFlag is true, value is read with most-significant byte first,
otherwise least-significant byte comes first.
A nil is returned if EOF is reached (also when EOF is hit after the first byte).
Works in both binary and text modes.

o  nextUnsignedLongMSB: msbFlag
Read four bytes and return the value as a 32-bit unsigned Integer, which may be
a LargeInteger.
If msbFlag is true, value is read with most-significant byte first, otherwise
least-significant byte comes first.
A nil is returned, if endOfFile occurs before all 4 bytes have been read.
Works in both binary and text modes.

o  nextUnsignedShortMSB: msbFlag
Read two bytes and return the value as a 16-bit unsigned Integer.
If msbFlag is true, value is read with most-significant byte first,
otherwise least-significant byte comes first.
A nil is returned if EOF is reached (also when EOF is hit after the first byte).
Works in both binary and text modes.

o  nextWord
in text-mode:
read the alphaNumeric next word (i.e. up to non letter-or-digit).
return a string containing those characters.
in binary-mode:
read two bytes (msb-first) and return the value as a 16-bit
unsigned Integer (for compatibility with other smalltalks)

non homogenous writing
o  nextPutByte: aByteValue
write a byte.
Works in both binary and text modes.

o  nextPutBytes: count from: anObject startingAt: start
write count bytes from an object starting at index start.
return the number of bytes written - which could be 0.
The object must have non-pointer indexed instvars
(i.e. be a ByteArray, String, Float- or DoubleArray),
or an externalBytes object (with known size).

Use with care - non object oriented i/o.
Warning:
in general, you cannot use this method to pass non-byte data to other
architectures (unless you prepared the buffer with care),
since it does not care for byte order or float representation.

o  nextPutLong: aNumber MSB: msbFlag
Write the argument, aNumber as a long (four bytes). If msbFlag is
true, data is written most-significant byte first; otherwise least
first.
Works in both binary and text modes.

o  nextPutShort: aNumber MSB: msbFlag
Write the argument, aNumber as a short (two bytes). If msbFlag is
true, data is written most-significant byte first; otherwise least
first.
Works in both binary and text modes.

positioning
o  position0Based

** This method raises an error - it must be redefined in concrete classes **

o  position0Based: index0Based

** This method raises an error - it must be redefined in concrete classes **

printing & storing
o  printOn: aStream

private
o  clearEOF

o  closeFile
low level close - may be redefined in subclasses
Don't send this message, send #close instead

o  closeFile: handle
for rel5 only

o  connectTo: aFileDescriptor withMode: modeSymbol handleType: handleTypeSymbol
connect a fileDescriptor; openmode is the string defining the way to open.
This can be used to connect an externally provided fileDescriptor (from
primitive code) or a pipeFileDescriptor (as returned by makePipe) to
a Stream object.
The openMode ('r', 'w' etc.) must match the mode in which
the fileDescriptor was originally opened (otherwise i/o errors will be reported later).

o  dupFd
duplicate my file descriptor

o  fopenMode
answer the mode for fopen.
Only used internally

o  open: aPath withMode: openModeString
low level open; opens the file/device and sets the handle instance
variable. Careful: this does not care for any other state.

o  reOpen
USERS WILL NEVER INVOKE THIS METHOD
sent after snapin to reopen streams.
cannot reopen here since I am abstract and have no device knowledge

o  setAccessor: what to: something
set the filePointer/fileHandle to the given one;
low level private & friend interface; may also be used to connect to some
externally provided handle.

o  setFileDescriptor: anInteger mode: openMode
set the handle based upon a given fileDescriptor -
notice: this one is based on the underlying OSs fileDescriptor -
this may not be available on all platforms (i.e. non unix systems).

o  setFileHandle: something
set the fileHandle to the given one;
low level private & friend interface; may also be used to connect to some
externally provided file handle.

o  setFileHandle: anIntegerOrExternalAddress mode: openMode
set the handle based upon a given fileHandle -
notice: this one is based on the underlying OSs fileDescriptor -
this is a fileDescriptor (Integer) on Unix and Windows, or an Handle (ExternalAddres) on Windows only.
It may not be available on all platforms.

o  setFilePointer: something
set the filePointer to the given one;
low level private & friend interface; may also be used to connect to some
externally provided file.

o  setLastError: aNumber

o  setSocketHandle: something
set the socketHandle to the given one;
low level private & friend interface; may also be used to connect to some
externally provided socket handle.

queries
o  isBinary
return true, if the stream is in binary (as opposed to text-) mode.
The default when created is false.

o  isBlocking
return true, if O_NONBLOCK is NOT set in the fileDescriptor (propably UNIX specific)

o  isExternalStream
return true, if the receiver is some kind of externalStream;
true is returned here - the method redefined from Object.

o  isOpen
return true, if this stream is open

o  isReadable
return true, if this stream can be read from

o  isWritable
return true, if this stream can be written to

reading
o  next
return the next element; advance read position.
In binary mode, an integer is returned, otherwise a character.
If there are no more elements, either an exception is thrown or nil is returned
- see #pastEndRead.

o  next: count
return the next count elements of the stream as a collection.
Redefined to return a String or ByteArray instead of the default: Array.

o  nextOrNil
return the next element; advance read position.
In binary mode, an integer is returned, otherwise a character.
If there are no more elements, nil is returned.
This is #atEnd and #next in a single operation - to speed up some code

o  peek
return the element to be read next without advancing read position.
In binary mode, an integer is returned, otherwise a character.
If there are no more elements, either an exception is thrown or nil is returned
- see #pastEndRead.

o  peekOrNil
return the element to be read next without advancing read position.
In binary mode, an integer is returned, otherwise a character.
If there are no more elements, nil is returned.
Same as #atEnd and #peek in a single operation - speeding up some code

o  upToEnd
return a collection of the elements up-to the end.
Return nil if the stream-end is reached before.

rel5 protocol
o  atEndFile: handle
for migration to rel5 only

o  nextByteFromFile: handle
for migration to rel5 only

o  nextPutByte: aByte toFile: handle
for migration to rel5 only

testing
o  atEnd
return true, if position is at end

o  canReadWithoutBlocking
return true, if any data is available for reading (i.e.
a read operation will not block the smalltalk process), false otherwise.

o  canWriteWithoutBlocking
return true, if data can be written into the stream
(i.e. a write operation will not block the smalltalk process).

o  gotErrorOrEOF
answerv true, if amn error or eof has been occured on the stream

o  nextError
return the error by trying to read something.
Should only be used, when we know, that a read operation
will return an error (otherwise a character may be lost).
Return an integer (error number), 0 (EOF) or nil (no error)

o  numAvailable
return the number of bytes available for reading

waiting for I/O
o  canBeSelected
return true, if this stream can be selected upon

o  readWaitWithTimeoutMs: timeout
suspend the current process, until the receiver
becomes ready for reading or a timeout (in milliseconds) expired.
If data is already available, return immediate.
Return true if a timeout occured (i.e. false, if data is available).
The other threads are not affected by the wait.

o  readWriteWaitWithTimeoutMs: timeout
suspend the current process, until the receiver
becomes ready for reading or writing or a timeout (in milliseconds) expired.
Return true if a timeout occured (i.e. false, if data is available).
Return immediate if the receiver is already ready.
The other threads are not affected by the wait.

o  writeWaitWithTimeoutMs: timeout
suspend the current process, until the receiver
becomes ready for writing or a timeout (in milliseconds) expired.
Return true if a timeout occured (i.e. false, if data is available).
Return immediate if the receiver is already ready.
The other threads are not affected by the wait.

writing
o  cr
append an end-of-line character (or CRLF if in crlf mode).
reimplemented for speed

o  flush
write all buffered data - ignored if unbuffered

o  nextPut: aCharacter
write the argument, aCharacter - return nil if failed, self if ok.
Only single-byte characters are currently supported

o  nextPutAll: aCollection
write all elements of the argument, aCollection.
Reimplemented for speed when writing strings or byteArrays.
For others, falls back to general method in superclass.

o  nextPutAll: aCollection startingAt: start to: stop
write a range of elements of the argument, aCollection.
Reimplemented for speed when writing strings or byteArrays.
For others, falls back to general method in superclass.


Examples:


open a file, read the contents and display it in a textView:


    |topView scrollPane textView fileStream text|

    topView := StandardSystemView new.
    topView label:'contents of Makefile'.

    scrollPane := HVScrollableView in:topView.
    scrollPane origin:0.0@0.0 corner:1.0@1.0.

    textView := EditTextView new.
    scrollPane scrolledView:textView.

    fileStream := 'Makefile' asFilename readStream.
    text := fileStream upToEnd.
    fileStream close.

    textView contents:text.

    topView open.
Notice, all of the above can also be done (simply) as:


    EditTextView openOn:'Makefile'


ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 09:08:04 GMT