89
|
1 |
"{ Package: 'stx:goodies/xtreams/support' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Xtreams }"
|
|
4 |
|
|
5 |
Encoder subclass:#STXEncoder
|
|
6 |
instanceVariableNames:'encoder stream character contentsSpecies'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Xtreams-Support'
|
|
10 |
!
|
|
11 |
|
|
12 |
STXEncoder comment:'Provides access to all encodings supported by VisualWorks.
|
|
13 |
|
|
14 |
Instance Variables
|
|
15 |
encoder <StreamEncoder> the encoder from classic EncodedStream
|
|
16 |
skipRecord <PositionRecord> the skipRecord of the encoder to allow repeated decoding attempts
|
|
17 |
backupRecord <PositionRecord> snapshot of the skipRecord that we can restore from
|
|
18 |
|
|
19 |
'
|
|
20 |
!
|
|
21 |
|
|
22 |
|
|
23 |
!STXEncoder class methodsFor:'instance creation'!
|
|
24 |
|
|
25 |
encoder: anEncoder
|
|
26 |
|
|
27 |
^self new encoder: anEncoder
|
|
28 |
!
|
|
29 |
|
|
30 |
for: anEncoding
|
|
31 |
|
|
32 |
^self new encoding: anEncoding
|
|
33 |
! !
|
|
34 |
|
|
35 |
!STXEncoder class methodsFor:'class initialization'!
|
|
36 |
|
|
37 |
initialize
|
|
38 |
|
|
39 |
DialectEncoder := self
|
|
40 |
! !
|
|
41 |
|
|
42 |
!STXEncoder methodsFor:'accessing'!
|
|
43 |
|
|
44 |
decodeFrom: aReadStream
|
|
45 |
|
|
46 |
stream := aReadStream.
|
|
47 |
^encoder readNextCharacterFrom: self
|
|
48 |
!
|
|
49 |
|
|
50 |
encode: aCharacter on: aWriteStream
|
|
51 |
|
|
52 |
character := aCharacter.
|
|
53 |
^aWriteStream write: (encoder readNextInputCharacterFrom: self)
|
|
54 |
!
|
|
55 |
|
|
56 |
encoder
|
|
57 |
|
|
58 |
^encoder
|
|
59 |
!
|
|
60 |
|
|
61 |
next: count
|
|
62 |
|
|
63 |
|bytes|
|
|
64 |
|
|
65 |
bytes := ByteArray new: count.
|
|
66 |
character isNil
|
|
67 |
ifTrue: [ stream read: count into: bytes ]
|
|
68 |
ifFalse: [ bytes at: 1 put: character.
|
|
69 |
character := nil.
|
|
70 |
stream read: count - 1 into: bytes at: 2 ].
|
|
71 |
^bytes
|
|
72 |
!
|
|
73 |
|
|
74 |
nextUnsignedShortMSB: bigEndian
|
|
75 |
|
|
76 |
^character codePoint
|
|
77 |
!
|
|
78 |
|
|
79 |
peek
|
|
80 |
|
|
81 |
^character ifNil: [ character := stream get ]
|
|
82 |
! !
|
|
83 |
|
|
84 |
!STXEncoder methodsFor:'initialize-release'!
|
|
85 |
|
|
86 |
encoder: anEncoder
|
|
87 |
|
|
88 |
encoder := anEncoder.
|
|
89 |
contentsSpecies := (anEncoder newString: 1) class.
|
|
90 |
!
|
|
91 |
|
|
92 |
encoding: anEncoding
|
|
93 |
|
|
94 |
| newEncoder |
|
|
95 |
newEncoder := CharacterEncoder encoderFor: anEncoding.
|
|
96 |
newEncoder isNullEncoder ifTrue: [ self error: 'Unsupported encoding!!' ].
|
|
97 |
self encoder: newEncoder
|
|
98 |
! !
|
|
99 |
|
|
100 |
!STXEncoder class methodsFor:'documentation'!
|
|
101 |
|
|
102 |
version_SVN
|
|
103 |
^ '$Id$'
|
|
104 |
! !
|
|
105 |
|
|
106 |
STXEncoder initialize!
|