BaseNCoder.st
author Stefan Vogel <sv@exept.de>
Tue, 22 Mar 2016 18:31:38 +0100
changeset 3764 1352adead5b5
parent 3761 43af86dd75ca
child 4278 939053637e6b
permissions -rw-r--r--
#REFACTORING class: BaseNCoder added: #nextPutBytes: changed:6 methods category of: #nextPut: #nextPutByte:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     1
"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2002 by eXept Software AG
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     4
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    10
 hereby transferred.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    11
"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    13
3548
5424405a96ed initialization done lazily (to speed up startup)
Claus Gittinger <cg@exept.de>
parents: 2638
diff changeset
    14
"{ NameSpace: Smalltalk }"
5424405a96ed initialization done lazily (to speed up startup)
Claus Gittinger <cg@exept.de>
parents: 2638
diff changeset
    15
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    16
ObjectCoder subclass:#BaseNCoder
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:'buffer bits charCount peekByte atEnd lineLimit'
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    20
	category:'System-Storage'
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    21
!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    22
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    23
!BaseNCoder class methodsFor:'documentation'!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    24
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    25
copyright
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    26
"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 2002 by eXept Software AG
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    29
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    35
 hereby transferred.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    36
"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    37
!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    38
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    39
documentation
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    40
"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    41
    Abstract superclass of Base64Coder and Base32Coder
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    42
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    43
    [author:]
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    44
        Stefan Vogel (stefan@zwerg)
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    45
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    46
    [instance variables:]
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    47
        buffer          SmallInteger   buffered data
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    48
        bits            SmallInteger   Number of valid bits in buffer
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    49
        charCount       SmallInteger   Number of characters since last cr
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    50
        atEnd           Boolean        true if end of Base64 string reached
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    51
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    52
    [class variables:]
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    53
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    54
    [see also:]
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    55
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    56
"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    57
! !
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    58
3548
5424405a96ed initialization done lazily (to speed up startup)
Claus Gittinger <cg@exept.de>
parents: 2638
diff changeset
    59
!BaseNCoder class methodsFor:'initialization'!
5424405a96ed initialization done lazily (to speed up startup)
Claus Gittinger <cg@exept.de>
parents: 2638
diff changeset
    60
5424405a96ed initialization done lazily (to speed up startup)
Claus Gittinger <cg@exept.de>
parents: 2638
diff changeset
    61
initializeMappings
5424405a96ed initialization done lazily (to speed up startup)
Claus Gittinger <cg@exept.de>
parents: 2638
diff changeset
    62
    self subclassResponsibility
5424405a96ed initialization done lazily (to speed up startup)
Claus Gittinger <cg@exept.de>
parents: 2638
diff changeset
    63
! !
5424405a96ed initialization done lazily (to speed up startup)
Claus Gittinger <cg@exept.de>
parents: 2638
diff changeset
    64
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    65
!BaseNCoder class methodsFor:'instance creation'!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    66
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    67
new
3548
5424405a96ed initialization done lazily (to speed up startup)
Claus Gittinger <cg@exept.de>
parents: 2638
diff changeset
    68
   self initializeMappings.
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    69
   ^ self basicNew initialize
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    70
! !
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    71
2090
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
    72
!BaseNCoder class methodsFor:'decoding'!
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
    73
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
    74
decodeAsString:encodedString
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
    75
    "decode a base-n encoded string.
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
    76
     We already expect a string instead of a ByteArray"
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
    77
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
    78
    ^ (self on:encodedString readStream) stringUpToEnd
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
    79
! !
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
    80
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    81
!BaseNCoder methodsFor:'accessing'!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    82
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    83
lineLimit:something
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    84
    "set the line length of the encoded output.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    85
     Default is a line length of 76 characters.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    86
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    87
     If nil, no line breaks will be done."
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    88
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    89
    lineLimit := something.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    90
