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