eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'EncodedStream':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: EncodedStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--PeekableStream
         |
         +--EncodedStream

Package:
stx:libbasic
Category:
Collections-Text-Encodings
Version:
rev: 1.54 date: 2018/01/19 13:44:53
user: stefan
file: EncodedStream.st directory: libbasic
module: stx stc-classLibrary: libbasic

Description:


a stream which transparently decodes from an external decoding,
looking for '{ Encoding: xxx' near the beginning of the file.

especially targeted towards reading ST/X source files.


Class protocol:

Compatibility-VW5.4
o  on: aStream encodedBy: aStreamEncoder

instance creation
o  stream: streamArg encoder: encoder
|s|
s := EncodedStream stream:Transcript encoder:(CharacterEncoder encoderToEncodeFrom:#utf8 into:#unicode).
s nextPutAll:('öäü' utf8Encoded)

|s|
s := EncodedStream stream:('öäü' readStream) encoder:(CharacterEncoder encoderToEncodeFrom:#utf8 into:#unicode).
s next:3

o  stream: streamArg encoding: encodingSymbol
|baseStream s|
baseStream := '' readWriteStream.
s := EncodedStream stream:baseStream encoding:#utf8.
s nextPutAll:'öäü'.
baseStream reset; contents.

s contents

utilities
o  decodedStreamFor: aStream
given a positionable stream, guess its encoding (by reading the
first few lines, looking for a string with an encoding hint,
and return an appropriate encoded string, which does the decoding
on the fly. Used mostly to read UTF8 files (source code)

o  encoderFor: anEncodingSymbol


Instance protocol:

Compatibility-VW5.4
o  on: aStream encodedBy: aStreamEncoder
Initialize the receiver on aStream with aStreamEncoder.

accessing
o  encoder

o  encoder: something

o  encoding

o  inputStream

o  lineNumber
the linenumber doesn't change when characters are decoded

o  pathName
if our base stream has a pathname, delegate...

o  readStream
read from self

o  stream

o  stream: something

chunk input/output
o  nextChunk
as a side effect, check for an encoding chunk

queries
o  contentsSpecies
(comment from inherited method)
this should return the class of which an instance is
returned by the #contents method. Here, Array is returned,
since the abstract Stream-class has no idea of the underlying
collection class.
It is redefined in some subclasses - for example, to return String.

o  isEncoderFor: encodingString

stream protocol
o  atEnd
(comment from inherited method)
return true if the end of the stream has been reached;
- we do not know here how to do it, it must be redefined in subclass

o  close
(comment from inherited method)
close the stream - nothing done here.
Added for compatibility with external streams.

o  collection
return the underlying container; nil, if there is none (eg. external streams).
Here we return nil, as the underlying collection (if any) is useless to the outside world

o  contents
decoder may decide to return nil from #next, even though the

o  emphasis: anObject
(comment from inherited method)
ignored here
- allows Streams to be used interchangable with text streams

o  flush
(comment from inherited method)
write out all unbuffered data - ignored here, but added
to make internalStreams protocol compatible with externalStreams

o  isEmpty
(comment from inherited method)
return true, if the contents of the stream is empty

o  next
(comment from inherited method)
return the next element of the stream
- we do not know here how to do it, it must be redefined in subclass

o  next: nCharactersToRead
(comment from inherited method)
return the next count elements of the stream as aCollection,
which depends on the streams type - (see #contentsSpecies).

o  nextPut: aCharacter
(comment from inherited method)
put the argument, anObject onto the receiver
- we do not know here how to do it, it must be redefined in subclass

o  nextPutAll: aCollection

o  nextPutAll: aCollection startingAt: start to: stop

o  peek
(comment from inherited method)
return the next element of the stream without advancing (i.e.
the following send of next will return this element again.)
- we do not know here how to do it, it must be redefined in subclass

o  position
only use #position/#position: to restore a previous position.
Computing relative positions does not work!
usage example(s):
#position: nils peekChar - make sure, that it positions before peekChar

o  position0Based
to be obsoleted - use position

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

o  position0Based: newPosition
to be obsoleted - use position

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

o  position1Based
to be obsoleted - use position

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

o  position1Based: newPosition
to be obsoleted - use position

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

o  position: newPosition
only use #position/#position: to restore a previous position.
Computing relative positions does not work!
Use #skip: to advance forward.

o  reset

o  setToEnd
Modified (comment): / 09-01-2018 / 17:50:27 / stefan

o  size
not always correct, but probably better than 0.
Better use #isEmpty.
usage example(s):
self error:'size of input is unknown (due to decoding)'

o  sync

o  syncData

testing
o  isEncodedStream
(comment from inherited method)
true, iff this is an encoder/decoder stream

o  isOpen
for compatibility with externalStream:
return true, if this stream is open.

o  isPositionable
(comment from inherited method)
return true, if the stream supports positioning (some do not).
Since this is an abstract class, false is returned here - just to make certain.

o  isReadable

o  isWritable

utilities
o  skipEncodingChunk
if this is a valid chunk (i.e. not a comment or encoding-directive),



ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Wed, 19 Sep 2018 12:56:17 GMT