! !
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    91
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    92
!BaseNCoder methodsFor:'decoding'!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    93
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    94
next
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    95
    "answer the next decoded byte"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    96
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    97
    |b|
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    98
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    99
    peekByte notNil ifTrue:[
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   100
        b := peekByte.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   101
        peekByte := nil.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   102
        ^ b
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   103
    ].
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   104
    ^ self basicNext.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   105
!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   106
2638
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   107
next:count
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   108
    "return the next count bytes of the stream as ByteArray"
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   109
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   110
    |answerStream 
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   111
     cnt  "{ Class: SmallInteger }" |
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   112
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   113
    cnt := count.
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   114
    answerStream := WriteStream on:(ByteArray new:cnt).
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   115
    answerStream signalAtEnd:true.
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   116
    1 to:cnt do:[:index |
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   117
        |next|
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   118
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   119
        next := self next.
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   120
        next isNil ifTrue:[
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   121
            "if next did not raise EndOfStreamError, we have to do it"
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   122
            EndOfStreamError raiseRequestFrom:self.
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   123
            "if you proceed, you get what we have already collected"
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   124
            ^ answerStream contents
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   125
        ].
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   126
        answerStream nextPut:next.
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   127
    ].
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   128
    ^ answerStream contents
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   129
!
cde8f8841e60 added: #next:
Stefan Vogel <sv@exept.de>
parents: 2160
diff changeset
   130
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   131
peek
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   132
    "answer the next decoded byte. Do not consume this byte"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   133
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   134
    peekByte isNil ifTrue:[
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   135
        peekByte := self basicNext.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   136
    ].
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   137
    ^ peekByte
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   138
! !
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   139
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   140
!BaseNCoder methodsFor:'encoding'!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   141
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   142
visitByteArray:aByteArray with:aParameter 
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   143
    ^ self
3764
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   144
        nextPutBytes:aByteArray;
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   145
        flush.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   146
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   147
    "
3764
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   148
      Base64Coder encodingOf:#[1 2 3 4 5 6 255]
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   149
    "
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   150
!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   151
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   152
visitObject:anObject with:aParameter
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   153
    "not defined. Use nextPut or nextPutAll:.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   154
     Could encode the printString here"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   155
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   156
    ^ self shouldNotImplement
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   157
!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   158
2160
554dbbd8cfce new: #visitStream:with:
Stefan Vogel <sv@exept.de>
parents: 2090
diff changeset
   159
visitStream:aStream with:aParameter
3764
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   160
    aStream copyToEndInto:self.
2160
554dbbd8cfce new: #visitStream:with:
Stefan Vogel <sv@exept.de>
parents: 2090
diff changeset
   161
    self flush.
554dbbd8cfce new: #visitStream:with:
Stefan Vogel <sv@exept.de>
parents: 2090
diff changeset
   162
554dbbd8cfce new: #visitStream:with:
Stefan Vogel <sv@exept.de>
parents: 2090
diff changeset
   163
    "
554dbbd8cfce new: #visitStream:with:
Stefan Vogel <sv@exept.de>
parents: 2090
diff changeset
   164
      Base64Coder encodingOf:#[1 2 3 4 5 6 255]
554dbbd8cfce new: #visitStream:with:
Stefan Vogel <sv@exept.de>
parents: 2090
diff changeset
   165
      Base64Coder encodingOf:#[1 2 3 4 5 6 255] readStream
554dbbd8cfce new: #visitStream:with:
Stefan Vogel <sv@exept.de>
parents: 2090
diff changeset
   166
    "
554dbbd8cfce new: #visitStream:with:
Stefan Vogel <sv@exept.de>
parents: 2090
diff changeset
   167
!
554dbbd8cfce new: #visitStream:with:
Stefan Vogel <sv@exept.de>
parents: 2090
diff changeset
   168
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   169
visitString:aString with:aParameter 
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   170
    ^ self
