Streams and Files Version - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Streams and Files Version

Description:

Copying a DOS file: |fileIn fileOut char ... Copying a DOS file to the window | window char ... A DOS file with comma delimited fields can be read as follows: ... – PowerPoint PPT presentation

Number of Views:70
Avg rating:3.0/5.0
Slides: 14
Provided by: calpoly
Category:
Tags: dos | files | streams | version

less

Transcript and Presenter's Notes

Title: Streams and Files Version


1
Streams and Files Version 2
  • Streams are packets of characters
  • (or other objects)
  • Smalltalk uses streams in
  • files and
  • in windows

2
Streams
  • File Methods
  • input output explanation
  • next nextPut single character
  • nextChunk show multiple characters
  • (strings)
  • upTo
    inputs field up to a

  • a specific character
  • close close must use for files
  • atEnd required for input files

3
CLASS HIERARCY
  • Hierarchy of STREAM classes
  • Object
  • Stream
  • Read Stream
  • WriteStream
  • Hierarchy of FILE classes
  • Object
  • CfsFileStream
  • CfsReadFileStream
  • CfsWriteFileStream

4
Streams
  • Defining a File to write to
  • Use class method called open or openEmpty
  • For example
  • cityFile CfsWriteFileStream
    open'a\file.txt.
  • open message assumes that no file with the name
    already exists
  • Use class method openEmpty to open an existing
    file with the same name
  • note existing file with the same name will be
    erased

5
Streams
  • Copying a DOS file
  • fileIn fileOut char
  • fileIn CfsReadFileStream open
    'c\cis234\cities.txt'.
  • fileOut CfsWriteFileStream open
    c\cis234\citout.txt'.
  • fileIn atEnd
  • whileFalse char fileIn next.
  • fileOut nextPut char.
  • fileIn close.
  • fileOut close

6
Copying a DOS file to the window
  • window char file
  • window EtWorkspace new.
  • window label 'File Window'.
  • window open.
  • file CfsReadFileStream open
    'c\cis234\citout.txt'.
  • file atEnd
  • whileFalse char file next.
  • window nextPut char.
  • file close

7
A DOS file with comma delimited fields can be
read as follows
  • cityFile CfsReadFileStream open
    a\city.txt.
  • cityFile atEnd
  • whileFalse
  • zipCode cityFile upTo ,.
  • stateName cityFile upTo ,.
  • city cityFile upTo cr.
  • cityFile upTo lf.
  • Transcript show (zipCode , , city).
  • inFile close.

8
Streams
  • The cr and lf stand for carriage return and line
    feed
  • These two characters exist at the end of each
    ASCII record
  • To obtain the values for these two characters use
    the following conversions
  • lf 10 asCharacter
  • cr 13 asCharacter

9
Streams
  • There is a need for permanent storage of any
    Smalltalk object.
  • There are two ways to do this
  • 1. ASCII form .sto (stored objects)
  • 2. Binary form .obj (filed objects)
  • For a beginning student the ASCII form is
    desirable

10
Streams
  • Thus it is possible to store and restore object
    contents easily
  • This facilitates transporting objects between
    computer systems

11
Streams
  • Any object can be quickly stored in ASCII format
    on disk using
  • array (Honda Toyota Saturn).
  • arrayFile CfsWriteFileStream
    openEmpty 'c\array.sto'.
  • array storeOn arrayFile.
  • arrayFile close.

12
Streams
  • Any object can be quickly restored on disk using
  • array nil.
  • arrayFile CfsReadFileStream open
    'c\array.sto'.
  • array Compiler evaluate
  • arrayFile contents.
  • arrayFile close.
  • array inspect.

13
Streams
  • Summary
  • Smalltalk Programmers can store objects to files
    to save their contents for later use
  • ASCII files are mainly used to communicate to
    other applications
Write a Comment
User Comments (0)
About PowerShow.com