SlideShare ist ein Scribd-Unternehmen logo
1 von 13
S.Ducasse 1
QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.
Stéphane Ducasse
Stephane.Ducasse@univ-savoie.fr
http://www.listic.univ-savoie.fr/~ducasse/
Streams
S.Ducasse 2
License: CC-Attribution-ShareAlike 2.0
http://creativecommons.org/licenses/by-sa/2.0/
S.Ducasse 3
• Allows the traversal of a collection
• Associated with a collection
• If the collection is a Smalltalk collection: InternalStream
• If the collection is a file or an object that behaves like a
collection: ExternalStream
• Stores the current position
Stream (abstract)
PeekableStream (abstract)
PositionableStream (abstract)
ExternalStream
ExternalReadStream
ExternalReadAppendStream
ExternalReadWriteStream
ExternalWriteStream
InternalStream
ReadStream
WriteStream
ReadWriteStream
Streams
S.Ducasse 4
|st|
st := ReadWriteStream on: (Array new: 6).
st nextPut: 1.
st nextPutAll: (4 8 2 6 7).
st contents. PrIt-> (1 4 8 2 6 7)
st reset.
st next. -> 1
st position: 3.
st next. -> 2
st := (1 2 5 3 7) readStream.
st next. -> 1
Example
S.Ducasse 5
Object>>printString
"Answer a String whose characters are a description of the
receiver."
| aStream |
aStream := WriteStream on: (String new: 16).
self printOn: aStream.
^aStream contents
printString, printOn:
S.Ducasse 6
printOn:
Node>>printOn: aStream
super printOn: aStream.
aStream nextPutAll: ' with name:'; print: self name.
self hasNextNode ifTrue: [
aStream nextPutAll: ' and next node:'; print: self nextNode
name]
S.Ducasse 7
Stream
next returns the next element
next: n returns the n next elements
contents returns all the elements
nextPut: anElement inserts anElement at the next
position
nextPutAll: aCollection inserts the collection element
from the next position
atEnd returns true if at the end of the collection
Stream Classes
S.Ducasse 8
PeekableStream:Access to the current without passing to
the next
peek
skipFor: anArgument
skip: n increases the position of n
skipUpTo: anElement increases the position after
anElement
on: aCollection, creates a stream
on: aCol from: firstIndex to: lastIndex (index elements
included)
Stream Classes (ii)
S.Ducasse 9
PositionableStream
skipToAll: throughAll: upToAll:
position
position: anInteger
reset setToEnd isEmpty
InternalStream
size returns the size of the internal collection
Creation: method with: (without reinitializing the stream)
Stream Classes (iii)
S.Ducasse 10
Transcript is a TextCollector that has aStream
TextCollector>>show: aString
self nextPutAll: aString.
self endEntry
endEntry via dependencies asks for refreshing the
window. If you want to speed up a slow trace, use
nextPutAll: + endEntry instead of show:
|st sc|
st := ReadStream on:‘we are the champions’.
sc := Scanner new on: st.
[st atEnd] whileFalse: [ Transcript nextPutAll: sc scanToken,‘ * ‘].
Transcript endEntry
Stream Tricks
S.Ducasse 11
How to ensure that the open files are closed
MyClass>>readFile: aFilename
|readStream|
readStream := aFilename readStream.
[[readStream atEnd] whileFalse: [....]]
valueNowOrOnUnwindDo: [readStream close]
How to find open files (VW specific)
(ExternalStream classPool at: OpenStreams) copy inspect
Streams, Blocks, and Files
S.Ducasse 12
Filename
appendStream (addition + creation if file doesnot exists)
newReadAppendStream, newReadWriteStream (if
receiver exists, contents removed)
readAppendStream, readWriteStream, readStream,
writeStream
Streams, Blocks, and Files (ii)
S.Ducasse 13
Removing Smalltalk comments from a file
|inStream outStream |
inStream := (Filename named:‘/home/ducasse/test.st’) readStream.
outStream := (Filename named:‘/home/ducasse/testout.st’) writeStream.
“(or ‘/home/ducasse/ducasse’ asFilename)”
[inStream atEnd] whileFalse:
[outStream nextPutAll: (inStream upTo: $”).
inStream skipTo: $”].
^outStream contents
“do not forget to close the files too”