3764
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   171
        nextPutAll:aString;
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   172
        flush.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   173
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   174
    "
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   175
      |encoded decoded decoder|
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   176
3764
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   177
      encoded := Base64Coder encode:'hello world'.  
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   178
      decoded := #[] writeStream.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   179
      decoder := Base64Coder on:encoded readStream.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   180
      [decoder atEnd] whileFalse:[
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   181
          decoded nextPut:(decoder next).
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   182
      ].
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   183
      decoded := decoded contents.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   184
      decoded asString.    
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   185
    "
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   186
! !
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   187
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   188
!BaseNCoder methodsFor:'initialization'!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   189
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   190
emptyWriteStream
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   191
    "answer an empty stream. We encode as string"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   192
    
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   193
    ^ WriteStream on:(String new:64)
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   194
!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   195
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   196
initialize
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   197
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   198
    buffer := bits := charCount := 0.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   199
    lineLimit := 76.   "RFC 2045 says: max 76 characters in one line"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   200
    atEnd := false.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   201
! !
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   202
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   203
!BaseNCoder methodsFor:'misc'!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   204
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   205
reset
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   206
    "reset to initial state"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   207
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   208
    super reset.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   209
    buffer := bits := charCount := 0.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   210
    atEnd := false.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   211
    peekByte := nil.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   212
! !
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   213
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   214
!BaseNCoder methodsFor:'private'!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   215
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   216
basicNext
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   217
    "answer the next decoded byte. 
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   218
     No peekByte handling is done here."
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   219
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   220
    |b|
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   221
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   222
    bits == 0 ifTrue:[
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   223
        self fillBuffer.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   224
        bits == 0 ifTrue:[
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   225
            ^ stream pastEndRead.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   226
        ]
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   227
    ].
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   228
    b := (buffer bitShift:(8 - bits)) bitAnd:16rFF.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   229
    bits := bits - 8.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   230
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   231
    ^ b.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   232
! !
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   233
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   234
!BaseNCoder methodsFor:'queries'!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   235
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   236
atEnd
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   237
    "answer true, if no more bytes can be read"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   238
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   239
    bits == 0 ifTrue:[
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   240
        atEnd ifTrue:[^ true].
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   241
        self fillBuffer.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   242
        bits == 0 ifTrue:[^ true].
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   243
    ].
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   244
    ^ false.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   245
!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   246
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   247
binary
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   248
    "switch to binary mode - nothing is done here.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   249
     Defined for compatibility with ExternalStream."
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   250
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   251
    ^ self
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   252
!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   253
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   254
isStream
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   255
    "we simulate a stream"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   256
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   257
    ^ true
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   258
! !
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   259
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   260
!BaseNCoder methodsFor:'stream compatibility'!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   261
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   262
nextBytesInto:anObject startingAt:offset
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   263
    "copy bytes into anObject starting at offset"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   264
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   265
    |off|
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   266
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   267
    off := offset.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   268
    [self atEnd] whileFalse:[
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   269
        anObject at:off put:self next.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   270
        off := off + 1.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   271
    ].
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   272
    ^ off - offset
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   273
!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   274
3764
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   275
nextPut:aByte
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   276
    "encode aByte on the output stream"
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   277
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   278
    ^ self nextPutByte:aByte asInteger.
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   279
!
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   280
3760
bc6b4bb97572 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3548
diff changeset
   281
nextPutAll:aCollection startingAt:first to:last
bc6b4bb97572 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3548
diff changeset
   282
    "append the elements with index from first to last
3761
43af86dd75ca #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3760
diff changeset
   283
     of the argument, aCollection onto the receiver."
3760
bc6b4bb97572 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3548
diff changeset
   284
bc6b4bb97572 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3548
diff changeset
   285
    aCollection from:first to:last do:[:element |
3764
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   286
        self nextPutByte:element
3760
bc6b4bb97572 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3548
diff changeset
   287
    ].
bc6b4bb97572 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3548
diff changeset
   288
    ^ aCollection
bc6b4bb97572 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3548
diff changeset
   289
