43
|
1 |
"{ Encoding: utf8 }" !
|
|
2 |
"{ Package: 'stx:goodies/xtreams/terminals' }" !
|
|
3 |
|
|
4 |
!UndefinedObject methodsFor:'converting'!
|
|
5 |
|
|
6 |
writing
|
|
7 |
^Xtreams::NullWriteStream new
|
|
8 |
! !
|
|
9 |
|
52
|
10 |
!PipeStream methodsFor:'converting'!
|
|
11 |
|
|
12 |
reading
|
|
13 |
|
|
14 |
^Xtreams::ExternalReadStream on: self
|
|
15 |
! !
|
|
16 |
|
|
17 |
!PipeStream methodsFor:'converting'!
|
39
|
18 |
|
52
|
19 |
writing
|
|
20 |
|
|
21 |
^Xtreams::ExternalWriteStream on: self
|
|
22 |
! !
|
|
23 |
|
|
24 |
!PipeStream methodsFor:'testing'!
|
|
25 |
|
|
26 |
isActive
|
|
27 |
|
|
28 |
^self isOpen
|
43
|
29 |
! !
|
39
|
30 |
|
43
|
31 |
!Block methodsFor:'xtreams'!
|
39
|
32 |
|
|
33 |
reading
|
|
34 |
self numArgs = 0 ifTrue: [^Xtreams::BlockClosureReadStream on: self].
|
|
35 |
self numArgs = 1 ifTrue: [^Xtreams::BlockClosureGenerateStream on: self].
|
|
36 |
self error: 'More arguments than we can poke a stick at!!'
|
|
37 |
! !
|
43
|
38 |
|
|
39 |
!Block methodsFor:'xtreams'!
|
39
|
40 |
|
|
41 |
writing
|
|
42 |
self numArgs = 1 ifTrue: [^Xtreams::BlockClosureWriteStream on: self].
|
|
43 |
self error: 'Must be a single argument block.'
|
|
44 |
! !
|
|
45 |
|
|
46 |
!Socket methodsFor:'converting'!
|
|
47 |
|
|
48 |
accepting
|
|
49 |
"Return a read stream that produces new sockets from incoming connections."
|
|
50 |
|
|
51 |
"^ ReadStream"
|
|
52 |
|
|
53 |
"Listen for connections and close those connections immediately.
|
|
54 |
| socket |
|
|
55 |
socket := SocketAccessor newTCP.
|
|
56 |
socket listenFor: 1.
|
|
57 |
[socket acceping do: [:client | client close]]
|
|
58 |
ensure: [socket close]
|
|
59 |
"
|
|
60 |
|
|
61 |
^[self accept] reading
|
|
62 |
closeBlock: [self close];
|
|
63 |
yourself
|
|
64 |
! !
|
43
|
65 |
|
39
|
66 |
!Socket methodsFor:'converting'!
|
|
67 |
|
|
68 |
reading
|
43
|
69 |
^Xtreams::ExternalReadStream on: self
|
39
|
70 |
! !
|
43
|
71 |
|
39
|
72 |
!Socket methodsFor:'converting'!
|
|
73 |
|
|
74 |
writing
|
43
|
75 |
^Xtreams::ExternalWriteStream on: self
|
|
76 |
! !
|
|
77 |
|
|
78 |
!SharedQueue methodsFor:'converting'!
|
|
79 |
|
|
80 |
reading
|
|
81 |
^Xtreams::SharedQueueReadStream on: self
|
39
|
82 |
! !
|
43
|
83 |
|
|
84 |
!SharedQueue methodsFor:'converting'!
|
|
85 |
|
|
86 |
writing
|
|
87 |
^Xtreams::SharedQueueWriteStream on: self
|
|
88 |
! !
|
|
89 |
|
|
90 |
!Filename methodsFor:'converting'!
|
|
91 |
|
|
92 |
appending
|
|
93 |
^(OperatingSystem open: self osNameForAccess attributes: #(O_APPEND O_CREAT) mode: nil) writing
|
|
94 |
position: self fileSize;
|
|
95 |
isPositionable: false;
|
|
96 |
yourself
|
39
|
97 |
! !
|
43
|
98 |
|
|
99 |
!Filename methodsFor:'converting'!
|
|
100 |
|
|
101 |
reading
|
|
102 |
self isDirectory ifFalse: [^(OperatingSystem open: self osNameForAccess attributes: #(O_RDONLY) mode: nil) reading].
|
|
103 |
|
|
104 |
"Return the directory contents as a stream of filenames"
|
|
105 |
^([self directoryContents]
|
|
106 |
on: Error
|
|
107 |
do: [:ex | ex return: #()])
|
|
108 |
reading collecting: [:each | self construct: each asFilename]
|
|
109 |
! !
|
|
110 |
|
|
111 |
!Filename methodsFor:'converting'!
|
|
112 |
|
|
113 |
writing
|
|
114 |
^(OperatingSystem open: self osNameForAccess attributes: #(O_WRONLY | O_CREAT) mode: nil) writing
|
|
115 |
! !
|
|
116 |
|
52
|
117 |
!SequenceableCollection methodsFor:'converting'!
|
39
|
118 |
|
|
119 |
reading
|
52
|
120 |
^Xtreams::SequenceableCollectionReadStream on: self
|
39
|
121 |
! !
|
43
|
122 |
|
52
|
123 |
!SequenceableCollection methodsFor:'converting'!
|
39
|
124 |
|
|
125 |
writing
|
52
|
126 |
^Xtreams::SequenceableCollectionWriteStream on: self
|
39
|
127 |
! !
|
43
|
128 |
|
|
129 |
!UnixOperatingSystem::FileDescriptorHandle methodsFor:'xtreams'!
|
|
130 |
|
|
131 |
writing
|
|
132 |
|
|
133 |
^Xtreams::FileWriteStream on: self
|
|
134 |
! !
|
|
135 |
|
|
136 |
!UnixOperatingSystem::FileDescriptorHandle methodsFor:'xtreams'!
|
|
137 |
|
|
138 |
reading
|
|
139 |
|
|
140 |
^Xtreams::FileReadStream on: self
|
|
141 |
! !
|
39
|
142 |
|
43
|
143 |
!Collection methodsFor:'converting'!
|
|
144 |
|
|
145 |
writing
|
|
146 |
^Xtreams::CollectionWriteStream on: self
|
39
|
147 |
! !
|
43
|
148 |
|
52
|
149 |
!Xtreams::Buffer methodsFor:'converting'!
|
|
150 |
|
|
151 |
reading
|
|
152 |
^BufferReadStream on: self
|
|
153 |
! !
|
|
154 |
|
|
155 |
!Xtreams::Buffer methodsFor:'converting'!
|
|
156 |
|
|
157 |
writing
|
|
158 |
^BufferWriteStream on: self
|
|
159 |
! !
|
|
160 |
|
|
161 |
!Xtreams::WriteStream methodsFor:'transforming'!
|
|
162 |
|
|
163 |
buffering: bufferSize
|
|
164 |
"Delays committing its content to its underlying stream until it has reached a certain size ,#flush is sent, or the stream is closed."
|
|
165 |
" bufferSize <Integer> The size of the buffer to start with.
|
|
166 |
^<PositionWriteStream>"
|
|
167 |
"
|
|
168 |
(ByteArray new writing buffering: 5)
|
|
169 |
write: (ByteArray withAll: (1 to: 11));
|
|
170 |
conclusion
|
|
171 |
"
|
|
172 |
^BufferedWriteStream on: self bufferSize: bufferSize
|
|
173 |
! !
|
|
174 |
|
43
|
175 |
!Random methodsFor:'converting'!
|
39
|
176 |
|
43
|
177 |
reading
|
|
178 |
^[self next] reading
|
|
179 |
contentsSpecies: self contentsSpecies;
|
|
180 |
yourself
|
39
|
181 |
! !
|
43
|
182 |
|