Weitere ähnliche Inhalte

Was ist angesagt?

Chapter21 separate-header-and-implementation-files
Chapter21 separate-header-and-implementation-filesChapter21 separate-header-and-implementation-files
Chapter21 separate-header-and-implementation-files
Deepak Singh
 
Memory manament in C
Memory manament in CMemory manament in C
Memory manament in C
Vu Dang Ngoc
 
37562259 top-consuming-process
37562259 top-consuming-process37562259 top-consuming-process
37562259 top-consuming-process
skumner
 
Statim, time series interface for Perl.
Statim, time series interface for Perl.Statim, time series interface for Perl.
Statim, time series interface for Perl.
Thiago Rondon
 
Ns 3 installation procedure
Ns 3 installation procedureNs 3 installation procedure
Ns 3 installation procedure
Vinayak Antin
 

Was ist angesagt? (20)

Chapter21 separate-header-and-implementation-files
Chapter21 separate-header-and-implementation-filesChapter21 separate-header-and-implementation-files
Chapter21 separate-header-and-implementation-files
 
Memory manament in C
Memory manament in CMemory manament in C
Memory manament in C
 
Note
NoteNote
Note
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by example
 
Flux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul Dix
 
Fundamental of Shell Programming
Fundamental of Shell ProgrammingFundamental of Shell Programming
Fundamental of Shell Programming
 
Juju - Google Go in a scalable Environment
Juju - Google Go in a scalable EnvironmentJuju - Google Go in a scalable Environment
Juju - Google Go in a scalable Environment
 
37562259 top-consuming-process
37562259 top-consuming-process37562259 top-consuming-process
37562259 top-consuming-process
 
Improving go-git performance
Improving go-git performanceImproving go-git performance
Improving go-git performance
 
Go on!
Go on!Go on!
Go on!
 
"Metrics: Where and How", Vsevolod Polyakov
"Metrics: Where and How", Vsevolod Polyakov"Metrics: Where and How", Vsevolod Polyakov
"Metrics: Where and How", Vsevolod Polyakov
 
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
 
Kronos : A DSL for scheduled tasks based on textX
Kronos : A DSL for scheduled tasks based on textXKronos : A DSL for scheduled tasks based on textX
Kronos : A DSL for scheduled tasks based on textX
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Statim, time series interface for Perl.
Statim, time series interface for Perl.Statim, time series interface for Perl.
Statim, time series interface for Perl.
 
Storm introduction
Storm introductionStorm introduction
Storm introduction
 
File io
File io File io
File io
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
Ns 3 installation procedure
Ns 3 installation procedureNs 3 installation procedure
Ns 3 installation procedure
 
Using zone.js
Using zone.jsUsing zone.js
Using zone.js
 

Andere mochten auch (20)

11 bytecode
11 bytecode11 bytecode
11 bytecode
 
Stoop 450-s unit
Stoop 450-s unitStoop 450-s unit
Stoop 450-s unit
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
8 - OOP - Smalltalk Model
8 - OOP - Smalltalk Model8 - OOP - Smalltalk Model
8 - OOP - Smalltalk Model
 
Stoop 423-some designpatterns
Stoop 423-some designpatternsStoop 423-some designpatterns
Stoop 423-some designpatterns
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
Stoop 305-reflective programming5
Stoop 305-reflective programming5Stoop 305-reflective programming5
Stoop 305-reflective programming5
 
Stoop 400 o-metaclassonly
Stoop 400 o-metaclassonlyStoop 400 o-metaclassonly
Stoop 400 o-metaclassonly
 
Stoop 416-lsp
Stoop 416-lspStoop 416-lsp
Stoop 416-lsp
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
Stoop 300-block optimizationinvw
Stoop 300-block optimizationinvwStoop 300-block optimizationinvw
Stoop 300-block optimizationinvw
 
Stoop 301-internal objectstructureinvw
Stoop 301-internal objectstructureinvwStoop 301-internal objectstructureinvw
Stoop 301-internal objectstructureinvw
 
Stoop 423-smalltalk idioms
Stoop 423-smalltalk idiomsStoop 423-smalltalk idioms
Stoop 423-smalltalk idioms
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
11 - OOP - Numbers
11 - OOP - Numbers11 - OOP - Numbers
11 - OOP - Numbers
 
Stoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesignStoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesign
 
Stoop 433-chain
Stoop 433-chainStoop 433-chain
Stoop 433-chain
 

Ähnlich wie 15 - Streams

Dockers Containers in action Slide 0 to hero
Dockers Containers in action Slide  0 to heroDockers Containers in action Slide  0 to hero
Dockers Containers in action Slide 0 to hero
TayyabAslam24
 
Chris Swan ONUG Academy - Container Networks Tutorial
Chris Swan ONUG Academy - Container Networks TutorialChris Swan ONUG Academy - Container Networks Tutorial
Chris Swan ONUG Academy - Container Networks Tutorial
Cohesive Networks
 

Ähnlich wie 15 - Streams (20)

containerD
containerDcontainerD
containerD
 
Augmenta Contribution guide
Augmenta Contribution guideAugmenta Contribution guide
Augmenta Contribution guide
 
Infinit filesystem, Reactor reloaded
Infinit filesystem, Reactor reloadedInfinit filesystem, Reactor reloaded
Infinit filesystem, Reactor reloaded
 
RxJava Applied
RxJava AppliedRxJava Applied
RxJava Applied
 
An intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSAn intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECS
 
Csp scala wixmeetup2016
Csp scala wixmeetup2016Csp scala wixmeetup2016
Csp scala wixmeetup2016
 
Docker Starter Pack
Docker Starter PackDocker Starter Pack
Docker Starter Pack
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Dockers Containers in action Slide 0 to hero
Dockers Containers in action Slide  0 to heroDockers Containers in action Slide  0 to hero
Dockers Containers in action Slide 0 to hero
 
Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2
 
Shifter: Containers in HPC Environments
Shifter: Containers in HPC EnvironmentsShifter: Containers in HPC Environments
Shifter: Containers in HPC Environments
 
containerd summit - Deep Dive into containerd
containerd summit - Deep Dive into containerdcontainerd summit - Deep Dive into containerd
containerd summit - Deep Dive into containerd
 
Aplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackAplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e Jetpack
 
Chris Swan ONUG Academy - Container Networks Tutorial
Chris Swan ONUG Academy - Container Networks TutorialChris Swan ONUG Academy - Container Networks Tutorial
Chris Swan ONUG Academy - Container Networks Tutorial
 
IMaRS - Incremental Materialization for RDF Streams (SR4LD2013)
IMaRS - Incremental Materialization for RDF Streams (SR4LD2013)IMaRS - Incremental Materialization for RDF Streams (SR4LD2013)
IMaRS - Incremental Materialization for RDF Streams (SR4LD2013)
 
Docker Workshop
Docker WorkshopDocker Workshop
Docker Workshop
 
Docker and the Container Ecosystem
Docker and the Container EcosystemDocker and the Container Ecosystem
Docker and the Container Ecosystem
 
Foss manual (1)
Foss manual (1)Foss manual (1)
Foss manual (1)
 
Reactive Streams 1.0 and Akka Streams
Reactive Streams 1.0 and Akka StreamsReactive Streams 1.0 and Akka Streams
Reactive Streams 1.0 and Akka Streams
 
Learning spark ch10 - Spark Streaming
Learning spark ch10 - Spark StreamingLearning spark ch10 - Spark Streaming
Learning spark ch10 - Spark Streaming
 

Mehr von The World of Smalltalk (20)

05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
 
99 questions
99 questions99 questions
99 questions
 
13 traits
13 traits13 traits
13 traits
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
10 reflection
10 reflection10 reflection
10 reflection
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
06 debugging
06 debugging06 debugging
06 debugging
 
05 seaside
05 seaside05 seaside
05 seaside
 
04 idioms
04 idioms04 idioms
04 idioms
 
02 basics
02 basics02 basics
02 basics
 
01 intro
01 intro01 intro
01 intro
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
Stoop sed-sharing ornot
Stoop sed-sharing ornotStoop sed-sharing ornot
Stoop sed-sharing ornot
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
 
Stoop ed-class forreuse
Stoop ed-class forreuseStoop ed-class forreuse
Stoop ed-class forreuse
 