!
bc6b4bb97572 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3548
diff changeset
   290
3764
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   291
nextPutBytes:aCollectionOfBytes
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   292
    "encode all objects from the argument"
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   293
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   294
    aCollectionOfBytes do:[:o |
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   295
        self nextPutByte:o
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   296
    ]
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   297
!
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   298
2090
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   299
stringUpToEnd
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   300
    "return a collection of the elements up-to the end"
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   301
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   302
    |answerStream|
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   303
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   304
    answerStream := WriteStream on:(String new:128).
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   305
    peekByte notNil ifTrue:[
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   306
        answerStream nextPut:(Character codePoint:peekByte).
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   307
        peekByte := nil.
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   308
    ].
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   309
    [
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   310
        [bits >= 8] whileTrue:[
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   311
            answerStream nextPut:(Character codePoint:((buffer bitShift:(8 - bits)) bitAnd:16rFF)).
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   312
            bits := bits - 8.
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   313
        ].
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   314
        atEnd ifTrue:[
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   315
            bits ~~ 0 ifTrue:[
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   316
                answerStream nextPut:(Character codePoint:(buffer bitAnd:16rFF)).
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   317
                bits := 0.
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   318
            ]
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   319
        ] ifFalse:[
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   320
            self fillBuffer.
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   321
        ].
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   322
    ] doWhile:[bits > 0].
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   323
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   324
    ^ answerStream contents
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   325
!
4b87ce97bb6a New: #decodeAsString:
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   326
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   327
upToEnd
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   328
    "return a collection of the elements up-to the end"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   329
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   330
    |answerStream|
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   331
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   332
    answerStream := WriteStream on:(ByteArray new:128).
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   333
    peekByte notNil ifTrue:[
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   334
        answerStream nextPut:peekByte.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   335
        peekByte := nil.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   336
    ].
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   337
    [
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   338
        [bits >= 8] whileTrue:[
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   339
            answerStream nextPut:((buffer bitShift:(8 - bits)) bitAnd:16rFF).
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   340
            bits := bits - 8.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   341
        ].
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   342
        atEnd ifTrue:[
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   343
            bits ~~ 0 ifTrue:[
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   344
                answerStream nextPut:(buffer bitAnd:16rFF).
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   345
                bits := 0.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   346
            ]
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   347
        ] ifFalse:[
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   348
            self fillBuffer.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   349
        ].
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   350
    ] doWhile:[bits > 0].
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   351
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   352
    ^ answerStream contents
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   353
! !
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   354
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   355
!BaseNCoder methodsFor:'subclass responsibility'!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   356
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   357
fillBuffer
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   358
    "fill buffer with next n characters each representing m bits"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   359
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   360
    ^ self subclassResponsibility.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   361
!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   362
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   363
flush
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   364
    "flush the remaining bits of buffer. 
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   365
     The number of bits in buffer is not a multiple of m, so we pad
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   366
     the buffer and signal that padding has been done via $= characters."
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   367
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   368
    ^ self subclassResponsibility.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   369
!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   370
3764
1352adead5b5 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3761
diff changeset
   371
nextPutByte:aByte
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   372
    "encode aByte on the output stream"
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   373
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   374
    ^ self subclassResponsibility.
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   375
! !
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   376
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   377
!BaseNCoder class methodsFor:'documentation'!
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   378
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   379
version
3760
bc6b4bb97572 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3548
diff changeset
   380
    ^ '$Header$'
3761
43af86dd75ca #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3760
diff changeset
   381
!
43af86dd75ca #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3760
diff changeset
   382
43af86dd75ca #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3760
diff changeset
   383
version_CVS
43af86dd75ca #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3760
diff changeset
   384
    ^ '$Header$'
1965
a0fd03c22adb initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   385
! !
3548
5424405a96ed initialization done lazily (to speed up startup)
Claus Gittinger <cg@exept.de>
parents: 2638
diff changeset
   386