SlideShare una empresa de Scribd logo
1 de 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”

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado (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
 

Similar a 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
 

Similar a 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
 

Más de 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
 

Último

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Último (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
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.
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
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
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 

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”