Kürzlich hochgeladen

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Kürzlich hochgeladen (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

15 - Streams

  • 1. S.Ducasse 1 QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture. Stéphane Ducasse Stephane.Ducasse@univ-savoie.fr http://www.listic.univ-savoie.fr/~ducasse/ Streams
  • 2. S.Ducasse 2 License: CC-Attribution-ShareAlike 2.0 http://creativecommons.org/licenses/by-sa/2.0/
  • 3. S.Ducasse 3 • Allows the traversal of a collection • Associated with a collection • If the collection is a Smalltalk collection: InternalStream • If the collection is a file or an object that behaves like a collection: ExternalStream • Stores the current position Stream (abstract) PeekableStream (abstract) PositionableStream (abstract) ExternalStream ExternalReadStream ExternalReadAppendStream ExternalReadWriteStream ExternalWriteStream InternalStream ReadStream WriteStream ReadWriteStream Streams
  • 4. S.Ducasse 4 |st| st := ReadWriteStream on: (Array new: 6). st nextPut: 1. st nextPutAll: (4 8 2 6 7). st contents. PrIt-> (1 4 8 2 6 7) st reset. st next. -> 1 st position: 3. st next. -> 2 st := (1 2 5 3 7) readStream. st next. -> 1 Example
  • 5. S.Ducasse 5 Object>>printString "Answer a String whose characters are a description of the receiver." | aStream | aStream := WriteStream on: (String new: 16). self printOn: aStream. ^aStream contents printString, printOn:
  • 6. S.Ducasse 6 printOn: Node>>printOn: aStream super printOn: aStream. aStream nextPutAll: ' with name:'; print: self name. self hasNextNode ifTrue: [ aStream nextPutAll: ' and next node:'; print: self nextNode name]
  • 7. S.Ducasse 7 Stream next returns the next element next: n returns the n next elements contents returns all the elements nextPut: anElement inserts anElement at the next position nextPutAll: aCollection inserts the collection element from the next position atEnd returns true if at the end of the collection Stream Classes
  • 8. S.Ducasse 8 PeekableStream:Access to the current without passing to the next peek skipFor: anArgument skip: n increases the position of n skipUpTo: anElement increases the position after anElement on: aCollection, creates a stream on: aCol from: firstIndex to: lastIndex (index elements included) Stream Classes (ii)
  • 9. S.Ducasse 9 PositionableStream skipToAll: throughAll: upToAll: position position: anInteger reset setToEnd isEmpty InternalStream size returns the size of the internal collection Creation: method with: (without reinitializing the stream) Stream Classes (iii)
  • 10. S.Ducasse 10 Transcript is a TextCollector that has aStream TextCollector>>show: aString self nextPutAll: aString. self endEntry endEntry via dependencies asks for refreshing the window. If you want to speed up a slow trace, use nextPutAll: + endEntry instead of show: |st sc| st := ReadStream on:‘we are the champions’. sc := Scanner new on: st. [st atEnd] whileFalse: [ Transcript nextPutAll: sc scanToken,‘ * ‘]. Transcript endEntry Stream Tricks
  • 11. S.Ducasse 11 How to ensure that the open files are closed MyClass>>readFile: aFilename |readStream| readStream := aFilename readStream. [[readStream atEnd] whileFalse: [....]] valueNowOrOnUnwindDo: [readStream close] How to find open files (VW specific) (ExternalStream classPool at: OpenStreams) copy inspect Streams, Blocks, and Files
  • 12. S.Ducasse 12 Filename appendStream (addition + creation if file doesnot exists) newReadAppendStream, newReadWriteStream (if receiver exists, contents removed) readAppendStream, readWriteStream, readStream, writeStream Streams, Blocks, and Files (ii)
  • 13. S.Ducasse 13 Removing Smalltalk comments from a file |inStream outStream | inStream := (Filename named:‘/home/ducasse/test.st’) readStream. outStream := (Filename named:‘/home/ducasse/testout.st’) writeStream. “(or ‘/home/ducasse/ducasse’ asFilename)” [inStream atEnd] whileFalse: [outStream nextPutAll: (inStream upTo: $”). inStream skipTo: $”]. ^outStream contents “do not forget to close the files too”