Levente Uzonyi uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-ul.97.mcz
==================== Summary ====================
Name: Files-ul.97
Author: ul
Time: 24 January 2011, 3:59:59.143 am
UUID: 6f9985b2-9bce-a145-a3d2-276a76ce1fa7
Ancestors: Files-ul.96
- removed previous stdio support code from StandardFileStream, migration is done in the preamble
=============== Diff against Files-ul.96 ===============
Item was added:
+ (PackageInfo named: 'Files') preamble: '"Migrate stdio handles and files from StandardFileStream to FileStream. Turn off encoding and reuse the streams if they are in use in the image for backwards compatibility."
+ (StandardFileStream classPool at: #StdioHandles) ifNotNil: [ :handleArray |
+ FileStream classPool at: #TheStdioHandles put: handleArray ].
+ (StandardFileStream instVarNamed: #stdioFiles) ifNotNil: [ :stdioFiles |
+ FileStream classPool
+ at: #StdioFiles put: stdioFiles;
+ at: #EncodeAndDecodeStdioFiles put: false ].
+ Smalltalk
+ removeFromStartUpList: StandardFileStream;
+ removeFromShutDownList: StandardFileStream'!
Item was changed:
FileStream subclass: #StandardFileStream
instanceVariableNames: 'name fileID buffer1'
+ classVariableNames: 'Registry'
- classVariableNames: 'Registry StdioHandles'
poolDictionaries: ''
category: 'Files-Kernel'!
- StandardFileStream class
- instanceVariableNames: 'stdioFiles'!
!StandardFileStream commentStamp: 'ul 12/6/2009 05:13' prior: 0!
Provides a simple, platform-independent, interface to a file system. The instance variable rwmode, inherited from class PositionableStream, here is used to hold a Boolean -- true means opened for read-write, false means opened for read-only. 2/12/96 sw
I implement a simple read buffering scheme with the variables defined in PositionableStream (which are unused in me otherwise) in the following way:
collection <ByteString> or <ByteArray> This is the buffer.
position <Integer> The relative position in the buffer. Greater or equal to zero.
readLimit <Integer> The number of bytes buffered. Greater or equal to zero.
Read buffering is enabled with #enableReadBuffering, disabled with #disableReadBuffering and it is enabled by default. The buffer is filled when a read attempt of an unbuffered absolute position is requested, or when a negative repositioning is made (with #position: with an argument < than the current absolute position) to an absolute position which is not buffered. In the first case, the buffer is positioned to the given absolute position. In the latter case the repositioning is made to the requested absolute position minus fourth of the buffer size. This means that further small negative repositionings won't result in buffer flushing. This is really useful when filing in code.
The read buffer is flushed (#flushReadBuffer) whenever a write attempt is made.
The buffer state is valid if and only if collection is not nil and position < readLimit.!
- StandardFileStream class
- instanceVariableNames: 'stdioFiles'!
Item was removed:
- ----- Method: StandardFileStream class>>flushAndVoidStdioFiles (in category 'class initialization') -----
- flushAndVoidStdioFiles
- stdioFiles ifNotNil:
- [stdioFiles do:
- [:f| f ifNotNil: [f isReadOnly ifFalse: [[f flush] on: Error do: [:ex|"care less"]]]].
- stdioFiles := nil]!
Item was removed:
- ----- Method: StandardFileStream class>>initialize (in category 'class initialization') -----
- initialize
- "StandardFileStream initialize"
- StdioHandles := Array new: 3.
- Smalltalk
- addToStartUpList: self after: SecurityManager; "the intent being before: AutoStart"
- addToShutDownList: self after: SecurityManager!
Item was removed:
- ----- Method: StandardFileStream class>>newForStdio (in category 'private-file creation') -----
- newForStdio
- "Circumvent CrLfFileStream new's returning an instance of MultiBteFileStream"
- ^self new!
Item was removed:
- ----- Method: StandardFileStream class>>shutDown: (in category 'class initialization') -----
- shutDown: quitting
- quitting ifTrue:
- [self withAllSubclassesDo:
- [:fileStreamClass| fileStreamClass flushAndVoidStdioFiles]]!
Item was removed:
- ----- Method: StandardFileStream class>>standardIOStreamNamed:forWrite: (in category 'private-file creation') -----
- standardIOStreamNamed: moniker forWrite: forWrite
-
- | index |
- index := #(stdin stdout stderr) identityIndexOf: moniker.
- ^((stdioFiles ifNil: [ stdioFiles := Array new: 3 ]) at: index)
- ifNil: [
- stdioFiles
- at: index
- put: (
- (StdioHandles at: index)
- ifNil: [ ^self error: moniker, ' is unavailable' ]
- ifNotNil: [ :handle|
- self newForStdio
- openOnHandle: handle
- name: moniker
- forWrite: forWrite ]) ]!
Item was removed:
- ----- Method: StandardFileStream class>>startUp: (in category 'class initialization') -----
- startUp: resuming
- (resuming and: [self == StandardFileStream]) ifTrue:
- [self withAllSubclassesDo:
- [:fileStreamClass| fileStreamClass voidStdioFiles].
- [StdioHandles := self stdioHandles]
- on: Error
- do: [:ex|
- StdioHandles isArray ifFalse:
- [StdioHandles := Array new: 3]]]!
Item was removed:
- ----- Method: StandardFileStream class>>stderr (in category 'file creation') -----
- stderr
- ^self standardIOStreamNamed: #stderr forWrite: true!
Item was removed:
- ----- Method: StandardFileStream class>>stdin (in category 'file creation') -----
- stdin
- ^self standardIOStreamNamed: #stdin forWrite: false!
Item was removed:
- ----- Method: StandardFileStream class>>stdioHandles (in category 'private-file creation') -----
- stdioHandles
- <primitive: 'primitiveFileStdioHandles' module: 'FilePlugin' error: ec>
- self primitiveFailed!
Item was removed:
- ----- Method: StandardFileStream class>>stdout (in category 'file creation') -----
- stdout
- ^self standardIOStreamNamed: #stdout forWrite: true!
Item was removed:
- ----- Method: StandardFileStream class>>voidStdioFiles (in category 'class initialization') -----
- voidStdioFiles
- stdioFiles := nil!
Levente Uzonyi uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-ul.97.mcz
==================== Summary ====================
Name: Files-ul.97
Author: ul
Time: 24 January 2011, 3:59:59.143 am
UUID: 6f9985b2-9bce-a145-a3d2-276a76ce1fa7
Ancestors: Files-ul.96
- removed previous stdio support code from StandardFileStream, migration is done in the preamble
=============== Diff against Files-ul.96 ===============
Item was added:
+ (PackageInfo named: 'Files') preamble: '"Migrate stdio handles and files from StandardFileStream to FileStream. Turn off encoding and reuse the streams if they are in use in the image for backwards compatibility."
+ (StandardFileStream classPool at: #StdioHandles) ifNotNil: [ :handleArray |
+ FileStream classPool at: #TheStdioHandles put: handleArray ].
+ (StandardFileStream instVarNamed: #stdioFiles) ifNotNil: [ :stdioFiles |
+ FileStream classPool
+ at: #StdioFiles put: stdioFiles;
+ at: #EncodeAndDecodeStdioFiles put: false ].
+ Smalltalk
+ removeFromStartUpList: StandardFileStream;
+ removeFromShutDownList: StandardFileStream'!
Item was changed:
FileStream subclass: #StandardFileStream
instanceVariableNames: 'name fileID buffer1'
+ classVariableNames: 'Registry'
- classVariableNames: 'Registry StdioHandles'
poolDictionaries: ''
category: 'Files-Kernel'!
- StandardFileStream class
- instanceVariableNames: 'stdioFiles'!
!StandardFileStream commentStamp: 'ul 12/6/2009 05:13' prior: 0!
Provides a simple, platform-independent, interface to a file system. The instance variable rwmode, inherited from class PositionableStream, here is used to hold a Boolean -- true means opened for read-write, false means opened for read-only. 2/12/96 sw
I implement a simple read buffering scheme with the variables defined in PositionableStream (which are unused in me otherwise) in the following way:
collection <ByteString> or <ByteArray> This is the buffer.
position <Integer> The relative position in the buffer. Greater or equal to zero.
readLimit <Integer> The number of bytes buffered. Greater or equal to zero.
Read buffering is enabled with #enableReadBuffering, disabled with #disableReadBuffering and it is enabled by default. The buffer is filled when a read attempt of an unbuffered absolute position is requested, or when a negative repositioning is made (with #position: with an argument < than the current absolute position) to an absolute position which is not buffered. In the first case, the buffer is positioned to the given absolute position. In the latter case the repositioning is made to the requested absolute position minus fourth of the buffer size. This means that further small negative repositionings won't result in buffer flushing. This is really useful when filing in code.
The read buffer is flushed (#flushReadBuffer) whenever a write attempt is made.
The buffer state is valid if and only if collection is not nil and position < readLimit.!
- StandardFileStream class
- instanceVariableNames: 'stdioFiles'!
Item was removed:
- ----- Method: StandardFileStream class>>flushAndVoidStdioFiles (in category 'class initialization') -----
- flushAndVoidStdioFiles
- stdioFiles ifNotNil:
- [stdioFiles do:
- [:f| f ifNotNil: [f isReadOnly ifFalse: [[f flush] on: Error do: [:ex|"care less"]]]].
- stdioFiles := nil]!
Item was removed:
- ----- Method: StandardFileStream class>>initialize (in category 'class initialization') -----
- initialize
- "StandardFileStream initialize"
- StdioHandles := Array new: 3.
- Smalltalk
- addToStartUpList: self after: SecurityManager; "the intent being before: AutoStart"
- addToShutDownList: self after: SecurityManager!
Item was removed:
- ----- Method: StandardFileStream class>>newForStdio (in category 'private-file creation') -----
- newForStdio
- "Circumvent CrLfFileStream new's returning an instance of MultiBteFileStream"
- ^self new!
Item was removed:
- ----- Method: StandardFileStream class>>shutDown: (in category 'class initialization') -----
- shutDown: quitting
- quitting ifTrue:
- [self withAllSubclassesDo:
- [:fileStreamClass| fileStreamClass flushAndVoidStdioFiles]]!
Item was removed:
- ----- Method: StandardFileStream class>>standardIOStreamNamed:forWrite: (in category 'private-file creation') -----
- standardIOStreamNamed: moniker forWrite: forWrite
-
- | index |
- index := #(stdin stdout stderr) identityIndexOf: moniker.
- ^((stdioFiles ifNil: [ stdioFiles := Array new: 3 ]) at: index)
- ifNil: [
- stdioFiles
- at: index
- put: (
- (StdioHandles at: index)
- ifNil: [ ^self error: moniker, ' is unavailable' ]
- ifNotNil: [ :handle|
- self newForStdio
- openOnHandle: handle
- name: moniker
- forWrite: forWrite ]) ]!
Item was removed:
- ----- Method: StandardFileStream class>>startUp: (in category 'class initialization') -----
- startUp: resuming
- (resuming and: [self == StandardFileStream]) ifTrue:
- [self withAllSubclassesDo:
- [:fileStreamClass| fileStreamClass voidStdioFiles].
- [StdioHandles := self stdioHandles]
- on: Error
- do: [:ex|
- StdioHandles isArray ifFalse:
- [StdioHandles := Array new: 3]]]!
Item was removed:
- ----- Method: StandardFileStream class>>stderr (in category 'file creation') -----
- stderr
- ^self standardIOStreamNamed: #stderr forWrite: true!
Item was removed:
- ----- Method: StandardFileStream class>>stdin (in category 'file creation') -----
- stdin
- ^self standardIOStreamNamed: #stdin forWrite: false!
Item was removed:
- ----- Method: StandardFileStream class>>stdioHandles (in category 'private-file creation') -----
- stdioHandles
- <primitive: 'primitiveFileStdioHandles' module: 'FilePlugin' error: ec>
- self primitiveFailed!
Item was removed:
- ----- Method: StandardFileStream class>>stdout (in category 'file creation') -----
- stdout
- ^self standardIOStreamNamed: #stdout forWrite: true!
Item was removed:
- ----- Method: StandardFileStream class>>voidStdioFiles (in category 'class initialization') -----
- voidStdioFiles
- stdioFiles := nil!
Levente Uzonyi uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-ul.96.mcz
==================== Summary ====================
Name: Files-ul.96
Author: ul
Time: 24 January 2011, 3:45:32.858 am
UUID: d06be799-4c77-3b46-aff8-4abc589fafd3
Ancestors: Files-mtf.95
Stdio support changes:
- Added stdio support code to FileStream.
- Unified API for accessing stdio streams. All users should send #stdin, #stdout and #stderr to FileStream to access the streams.
- MultiByteFileStream is used instead of CrLfFileStream.
- CrLfFileStream class >> #new is now deprecated
=============== Diff against Files-mtf.95 ===============
Item was changed:
StandardFileStream subclass: #CrLfFileStream
instanceVariableNames: 'lineEndConvention'
classVariableNames: 'Cr CrLf Lf LineEndDefault LineEndStrings LookAheadCount'
poolDictionaries: ''
category: 'Files-Kernel'!
+ !CrLfFileStream commentStamp: 'ul 12/26/2010 03:13' prior: 0!
+ This class is now obsolete, use MultiByteFileStream instead.
+
- !CrLfFileStream commentStamp: 'ls 11/10/2002 13:32' prior: 0!
I am the same as a regular file stream, except that when I am in text mode, I will automatically convert line endings between the underlying platform's convention, and Squeak's convention of carriage-return only. The goal is that Squeak text files can be treated as OS text files, and vice versa.
In binary mode, I behave identically to a StandardFileStream.
To enable CrLfFileStream as the default file stream class for an entire image, modify FileStream class concreteStream .
There are two caveats on programming with CrLfFileStream.
First, the choice of text mode versus binary mode affects which characters are visible in Squeak, and no longer just affects whether those characters are returned as Character's or as Integer's. Thus the choice of mode needs to be made very carefully, and must be based on intent instead of convenience of representation. The methods asString, asByteArray, asCharacter, and asInteger can be used to convert between character and integer representations. (Arguably, file streams should accept either strings or characters in nextPut: and nextPutAll:, but that is not the case right now.)
Second, arithmetic on positions no longer works, because one character that Squeak sees (carriage return) could map to two characters in the underlying file (carriage return plus line feed, on MS Windows and MS DOS). Comparison between positions still works. (This caveat could perhaps be fixed by maintaining a map between Squeak positions and positions in the underlying file, but it is complicated. Consider, for example, updates to the middle of the file. Also, consider that text files are rarely updated in the middle of the file, and that general random access to a text file is rarely very useful. If general random access with specific file counts is desired, then the file is starting to sound like a binary file instead of a text file.)
!
Item was changed:
----- Method: CrLfFileStream class>>new (in category 'class initialization') -----
new
+ self deprecated: 'This class is now obsolete, use MultiByteFileStream instead.'.
^ (MultiByteFileStream new) wantsLineEndConversion: true; yourself.
!
Item was removed:
- ----- Method: CrLfFileStream class>>newForStdio (in category 'instance creation') -----
- newForStdio
- "Circumvent CrLfFileStream new's retuning an instance of MultiBteFileStream"
- ^super new!
Item was removed:
- ----- Method: CrLfFileStream>>openOnHandle:name:forWrite: (in category 'open/close') -----
- openOnHandle: aFileID name: streamName forWrite: writeMode
- "Initialize the file with the given handle. If writeMode is true then
- allow writing, otherwise put the file in read-only mode."
- super openOnHandle: aFileID name: streamName forWrite: writeMode.
- lineEndConvention := LineEndDefault!
Item was changed:
ReadWriteStream subclass: #FileStream
instanceVariableNames: 'rwmode'
+ classVariableNames: 'EncodeAndDecodeStdioFiles Stderr Stdin StdioFiles Stdout TheStdioHandles'
- classVariableNames: ''
poolDictionaries: ''
category: 'Files-Kernel'!
!FileStream commentStamp: '<historical>' prior: 0!
I represent a Stream that accesses a FilePage from a File. One use for my instance is to access larger "virtual Strings" than can be stored contiguously in main memory. I restrict the objects stored and retrieved to be Integers or Characters. An end of file pointer terminates reading; it can be extended by writing past it, or the file can be explicitly truncated.
To use the file system for most applications, you typically create a FileStream. This is done by sending a message to a FileDirectory (file:, oldFile:, newFile:, rename:newName:) which creates an instance of me. Accesses to the file are then done via my instance.
*** On DOS, files cannot be shortened!! *** To overwrite a file with a shorter one, first delete the old file (FileDirectory deleteFilePath: 'Hard Disk:aFolder:dataFolder:foo') or (aFileDirectory deleteFileNamed: 'foo'). Then write your new shorter version.!
Item was added:
+ ----- Method: FileStream class>>encodeAndDecodeStdioFiles (in category 'stdio') -----
+ encodeAndDecodeStdioFiles
+
+ <preference: 'Encode and decode the contents of stdio files.'
+ category: 'Files'
+ description: 'It true, then the contents of stdin, stdout and stderr are encoded/decoded using the system default text converter.'
+ type: #Boolean>
+ ^EncodeAndDecodeStdioFiles ifNil: [ true ]!
Item was added:
+ ----- Method: FileStream class>>encodeAndDecodeStdioFiles: (in category 'stdio') -----
+ encodeAndDecodeStdioFiles: aBoolean
+
+ EncodeAndDecodeStdioFiles := aBoolean.
+ self updateStdioFiles!
Item was added:
+ ----- Method: FileStream class>>flushAndVoidStdioFiles (in category 'stdio') -----
+ flushAndVoidStdioFiles
+
+ StdioFiles ifNotNil: [
+ StdioFiles do: [ :file |
+ file ifNotNil: [
+ file isReadOnly ifFalse: [
+ [ file flush ]
+ on: Error
+ do: [ :ex | "care less" ] ] ] ].
+ self voidStdioFiles ]!
Item was changed:
----- Method: FileStream class>>initialize (in category 'initialize-release') -----
initialize
+ FileServices registerFileReader: self.
+ EncodeAndDecodeStdioFiles := true.
+ TheStdioHandles := Array new: 3.
+ Smalltalk
+ addToStartUpList: self after: SecurityManager; "the intent being before: AutoStart"
+ addToShutDownList: self after: SecurityManager!
- FileServices registerFileReader: self!
Item was added:
+ ----- Method: FileStream class>>newForStdio (in category 'stdio') -----
+ newForStdio
+ "This is a hook for subclasses to initialize themselves properly."
+
+ ^self new!
Item was added:
+ ----- Method: FileStream class>>shutDown: (in category 'system startup') -----
+ shutDown: quitting
+
+ quitting ifTrue: [ self flushAndVoidStdioFiles ]!
Item was added:
+ ----- Method: FileStream class>>standardIOStreamNamed:forWrite: (in category 'stdio') -----
+ standardIOStreamNamed: moniker forWrite: forWrite
+
+ | index |
+ index := #(stdin stdout stderr) identityIndexOf: moniker.
+ ^((StdioFiles ifNil: [ StdioFiles := Array new: 3 ]) at: index)
+ ifNil: [
+ StdioFiles
+ at: index
+ put: (
+ (TheStdioHandles at: index)
+ ifNil: [ ^self error: moniker, ' is unavailable' ]
+ ifNotNil: [ :handle |
+ self stdioStreamClass newForStdio
+ openOnHandle: handle
+ name: moniker
+ forWrite: forWrite ]) ]
+ !
Item was added:
+ ----- Method: FileStream class>>startUp: (in category 'system startup') -----
+ startUp: resuming
+
+ resuming ifTrue: [
+ self voidStdioFiles.
+ [ TheStdioHandles := self stdioHandles ]
+ on: Error
+ do: [:ex|
+ TheStdioHandles isArray ifFalse: [
+ TheStdioHandles := Array new: 3 ] ] ]!
Item was added:
+ ----- Method: FileStream class>>stderr (in category 'stdio') -----
+ stderr
+
+ ^Stderr ifNil: [ Stderr := self standardIOStreamNamed: #stderr forWrite: true ]!
Item was added:
+ ----- Method: FileStream class>>stdin (in category 'stdio') -----
+ stdin
+
+ ^Stdin ifNil: [ Stdin := self standardIOStreamNamed: #stdin forWrite: false ]!
Item was added:
+ ----- Method: FileStream class>>stdioHandles (in category 'stdio') -----
+ stdioHandles
+ <primitive: 'primitiveFileStdioHandles' module: 'FilePlugin' error: ec>
+ self primitiveFailed!
Item was added:
+ ----- Method: FileStream class>>stdioStreamClass (in category 'stdio') -----
+ stdioStreamClass
+
+ ^self encodeAndDecodeStdioFiles
+ ifTrue: [ MultiByteFileStream ]
+ ifFalse: [ StandardFileStream ]!
Item was added:
+ ----- Method: FileStream class>>stdout (in category 'stdio') -----
+ stdout
+
+ ^Stdout ifNil: [ Stdout := self standardIOStreamNamed: #stdout forWrite: true ]!
Item was added:
+ ----- Method: FileStream class>>updateStdioFiles (in category 'stdio') -----
+ updateStdioFiles
+ "Make sure that all existing stdio files are instances of #stdioStreamClass."
+
+ StdioFiles ifNil: [ ^self ].
+ Stdin := Stdout := Stderr := nil.
+ StdioFiles := StdioFiles collect: [ :file |
+ file ifNotNil: [
+ file class == self stdioStreamClass
+ ifTrue: [ file ]
+ ifFalse: [
+ self stdioStreamClass newForStdio
+ copyFrom: file;
+ yourself ] ] ]
+ !
Item was added:
+ ----- Method: FileStream class>>voidStdioFiles (in category 'stdio') -----
+ voidStdioFiles
+
+ Stdin := Stdout := Stderr := StdioFiles := nil!
Levente Uzonyi uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-ul.96.mcz
==================== Summary ====================
Name: Files-ul.96
Author: ul
Time: 24 January 2011, 3:45:32.858 am
UUID: d06be799-4c77-3b46-aff8-4abc589fafd3
Ancestors: Files-mtf.95
Stdio support changes:
- Added stdio support code to FileStream.
- Unified API for accessing stdio streams. All users should send #stdin, #stdout and #stderr to FileStream to access the streams.
- MultiByteFileStream is used instead of CrLfFileStream.
- CrLfFileStream class >> #new is now deprecated
=============== Diff against Files-mtf.95 ===============
Item was changed:
StandardFileStream subclass: #CrLfFileStream
instanceVariableNames: 'lineEndConvention'
classVariableNames: 'Cr CrLf Lf LineEndDefault LineEndStrings LookAheadCount'
poolDictionaries: ''
category: 'Files-Kernel'!
+ !CrLfFileStream commentStamp: 'ul 12/26/2010 03:13' prior: 0!
+ This class is now obsolete, use MultiByteFileStream instead.
+
- !CrLfFileStream commentStamp: 'ls 11/10/2002 13:32' prior: 0!
I am the same as a regular file stream, except that when I am in text mode, I will automatically convert line endings between the underlying platform's convention, and Squeak's convention of carriage-return only. The goal is that Squeak text files can be treated as OS text files, and vice versa.
In binary mode, I behave identically to a StandardFileStream.
To enable CrLfFileStream as the default file stream class for an entire image, modify FileStream class concreteStream .
There are two caveats on programming with CrLfFileStream.
First, the choice of text mode versus binary mode affects which characters are visible in Squeak, and no longer just affects whether those characters are returned as Character's or as Integer's. Thus the choice of mode needs to be made very carefully, and must be based on intent instead of convenience of representation. The methods asString, asByteArray, asCharacter, and asInteger can be used to convert between character and integer representations. (Arguably, file streams should accept either strings or characters in nextPut: and nextPutAll:, but that is not the case right now.)
Second, arithmetic on positions no longer works, because one character that Squeak sees (carriage return) could map to two characters in the underlying file (carriage return plus line feed, on MS Windows and MS DOS). Comparison between positions still works. (This caveat could perhaps be fixed by maintaining a map between Squeak positions and positions in the underlying file, but it is complicated. Consider, for example, updates to the middle of the file. Also, consider that text files are rarely updated in the middle of the file, and that general random access to a text file is rarely very useful. If general random access with specific file counts is desired, then the file is starting to sound like a binary file instead of a text file.)
!
Item was changed:
----- Method: CrLfFileStream class>>new (in category 'class initialization') -----
new
+ self deprecated: 'This class is now obsolete, use MultiByteFileStream instead.'.
^ (MultiByteFileStream new) wantsLineEndConversion: true; yourself.
!
Item was removed:
- ----- Method: CrLfFileStream class>>newForStdio (in category 'instance creation') -----
- newForStdio
- "Circumvent CrLfFileStream new's retuning an instance of MultiBteFileStream"
- ^super new!
Item was removed:
- ----- Method: CrLfFileStream>>openOnHandle:name:forWrite: (in category 'open/close') -----
- openOnHandle: aFileID name: streamName forWrite: writeMode
- "Initialize the file with the given handle. If writeMode is true then
- allow writing, otherwise put the file in read-only mode."
- super openOnHandle: aFileID name: streamName forWrite: writeMode.
- lineEndConvention := LineEndDefault!
Item was changed:
ReadWriteStream subclass: #FileStream
instanceVariableNames: 'rwmode'
+ classVariableNames: 'EncodeAndDecodeStdioFiles Stderr Stdin StdioFiles Stdout TheStdioHandles'
- classVariableNames: ''
poolDictionaries: ''
category: 'Files-Kernel'!
!FileStream commentStamp: '<historical>' prior: 0!
I represent a Stream that accesses a FilePage from a File. One use for my instance is to access larger "virtual Strings" than can be stored contiguously in main memory. I restrict the objects stored and retrieved to be Integers or Characters. An end of file pointer terminates reading; it can be extended by writing past it, or the file can be explicitly truncated.
To use the file system for most applications, you typically create a FileStream. This is done by sending a message to a FileDirectory (file:, oldFile:, newFile:, rename:newName:) which creates an instance of me. Accesses to the file are then done via my instance.
*** On DOS, files cannot be shortened!! *** To overwrite a file with a shorter one, first delete the old file (FileDirectory deleteFilePath: 'Hard Disk:aFolder:dataFolder:foo') or (aFileDirectory deleteFileNamed: 'foo'). Then write your new shorter version.!
Item was added:
+ ----- Method: FileStream class>>encodeAndDecodeStdioFiles (in category 'stdio') -----
+ encodeAndDecodeStdioFiles
+
+ <preference: 'Encode and decode the contents of stdio files.'
+ category: 'Files'
+ description: 'It true, then the contents of stdin, stdout and stderr are encoded/decoded using the system default text converter.'
+ type: #Boolean>
+ ^EncodeAndDecodeStdioFiles ifNil: [ true ]!
Item was added:
+ ----- Method: FileStream class>>encodeAndDecodeStdioFiles: (in category 'stdio') -----
+ encodeAndDecodeStdioFiles: aBoolean
+
+ EncodeAndDecodeStdioFiles := aBoolean.
+ self updateStdioFiles!
Item was added:
+ ----- Method: FileStream class>>flushAndVoidStdioFiles (in category 'stdio') -----
+ flushAndVoidStdioFiles
+
+ StdioFiles ifNotNil: [
+ StdioFiles do: [ :file |
+ file ifNotNil: [
+ file isReadOnly ifFalse: [
+ [ file flush ]
+ on: Error
+ do: [ :ex | "care less" ] ] ] ].
+ self voidStdioFiles ]!
Item was changed:
----- Method: FileStream class>>initialize (in category 'initialize-release') -----
initialize
+ FileServices registerFileReader: self.
+ EncodeAndDecodeStdioFiles := true.
+ TheStdioHandles := Array new: 3.
+ Smalltalk
+ addToStartUpList: self after: SecurityManager; "the intent being before: AutoStart"
+ addToShutDownList: self after: SecurityManager!
- FileServices registerFileReader: self!
Item was added:
+ ----- Method: FileStream class>>newForStdio (in category 'stdio') -----
+ newForStdio
+ "This is a hook for subclasses to initialize themselves properly."
+
+ ^self new!
Item was added:
+ ----- Method: FileStream class>>shutDown: (in category 'system startup') -----
+ shutDown: quitting
+
+ quitting ifTrue: [ self flushAndVoidStdioFiles ]!
Item was added:
+ ----- Method: FileStream class>>standardIOStreamNamed:forWrite: (in category 'stdio') -----
+ standardIOStreamNamed: moniker forWrite: forWrite
+
+ | index |
+ index := #(stdin stdout stderr) identityIndexOf: moniker.
+ ^((StdioFiles ifNil: [ StdioFiles := Array new: 3 ]) at: index)
+ ifNil: [
+ StdioFiles
+ at: index
+ put: (
+ (TheStdioHandles at: index)
+ ifNil: [ ^self error: moniker, ' is unavailable' ]
+ ifNotNil: [ :handle |
+ self stdioStreamClass newForStdio
+ openOnHandle: handle
+ name: moniker
+ forWrite: forWrite ]) ]
+ !
Item was added:
+ ----- Method: FileStream class>>startUp: (in category 'system startup') -----
+ startUp: resuming
+
+ resuming ifTrue: [
+ self voidStdioFiles.
+ [ TheStdioHandles := self stdioHandles ]
+ on: Error
+ do: [:ex|
+ TheStdioHandles isArray ifFalse: [
+ TheStdioHandles := Array new: 3 ] ] ]!
Item was added:
+ ----- Method: FileStream class>>stderr (in category 'stdio') -----
+ stderr
+
+ ^Stderr ifNil: [ Stderr := self standardIOStreamNamed: #stderr forWrite: true ]!
Item was added:
+ ----- Method: FileStream class>>stdin (in category 'stdio') -----
+ stdin
+
+ ^Stdin ifNil: [ Stdin := self standardIOStreamNamed: #stdin forWrite: false ]!
Item was added:
+ ----- Method: FileStream class>>stdioHandles (in category 'stdio') -----
+ stdioHandles
+ <primitive: 'primitiveFileStdioHandles' module: 'FilePlugin' error: ec>
+ self primitiveFailed!
Item was added:
+ ----- Method: FileStream class>>stdioStreamClass (in category 'stdio') -----
+ stdioStreamClass
+
+ ^self encodeAndDecodeStdioFiles
+ ifTrue: [ MultiByteFileStream ]
+ ifFalse: [ StandardFileStream ]!
Item was added:
+ ----- Method: FileStream class>>stdout (in category 'stdio') -----
+ stdout
+
+ ^Stdout ifNil: [ Stdout := self standardIOStreamNamed: #stdout forWrite: true ]!
Item was added:
+ ----- Method: FileStream class>>updateStdioFiles (in category 'stdio') -----
+ updateStdioFiles
+ "Make sure that all existing stdio files are instances of #stdioStreamClass."
+
+ StdioFiles ifNil: [ ^self ].
+ Stdin := Stdout := Stderr := nil.
+ StdioFiles := StdioFiles collect: [ :file |
+ file ifNotNil: [
+ file class == self stdioStreamClass
+ ifTrue: [ file ]
+ ifFalse: [
+ self stdioStreamClass newForStdio
+ copyFrom: file;
+ yourself ] ] ]
+ !
Item was added:
+ ----- Method: FileStream class>>voidStdioFiles (in category 'stdio') -----
+ voidStdioFiles
+
+ Stdin := Stdout := Stderr := StdioFiles := nil!
Levente Uzonyi uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-ul.96.mcz
==================== Summary ====================
Name: Files-ul.96
Author: ul
Time: 24 January 2011, 3:45:32.858 am
UUID: d06be799-4c77-3b46-aff8-4abc589fafd3
Ancestors: Files-mtf.95
Stdio support changes:
- Added stdio support code to FileStream.
- Unified API for accessing stdio streams. All users should send #stdin, #stdout and #stderr to FileStream to access the streams.
- MultiByteFileStream is used instead of CrLfFileStream.
- CrLfFileStream class >> #new is now deprecated
=============== Diff against Files-mtf.95 ===============
Item was changed:
StandardFileStream subclass: #CrLfFileStream
instanceVariableNames: 'lineEndConvention'
classVariableNames: 'Cr CrLf Lf LineEndDefault LineEndStrings LookAheadCount'
poolDictionaries: ''
category: 'Files-Kernel'!
+ !CrLfFileStream commentStamp: 'ul 12/26/2010 03:13' prior: 0!
+ This class is now obsolete, use MultiByteFileStream instead.
+
- !CrLfFileStream commentStamp: 'ls 11/10/2002 13:32' prior: 0!
I am the same as a regular file stream, except that when I am in text mode, I will automatically convert line endings between the underlying platform's convention, and Squeak's convention of carriage-return only. The goal is that Squeak text files can be treated as OS text files, and vice versa.
In binary mode, I behave identically to a StandardFileStream.
To enable CrLfFileStream as the default file stream class for an entire image, modify FileStream class concreteStream .
There are two caveats on programming with CrLfFileStream.
First, the choice of text mode versus binary mode affects which characters are visible in Squeak, and no longer just affects whether those characters are returned as Character's or as Integer's. Thus the choice of mode needs to be made very carefully, and must be based on intent instead of convenience of representation. The methods asString, asByteArray, asCharacter, and asInteger can be used to convert between character and integer representations. (Arguably, file streams should accept either strings or characters in nextPut: and nextPutAll:, but that is not the case right now.)
Second, arithmetic on positions no longer works, because one character that Squeak sees (carriage return) could map to two characters in the underlying file (carriage return plus line feed, on MS Windows and MS DOS). Comparison between positions still works. (This caveat could perhaps be fixed by maintaining a map between Squeak positions and positions in the underlying file, but it is complicated. Consider, for example, updates to the middle of the file. Also, consider that text files are rarely updated in the middle of the file, and that general random access to a text file is rarely very useful. If general random access with specific file counts is desired, then the file is starting to sound like a binary file instead of a text file.)
!
Item was changed:
----- Method: CrLfFileStream class>>new (in category 'class initialization') -----
new
+ self deprecated: 'This class is now obsolete, use MultiByteFileStream instead.'.
^ (MultiByteFileStream new) wantsLineEndConversion: true; yourself.
!
Item was removed:
- ----- Method: CrLfFileStream class>>newForStdio (in category 'instance creation') -----
- newForStdio
- "Circumvent CrLfFileStream new's retuning an instance of MultiBteFileStream"
- ^super new!
Item was removed:
- ----- Method: CrLfFileStream>>openOnHandle:name:forWrite: (in category 'open/close') -----
- openOnHandle: aFileID name: streamName forWrite: writeMode
- "Initialize the file with the given handle. If writeMode is true then
- allow writing, otherwise put the file in read-only mode."
- super openOnHandle: aFileID name: streamName forWrite: writeMode.
- lineEndConvention := LineEndDefault!
Item was changed:
ReadWriteStream subclass: #FileStream
instanceVariableNames: 'rwmode'
+ classVariableNames: 'EncodeAndDecodeStdioFiles Stderr Stdin StdioFiles Stdout TheStdioHandles'
- classVariableNames: ''
poolDictionaries: ''
category: 'Files-Kernel'!
!FileStream commentStamp: '<historical>' prior: 0!
I represent a Stream that accesses a FilePage from a File. One use for my instance is to access larger "virtual Strings" than can be stored contiguously in main memory. I restrict the objects stored and retrieved to be Integers or Characters. An end of file pointer terminates reading; it can be extended by writing past it, or the file can be explicitly truncated.
To use the file system for most applications, you typically create a FileStream. This is done by sending a message to a FileDirectory (file:, oldFile:, newFile:, rename:newName:) which creates an instance of me. Accesses to the file are then done via my instance.
*** On DOS, files cannot be shortened!! *** To overwrite a file with a shorter one, first delete the old file (FileDirectory deleteFilePath: 'Hard Disk:aFolder:dataFolder:foo') or (aFileDirectory deleteFileNamed: 'foo'). Then write your new shorter version.!
Item was added:
+ ----- Method: FileStream class>>encodeAndDecodeStdioFiles (in category 'stdio') -----
+ encodeAndDecodeStdioFiles
+
+ <preference: 'Encode and decode the contents of stdio files.'
+ category: 'Files'
+ description: 'It true, then the contents of stdin, stdout and stderr are encoded/decoded using the system default text converter.'
+ type: #Boolean>
+ ^EncodeAndDecodeStdioFiles ifNil: [ true ]!
Item was added:
+ ----- Method: FileStream class>>encodeAndDecodeStdioFiles: (in category 'stdio') -----
+ encodeAndDecodeStdioFiles: aBoolean
+
+ EncodeAndDecodeStdioFiles := aBoolean.
+ self updateStdioFiles!
Item was added:
+ ----- Method: FileStream class>>flushAndVoidStdioFiles (in category 'stdio') -----
+ flushAndVoidStdioFiles
+
+ StdioFiles ifNotNil: [
+ StdioFiles do: [ :file |
+ file ifNotNil: [
+ file isReadOnly ifFalse: [
+ [ file flush ]
+ on: Error
+ do: [ :ex | "care less" ] ] ] ].
+ self voidStdioFiles ]!
Item was changed:
----- Method: FileStream class>>initialize (in category 'initialize-release') -----
initialize
+ FileServices registerFileReader: self.
+ EncodeAndDecodeStdioFiles := true.
+ TheStdioHandles := Array new: 3.
+ Smalltalk
+ addToStartUpList: self after: SecurityManager; "the intent being before: AutoStart"
+ addToShutDownList: self after: SecurityManager!
- FileServices registerFileReader: self!
Item was added:
+ ----- Method: FileStream class>>newForStdio (in category 'stdio') -----
+ newForStdio
+ "This is a hook for subclasses to initialize themselves properly."
+
+ ^self new!
Item was added:
+ ----- Method: FileStream class>>shutDown: (in category 'system startup') -----
+ shutDown: quitting
+
+ quitting ifTrue: [ self flushAndVoidStdioFiles ]!
Item was added:
+ ----- Method: FileStream class>>standardIOStreamNamed:forWrite: (in category 'stdio') -----
+ standardIOStreamNamed: moniker forWrite: forWrite
+
+ | index |
+ index := #(stdin stdout stderr) identityIndexOf: moniker.
+ ^((StdioFiles ifNil: [ StdioFiles := Array new: 3 ]) at: index)
+ ifNil: [
+ StdioFiles
+ at: index
+ put: (
+ (TheStdioHandles at: index)
+ ifNil: [ ^self error: moniker, ' is unavailable' ]
+ ifNotNil: [ :handle |
+ self stdioStreamClass newForStdio
+ openOnHandle: handle
+ name: moniker
+ forWrite: forWrite ]) ]
+ !
Item was added:
+ ----- Method: FileStream class>>startUp: (in category 'system startup') -----
+ startUp: resuming
+
+ resuming ifTrue: [
+ self voidStdioFiles.
+ [ TheStdioHandles := self stdioHandles ]
+ on: Error
+ do: [:ex|
+ TheStdioHandles isArray ifFalse: [
+ TheStdioHandles := Array new: 3 ] ] ]!
Item was added:
+ ----- Method: FileStream class>>stderr (in category 'stdio') -----
+ stderr
+
+ ^Stderr ifNil: [ Stderr := self standardIOStreamNamed: #stderr forWrite: true ]!
Item was added:
+ ----- Method: FileStream class>>stdin (in category 'stdio') -----
+ stdin
+
+ ^Stdin ifNil: [ Stdin := self standardIOStreamNamed: #stdin forWrite: false ]!
Item was added:
+ ----- Method: FileStream class>>stdioHandles (in category 'stdio') -----
+ stdioHandles
+ <primitive: 'primitiveFileStdioHandles' module: 'FilePlugin' error: ec>
+ self primitiveFailed!
Item was added:
+ ----- Method: FileStream class>>stdioStreamClass (in category 'stdio') -----
+ stdioStreamClass
+
+ ^self encodeAndDecodeStdioFiles
+ ifTrue: [ MultiByteFileStream ]
+ ifFalse: [ StandardFileStream ]!
Item was added:
+ ----- Method: FileStream class>>stdout (in category 'stdio') -----
+ stdout
+
+ ^Stdout ifNil: [ Stdout := self standardIOStreamNamed: #stdout forWrite: true ]!
Item was added:
+ ----- Method: FileStream class>>updateStdioFiles (in category 'stdio') -----
+ updateStdioFiles
+ "Make sure that all existing stdio files are instances of #stdioStreamClass."
+
+ StdioFiles ifNil: [ ^self ].
+ Stdin := Stdout := Stderr := nil.
+ StdioFiles := StdioFiles collect: [ :file |
+ file ifNotNil: [
+ file class == self stdioStreamClass
+ ifTrue: [ file ]
+ ifFalse: [
+ self stdioStreamClass newForStdio
+ copyFrom: file;
+ yourself ] ] ]
+ !
Item was added:
+ ----- Method: FileStream class>>voidStdioFiles (in category 'stdio') -----
+ voidStdioFiles
+
+ Stdin := Stdout := Stderr := StdioFiles := nil!
Levente Uzonyi uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-ul.99.mcz
==================== Summary ====================
Name: Files-ul.99
Author: ul
Time: 29 January 2011, 1:12:30.559 am
UUID: 15cfe8c5-693e-e442-bfab-22eabbf3be6b
Ancestors: Files-ul.98, Files-ul.97
- merged
=============== Diff against Files-ul.98 ===============
Item was added:
+ (PackageInfo named: 'Files') preamble: '"Migrate stdio handles and files from StandardFileStream to FileStream. Turn off encoding and reuse the streams if they are in use in the image for backwards compatibility."
+ (StandardFileStream classPool at: #StdioHandles) ifNotNil: [ :handleArray |
+ FileStream classPool at: #TheStdioHandles put: handleArray ].
+ (StandardFileStream instVarNamed: #stdioFiles) ifNotNil: [ :stdioFiles |
+ FileStream classPool
+ at: #StdioFiles put: stdioFiles;
+ at: #EncodeAndDecodeStdioFiles put: false ].
+ Smalltalk
+ removeFromStartUpList: StandardFileStream;
+ removeFromShutDownList: StandardFileStream'!
Item was changed:
FileStream subclass: #StandardFileStream
instanceVariableNames: 'name fileID buffer1'
+ classVariableNames: 'Registry'
- classVariableNames: 'Registry StdioHandles'
poolDictionaries: ''
category: 'Files-Kernel'!
- StandardFileStream class
- instanceVariableNames: 'stdioFiles'!
!StandardFileStream commentStamp: 'ul 12/6/2009 05:13' prior: 0!
Provides a simple, platform-independent, interface to a file system. The instance variable rwmode, inherited from class PositionableStream, here is used to hold a Boolean -- true means opened for read-write, false means opened for read-only. 2/12/96 sw
I implement a simple read buffering scheme with the variables defined in PositionableStream (which are unused in me otherwise) in the following way:
collection <ByteString> or <ByteArray> This is the buffer.
position <Integer> The relative position in the buffer. Greater or equal to zero.
readLimit <Integer> The number of bytes buffered. Greater or equal to zero.
Read buffering is enabled with #enableReadBuffering, disabled with #disableReadBuffering and it is enabled by default. The buffer is filled when a read attempt of an unbuffered absolute position is requested, or when a negative repositioning is made (with #position: with an argument < than the current absolute position) to an absolute position which is not buffered. In the first case, the buffer is positioned to the given absolute position. In the latter case the repositioning is made to the requested absolute position minus fourth of the buffer size. This means that further small negative repositionings won't result in buffer flushing. This is really useful when filing in code.
The read buffer is flushed (#flushReadBuffer) whenever a write attempt is made.
The buffer state is valid if and only if collection is not nil and position < readLimit.!
- StandardFileStream class
- instanceVariableNames: 'stdioFiles'!
Item was removed:
- ----- Method: StandardFileStream class>>flushAndVoidStdioFiles (in category 'class initialization') -----
- flushAndVoidStdioFiles
- stdioFiles ifNotNil:
- [stdioFiles do:
- [:f| f ifNotNil: [f isReadOnly ifFalse: [[f flush] on: Error do: [:ex|"care less"]]]].
- stdioFiles := nil]!
Item was removed:
- ----- Method: StandardFileStream class>>initialize (in category 'class initialization') -----
- initialize
- "StandardFileStream initialize"
- StdioHandles := Array new: 3.
- Smalltalk
- addToStartUpList: self after: SecurityManager; "the intent being before: AutoStart"
- addToShutDownList: self after: SecurityManager!
Item was removed:
- ----- Method: StandardFileStream class>>newForStdio (in category 'private-file creation') -----
- newForStdio
- "Circumvent CrLfFileStream new's returning an instance of MultiBteFileStream"
- ^self new!
Item was removed:
- ----- Method: StandardFileStream class>>shutDown: (in category 'class initialization') -----
- shutDown: quitting
- quitting ifTrue:
- [self withAllSubclassesDo:
- [:fileStreamClass| fileStreamClass flushAndVoidStdioFiles]]!
Item was removed:
- ----- Method: StandardFileStream class>>standardIOStreamNamed:forWrite: (in category 'private-file creation') -----
- standardIOStreamNamed: moniker forWrite: forWrite
-
- | index |
- index := #(stdin stdout stderr) identityIndexOf: moniker.
- ^((stdioFiles ifNil: [ stdioFiles := Array new: 3 ]) at: index)
- ifNil: [
- stdioFiles
- at: index
- put: (
- (StdioHandles at: index)
- ifNil: [ ^self error: moniker, ' is unavailable' ]
- ifNotNil: [ :handle|
- self newForStdio
- openOnHandle: handle
- name: moniker
- forWrite: forWrite ]) ]!
Item was removed:
- ----- Method: StandardFileStream class>>startUp: (in category 'class initialization') -----
- startUp: resuming
- (resuming and: [self == StandardFileStream]) ifTrue:
- [self withAllSubclassesDo:
- [:fileStreamClass| fileStreamClass voidStdioFiles].
- [StdioHandles := self stdioHandles]
- on: Error
- do: [:ex|
- StdioHandles isArray ifFalse:
- [StdioHandles := Array new: 3]]]!
Item was removed:
- ----- Method: StandardFileStream class>>stderr (in category 'file creation') -----
- stderr
- ^self standardIOStreamNamed: #stderr forWrite: true!
Item was removed:
- ----- Method: StandardFileStream class>>stdin (in category 'file creation') -----
- stdin
- ^self standardIOStreamNamed: #stdin forWrite: false!
Item was removed:
- ----- Method: StandardFileStream class>>stdioHandles (in category 'private-file creation') -----
- stdioHandles
- <primitive: 'primitiveFileStdioHandles' module: 'FilePlugin' error: ec>
- self primitiveFailed!
Item was removed:
- ----- Method: StandardFileStream class>>stdout (in category 'file creation') -----
- stdout
- ^self standardIOStreamNamed: #stdout forWrite: true!
Item was removed:
- ----- Method: StandardFileStream class>>voidStdioFiles (in category 'class initialization') -----
- voidStdioFiles
- stdioFiles := nil!
Levente Uzonyi uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-ul.99.mcz
==================== Summary ====================
Name: Files-ul.99
Author: ul
Time: 29 January 2011, 1:12:30.559 am
UUID: 15cfe8c5-693e-e442-bfab-22eabbf3be6b
Ancestors: Files-ul.98, Files-ul.97
- merged
=============== Diff against Files-ul.98 ===============
Item was added:
+ (PackageInfo named: 'Files') preamble: '"Migrate stdio handles and files from StandardFileStream to FileStream. Turn off encoding and reuse the streams if they are in use in the image for backwards compatibility."
+ (StandardFileStream classPool at: #StdioHandles) ifNotNil: [ :handleArray |
+ FileStream classPool at: #TheStdioHandles put: handleArray ].
+ (StandardFileStream instVarNamed: #stdioFiles) ifNotNil: [ :stdioFiles |
+ FileStream classPool
+ at: #StdioFiles put: stdioFiles;
+ at: #EncodeAndDecodeStdioFiles put: false ].
+ Smalltalk
+ removeFromStartUpList: StandardFileStream;
+ removeFromShutDownList: StandardFileStream'!
Item was changed:
FileStream subclass: #StandardFileStream
instanceVariableNames: 'name fileID buffer1'
+ classVariableNames: 'Registry'
- classVariableNames: 'Registry StdioHandles'
poolDictionaries: ''
category: 'Files-Kernel'!
- StandardFileStream class
- instanceVariableNames: 'stdioFiles'!
!StandardFileStream commentStamp: 'ul 12/6/2009 05:13' prior: 0!
Provides a simple, platform-independent, interface to a file system. The instance variable rwmode, inherited from class PositionableStream, here is used to hold a Boolean -- true means opened for read-write, false means opened for read-only. 2/12/96 sw
I implement a simple read buffering scheme with the variables defined in PositionableStream (which are unused in me otherwise) in the following way:
collection <ByteString> or <ByteArray> This is the buffer.
position <Integer> The relative position in the buffer. Greater or equal to zero.
readLimit <Integer> The number of bytes buffered. Greater or equal to zero.
Read buffering is enabled with #enableReadBuffering, disabled with #disableReadBuffering and it is enabled by default. The buffer is filled when a read attempt of an unbuffered absolute position is requested, or when a negative repositioning is made (with #position: with an argument < than the current absolute position) to an absolute position which is not buffered. In the first case, the buffer is positioned to the given absolute position. In the latter case the repositioning is made to the requested absolute position minus fourth of the buffer size. This means that further small negative repositionings won't result in buffer flushing. This is really useful when filing in code.
The read buffer is flushed (#flushReadBuffer) whenever a write attempt is made.
The buffer state is valid if and only if collection is not nil and position < readLimit.!
- StandardFileStream class
- instanceVariableNames: 'stdioFiles'!
Item was removed:
- ----- Method: StandardFileStream class>>flushAndVoidStdioFiles (in category 'class initialization') -----
- flushAndVoidStdioFiles
- stdioFiles ifNotNil:
- [stdioFiles do:
- [:f| f ifNotNil: [f isReadOnly ifFalse: [[f flush] on: Error do: [:ex|"care less"]]]].
- stdioFiles := nil]!
Item was removed:
- ----- Method: StandardFileStream class>>initialize (in category 'class initialization') -----
- initialize
- "StandardFileStream initialize"
- StdioHandles := Array new: 3.
- Smalltalk
- addToStartUpList: self after: SecurityManager; "the intent being before: AutoStart"
- addToShutDownList: self after: SecurityManager!
Item was removed:
- ----- Method: StandardFileStream class>>newForStdio (in category 'private-file creation') -----
- newForStdio
- "Circumvent CrLfFileStream new's returning an instance of MultiBteFileStream"
- ^self new!
Item was removed:
- ----- Method: StandardFileStream class>>shutDown: (in category 'class initialization') -----
- shutDown: quitting
- quitting ifTrue:
- [self withAllSubclassesDo:
- [:fileStreamClass| fileStreamClass flushAndVoidStdioFiles]]!
Item was removed:
- ----- Method: StandardFileStream class>>standardIOStreamNamed:forWrite: (in category 'private-file creation') -----
- standardIOStreamNamed: moniker forWrite: forWrite
-
- | index |
- index := #(stdin stdout stderr) identityIndexOf: moniker.
- ^((stdioFiles ifNil: [ stdioFiles := Array new: 3 ]) at: index)
- ifNil: [
- stdioFiles
- at: index
- put: (
- (StdioHandles at: index)
- ifNil: [ ^self error: moniker, ' is unavailable' ]
- ifNotNil: [ :handle|
- self newForStdio
- openOnHandle: handle
- name: moniker
- forWrite: forWrite ]) ]!
Item was removed:
- ----- Method: StandardFileStream class>>startUp: (in category 'class initialization') -----
- startUp: resuming
- (resuming and: [self == StandardFileStream]) ifTrue:
- [self withAllSubclassesDo:
- [:fileStreamClass| fileStreamClass voidStdioFiles].
- [StdioHandles := self stdioHandles]
- on: Error
- do: [:ex|
- StdioHandles isArray ifFalse:
- [StdioHandles := Array new: 3]]]!
Item was removed:
- ----- Method: StandardFileStream class>>stderr (in category 'file creation') -----
- stderr
- ^self standardIOStreamNamed: #stderr forWrite: true!
Item was removed:
- ----- Method: StandardFileStream class>>stdin (in category 'file creation') -----
- stdin
- ^self standardIOStreamNamed: #stdin forWrite: false!
Item was removed:
- ----- Method: StandardFileStream class>>stdioHandles (in category 'private-file creation') -----
- stdioHandles
- <primitive: 'primitiveFileStdioHandles' module: 'FilePlugin' error: ec>
- self primitiveFailed!
Item was removed:
- ----- Method: StandardFileStream class>>stdout (in category 'file creation') -----
- stdout
- ^self standardIOStreamNamed: #stdout forWrite: true!
Item was removed:
- ----- Method: StandardFileStream class>>voidStdioFiles (in category 'class initialization') -----
- voidStdioFiles
- stdioFiles := nil!
Levente Uzonyi uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-ul.99.mcz
==================== Summary ====================
Name: Files-ul.99
Author: ul
Time: 29 January 2011, 1:12:30.559 am
UUID: 15cfe8c5-693e-e442-bfab-22eabbf3be6b
Ancestors: Files-ul.98, Files-ul.97
- merged
=============== Diff against Files-ul.98 ===============
Item was added:
+ (PackageInfo named: 'Files') preamble: '"Migrate stdio handles and files from StandardFileStream to FileStream. Turn off encoding and reuse the streams if they are in use in the image for backwards compatibility."
+ (StandardFileStream classPool at: #StdioHandles) ifNotNil: [ :handleArray |
+ FileStream classPool at: #TheStdioHandles put: handleArray ].
+ (StandardFileStream instVarNamed: #stdioFiles) ifNotNil: [ :stdioFiles |
+ FileStream classPool
+ at: #StdioFiles put: stdioFiles;
+ at: #EncodeAndDecodeStdioFiles put: false ].
+ Smalltalk
+ removeFromStartUpList: StandardFileStream;
+ removeFromShutDownList: StandardFileStream'!
Item was changed:
FileStream subclass: #StandardFileStream
instanceVariableNames: 'name fileID buffer1'
+ classVariableNames: 'Registry'
- classVariableNames: 'Registry StdioHandles'
poolDictionaries: ''
category: 'Files-Kernel'!
- StandardFileStream class
- instanceVariableNames: 'stdioFiles'!
!StandardFileStream commentStamp: 'ul 12/6/2009 05:13' prior: 0!
Provides a simple, platform-independent, interface to a file system. The instance variable rwmode, inherited from class PositionableStream, here is used to hold a Boolean -- true means opened for read-write, false means opened for read-only. 2/12/96 sw
I implement a simple read buffering scheme with the variables defined in PositionableStream (which are unused in me otherwise) in the following way:
collection <ByteString> or <ByteArray> This is the buffer.
position <Integer> The relative position in the buffer. Greater or equal to zero.
readLimit <Integer> The number of bytes buffered. Greater or equal to zero.
Read buffering is enabled with #enableReadBuffering, disabled with #disableReadBuffering and it is enabled by default. The buffer is filled when a read attempt of an unbuffered absolute position is requested, or when a negative repositioning is made (with #position: with an argument < than the current absolute position) to an absolute position which is not buffered. In the first case, the buffer is positioned to the given absolute position. In the latter case the repositioning is made to the requested absolute position minus fourth of the buffer size. This means that further small negative repositionings won't result in buffer flushing. This is really useful when filing in code.
The read buffer is flushed (#flushReadBuffer) whenever a write attempt is made.
The buffer state is valid if and only if collection is not nil and position < readLimit.!
- StandardFileStream class
- instanceVariableNames: 'stdioFiles'!
Item was removed:
- ----- Method: StandardFileStream class>>flushAndVoidStdioFiles (in category 'class initialization') -----
- flushAndVoidStdioFiles
- stdioFiles ifNotNil:
- [stdioFiles do:
- [:f| f ifNotNil: [f isReadOnly ifFalse: [[f flush] on: Error do: [:ex|"care less"]]]].
- stdioFiles := nil]!
Item was removed:
- ----- Method: StandardFileStream class>>initialize (in category 'class initialization') -----
- initialize
- "StandardFileStream initialize"
- StdioHandles := Array new: 3.
- Smalltalk
- addToStartUpList: self after: SecurityManager; "the intent being before: AutoStart"
- addToShutDownList: self after: SecurityManager!
Item was removed:
- ----- Method: StandardFileStream class>>newForStdio (in category 'private-file creation') -----
- newForStdio
- "Circumvent CrLfFileStream new's returning an instance of MultiBteFileStream"
- ^self new!
Item was removed:
- ----- Method: StandardFileStream class>>shutDown: (in category 'class initialization') -----
- shutDown: quitting
- quitting ifTrue:
- [self withAllSubclassesDo:
- [:fileStreamClass| fileStreamClass flushAndVoidStdioFiles]]!
Item was removed:
- ----- Method: StandardFileStream class>>standardIOStreamNamed:forWrite: (in category 'private-file creation') -----
- standardIOStreamNamed: moniker forWrite: forWrite
-
- | index |
- index := #(stdin stdout stderr) identityIndexOf: moniker.
- ^((stdioFiles ifNil: [ stdioFiles := Array new: 3 ]) at: index)
- ifNil: [
- stdioFiles
- at: index
- put: (
- (StdioHandles at: index)
- ifNil: [ ^self error: moniker, ' is unavailable' ]
- ifNotNil: [ :handle|
- self newForStdio
- openOnHandle: handle
- name: moniker
- forWrite: forWrite ]) ]!
Item was removed:
- ----- Method: StandardFileStream class>>startUp: (in category 'class initialization') -----
- startUp: resuming
- (resuming and: [self == StandardFileStream]) ifTrue:
- [self withAllSubclassesDo:
- [:fileStreamClass| fileStreamClass voidStdioFiles].
- [StdioHandles := self stdioHandles]
- on: Error
- do: [:ex|
- StdioHandles isArray ifFalse:
- [StdioHandles := Array new: 3]]]!
Item was removed:
- ----- Method: StandardFileStream class>>stderr (in category 'file creation') -----
- stderr
- ^self standardIOStreamNamed: #stderr forWrite: true!
Item was removed:
- ----- Method: StandardFileStream class>>stdin (in category 'file creation') -----
- stdin
- ^self standardIOStreamNamed: #stdin forWrite: false!
Item was removed:
- ----- Method: StandardFileStream class>>stdioHandles (in category 'private-file creation') -----
- stdioHandles
- <primitive: 'primitiveFileStdioHandles' module: 'FilePlugin' error: ec>
- self primitiveFailed!
Item was removed:
- ----- Method: StandardFileStream class>>stdout (in category 'file creation') -----
- stdout
- ^self standardIOStreamNamed: #stdout forWrite: true!
Item was removed:
- ----- Method: StandardFileStream class>>voidStdioFiles (in category 'class initialization') -----
- voidStdioFiles
- stdioFiles := nil!
Levente Uzonyi uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-ul.98.mcz
==================== Summary ====================
Name: Files-ul.98
Author: ul
Time: 29 January 2011, 1:11:53.403 am
UUID: 4ee664f6-e307-8340-bf9d-b646097d4162
Ancestors: Files-cmm.96, Files-ul.96
- merged
=============== Diff against Files-cmm.96 ===============
Item was changed:
StandardFileStream subclass: #CrLfFileStream
instanceVariableNames: 'lineEndConvention'
classVariableNames: 'Cr CrLf Lf LineEndDefault LineEndStrings LookAheadCount'
poolDictionaries: ''
category: 'Files-Kernel'!
+ !CrLfFileStream commentStamp: 'ul 12/26/2010 03:13' prior: 0!
+ This class is now obsolete, use MultiByteFileStream instead.
+
- !CrLfFileStream commentStamp: 'ls 11/10/2002 13:32' prior: 0!
I am the same as a regular file stream, except that when I am in text mode, I will automatically convert line endings between the underlying platform's convention, and Squeak's convention of carriage-return only. The goal is that Squeak text files can be treated as OS text files, and vice versa.
In binary mode, I behave identically to a StandardFileStream.
To enable CrLfFileStream as the default file stream class for an entire image, modify FileStream class concreteStream .
There are two caveats on programming with CrLfFileStream.
First, the choice of text mode versus binary mode affects which characters are visible in Squeak, and no longer just affects whether those characters are returned as Character's or as Integer's. Thus the choice of mode needs to be made very carefully, and must be based on intent instead of convenience of representation. The methods asString, asByteArray, asCharacter, and asInteger can be used to convert between character and integer representations. (Arguably, file streams should accept either strings or characters in nextPut: and nextPutAll:, but that is not the case right now.)
Second, arithmetic on positions no longer works, because one character that Squeak sees (carriage return) could map to two characters in the underlying file (carriage return plus line feed, on MS Windows and MS DOS). Comparison between positions still works. (This caveat could perhaps be fixed by maintaining a map between Squeak positions and positions in the underlying file, but it is complicated. Consider, for example, updates to the middle of the file. Also, consider that text files are rarely updated in the middle of the file, and that general random access to a text file is rarely very useful. If general random access with specific file counts is desired, then the file is starting to sound like a binary file instead of a text file.)
!
Item was changed:
----- Method: CrLfFileStream class>>new (in category 'class initialization') -----
new
+ self deprecated: 'This class is now obsolete, use MultiByteFileStream instead.'.
^ (MultiByteFileStream new) wantsLineEndConversion: true; yourself.
!
Item was removed:
- ----- Method: CrLfFileStream class>>newForStdio (in category 'instance creation') -----
- newForStdio
- "Circumvent CrLfFileStream new's retuning an instance of MultiBteFileStream"
- ^super new!
Item was removed:
- ----- Method: CrLfFileStream>>openOnHandle:name:forWrite: (in category 'open/close') -----
- openOnHandle: aFileID name: streamName forWrite: writeMode
- "Initialize the file with the given handle. If writeMode is true then
- allow writing, otherwise put the file in read-only mode."
- super openOnHandle: aFileID name: streamName forWrite: writeMode.
- lineEndConvention := LineEndDefault!
Item was changed:
ReadWriteStream subclass: #FileStream
instanceVariableNames: 'rwmode'
+ classVariableNames: 'EncodeAndDecodeStdioFiles Stderr Stdin StdioFiles Stdout TheStdioHandles'
- classVariableNames: ''
poolDictionaries: ''
category: 'Files-Kernel'!
!FileStream commentStamp: '<historical>' prior: 0!
I represent a Stream that accesses a FilePage from a File. One use for my instance is to access larger "virtual Strings" than can be stored contiguously in main memory. I restrict the objects stored and retrieved to be Integers or Characters. An end of file pointer terminates reading; it can be extended by writing past it, or the file can be explicitly truncated.
To use the file system for most applications, you typically create a FileStream. This is done by sending a message to a FileDirectory (file:, oldFile:, newFile:, rename:newName:) which creates an instance of me. Accesses to the file are then done via my instance.
*** On DOS, files cannot be shortened!! *** To overwrite a file with a shorter one, first delete the old file (FileDirectory deleteFilePath: 'Hard Disk:aFolder:dataFolder:foo') or (aFileDirectory deleteFileNamed: 'foo'). Then write your new shorter version.!
Item was added:
+ ----- Method: FileStream class>>encodeAndDecodeStdioFiles (in category 'stdio') -----
+ encodeAndDecodeStdioFiles
+
+ <preference: 'Encode and decode the contents of stdio files.'
+ category: 'Files'
+ description: 'It true, then the contents of stdin, stdout and stderr are encoded/decoded using the system default text converter.'
+ type: #Boolean>
+ ^EncodeAndDecodeStdioFiles ifNil: [ true ]!
Item was added:
+ ----- Method: FileStream class>>encodeAndDecodeStdioFiles: (in category 'stdio') -----
+ encodeAndDecodeStdioFiles: aBoolean
+
+ EncodeAndDecodeStdioFiles := aBoolean.
+ self updateStdioFiles!
Item was added:
+ ----- Method: FileStream class>>flushAndVoidStdioFiles (in category 'stdio') -----
+ flushAndVoidStdioFiles
+
+ StdioFiles ifNotNil: [
+ StdioFiles do: [ :file |
+ file ifNotNil: [
+ file isReadOnly ifFalse: [
+ [ file flush ]
+ on: Error
+ do: [ :ex | "care less" ] ] ] ].
+ self voidStdioFiles ]!
Item was changed:
----- Method: FileStream class>>initialize (in category 'initialize-release') -----
initialize
+ FileServices registerFileReader: self.
+ EncodeAndDecodeStdioFiles := true.
+ TheStdioHandles := Array new: 3.
+ Smalltalk
+ addToStartUpList: self after: SecurityManager; "the intent being before: AutoStart"
+ addToShutDownList: self after: SecurityManager!
- FileServices registerFileReader: self!
Item was added:
+ ----- Method: FileStream class>>newForStdio (in category 'stdio') -----
+ newForStdio
+ "This is a hook for subclasses to initialize themselves properly."
+
+ ^self new!
Item was added:
+ ----- Method: FileStream class>>shutDown: (in category 'system startup') -----
+ shutDown: quitting
+
+ quitting ifTrue: [ self flushAndVoidStdioFiles ]!
Item was added:
+ ----- Method: FileStream class>>standardIOStreamNamed:forWrite: (in category 'stdio') -----
+ standardIOStreamNamed: moniker forWrite: forWrite
+
+ | index |
+ index := #(stdin stdout stderr) identityIndexOf: moniker.
+ ^((StdioFiles ifNil: [ StdioFiles := Array new: 3 ]) at: index)
+ ifNil: [
+ StdioFiles
+ at: index
+ put: (
+ (TheStdioHandles at: index)
+ ifNil: [ ^self error: moniker, ' is unavailable' ]
+ ifNotNil: [ :handle |
+ self stdioStreamClass newForStdio
+ openOnHandle: handle
+ name: moniker
+ forWrite: forWrite ]) ]
+ !
Item was added:
+ ----- Method: FileStream class>>startUp: (in category 'system startup') -----
+ startUp: resuming
+
+ resuming ifTrue: [
+ self voidStdioFiles.
+ [ TheStdioHandles := self stdioHandles ]
+ on: Error
+ do: [:ex|
+ TheStdioHandles isArray ifFalse: [
+ TheStdioHandles := Array new: 3 ] ] ]!
Item was added:
+ ----- Method: FileStream class>>stderr (in category 'stdio') -----
+ stderr
+
+ ^Stderr ifNil: [ Stderr := self standardIOStreamNamed: #stderr forWrite: true ]!
Item was added:
+ ----- Method: FileStream class>>stdin (in category 'stdio') -----
+ stdin
+
+ ^Stdin ifNil: [ Stdin := self standardIOStreamNamed: #stdin forWrite: false ]!
Item was added:
+ ----- Method: FileStream class>>stdioHandles (in category 'stdio') -----
+ stdioHandles
+ <primitive: 'primitiveFileStdioHandles' module: 'FilePlugin' error: ec>
+ self primitiveFailed!
Item was added:
+ ----- Method: FileStream class>>stdioStreamClass (in category 'stdio') -----
+ stdioStreamClass
+
+ ^self encodeAndDecodeStdioFiles
+ ifTrue: [ MultiByteFileStream ]
+ ifFalse: [ StandardFileStream ]!
Item was added:
+ ----- Method: FileStream class>>stdout (in category 'stdio') -----
+ stdout
+
+ ^Stdout ifNil: [ Stdout := self standardIOStreamNamed: #stdout forWrite: true ]!
Item was added:
+ ----- Method: FileStream class>>updateStdioFiles (in category 'stdio') -----
+ updateStdioFiles
+ "Make sure that all existing stdio files are instances of #stdioStreamClass."
+
+ StdioFiles ifNil: [ ^self ].
+ Stdin := Stdout := Stderr := nil.
+ StdioFiles := StdioFiles collect: [ :file |
+ file ifNotNil: [
+ file class == self stdioStreamClass
+ ifTrue: [ file ]
+ ifFalse: [
+ self stdioStreamClass newForStdio
+ copyFrom: file;
+ yourself ] ] ]
+ !
Item was added:
+ ----- Method: FileStream class>>voidStdioFiles (in category 'stdio') -----
+ voidStdioFiles
+
+ Stdin := Stdout := Stderr := StdioFiles := nil!
Levente Uzonyi uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-ul.98.mcz
==================== Summary ====================
Name: Files-ul.98
Author: ul
Time: 29 January 2011, 1:11:53.403 am
UUID: 4ee664f6-e307-8340-bf9d-b646097d4162
Ancestors: Files-cmm.96, Files-ul.96
- merged
=============== Diff against Files-cmm.96 ===============
Item was changed:
StandardFileStream subclass: #CrLfFileStream
instanceVariableNames: 'lineEndConvention'
classVariableNames: 'Cr CrLf Lf LineEndDefault LineEndStrings LookAheadCount'
poolDictionaries: ''
category: 'Files-Kernel'!
+ !CrLfFileStream commentStamp: 'ul 12/26/2010 03:13' prior: 0!
+ This class is now obsolete, use MultiByteFileStream instead.
+
- !CrLfFileStream commentStamp: 'ls 11/10/2002 13:32' prior: 0!
I am the same as a regular file stream, except that when I am in text mode, I will automatically convert line endings between the underlying platform's convention, and Squeak's convention of carriage-return only. The goal is that Squeak text files can be treated as OS text files, and vice versa.
In binary mode, I behave identically to a StandardFileStream.
To enable CrLfFileStream as the default file stream class for an entire image, modify FileStream class concreteStream .
There are two caveats on programming with CrLfFileStream.
First, the choice of text mode versus binary mode affects which characters are visible in Squeak, and no longer just affects whether those characters are returned as Character's or as Integer's. Thus the choice of mode needs to be made very carefully, and must be based on intent instead of convenience of representation. The methods asString, asByteArray, asCharacter, and asInteger can be used to convert between character and integer representations. (Arguably, file streams should accept either strings or characters in nextPut: and nextPutAll:, but that is not the case right now.)
Second, arithmetic on positions no longer works, because one character that Squeak sees (carriage return) could map to two characters in the underlying file (carriage return plus line feed, on MS Windows and MS DOS). Comparison between positions still works. (This caveat could perhaps be fixed by maintaining a map between Squeak positions and positions in the underlying file, but it is complicated. Consider, for example, updates to the middle of the file. Also, consider that text files are rarely updated in the middle of the file, and that general random access to a text file is rarely very useful. If general random access with specific file counts is desired, then the file is starting to sound like a binary file instead of a text file.)
!
Item was changed:
----- Method: CrLfFileStream class>>new (in category 'class initialization') -----
new
+ self deprecated: 'This class is now obsolete, use MultiByteFileStream instead.'.
^ (MultiByteFileStream new) wantsLineEndConversion: true; yourself.
!
Item was removed:
- ----- Method: CrLfFileStream class>>newForStdio (in category 'instance creation') -----
- newForStdio
- "Circumvent CrLfFileStream new's retuning an instance of MultiBteFileStream"
- ^super new!
Item was removed:
- ----- Method: CrLfFileStream>>openOnHandle:name:forWrite: (in category 'open/close') -----
- openOnHandle: aFileID name: streamName forWrite: writeMode
- "Initialize the file with the given handle. If writeMode is true then
- allow writing, otherwise put the file in read-only mode."
- super openOnHandle: aFileID name: streamName forWrite: writeMode.
- lineEndConvention := LineEndDefault!
Item was changed:
ReadWriteStream subclass: #FileStream
instanceVariableNames: 'rwmode'
+ classVariableNames: 'EncodeAndDecodeStdioFiles Stderr Stdin StdioFiles Stdout TheStdioHandles'
- classVariableNames: ''
poolDictionaries: ''
category: 'Files-Kernel'!
!FileStream commentStamp: '<historical>' prior: 0!
I represent a Stream that accesses a FilePage from a File. One use for my instance is to access larger "virtual Strings" than can be stored contiguously in main memory. I restrict the objects stored and retrieved to be Integers or Characters. An end of file pointer terminates reading; it can be extended by writing past it, or the file can be explicitly truncated.
To use the file system for most applications, you typically create a FileStream. This is done by sending a message to a FileDirectory (file:, oldFile:, newFile:, rename:newName:) which creates an instance of me. Accesses to the file are then done via my instance.
*** On DOS, files cannot be shortened!! *** To overwrite a file with a shorter one, first delete the old file (FileDirectory deleteFilePath: 'Hard Disk:aFolder:dataFolder:foo') or (aFileDirectory deleteFileNamed: 'foo'). Then write your new shorter version.!
Item was added:
+ ----- Method: FileStream class>>encodeAndDecodeStdioFiles (in category 'stdio') -----
+ encodeAndDecodeStdioFiles
+
+ <preference: 'Encode and decode the contents of stdio files.'
+ category: 'Files'
+ description: 'It true, then the contents of stdin, stdout and stderr are encoded/decoded using the system default text converter.'
+ type: #Boolean>
+ ^EncodeAndDecodeStdioFiles ifNil: [ true ]!
Item was added:
+ ----- Method: FileStream class>>encodeAndDecodeStdioFiles: (in category 'stdio') -----
+ encodeAndDecodeStdioFiles: aBoolean
+
+ EncodeAndDecodeStdioFiles := aBoolean.
+ self updateStdioFiles!
Item was added:
+ ----- Method: FileStream class>>flushAndVoidStdioFiles (in category 'stdio') -----
+ flushAndVoidStdioFiles
+
+ StdioFiles ifNotNil: [
+ StdioFiles do: [ :file |
+ file ifNotNil: [
+ file isReadOnly ifFalse: [
+ [ file flush ]
+ on: Error
+ do: [ :ex | "care less" ] ] ] ].
+ self voidStdioFiles ]!
Item was changed:
----- Method: FileStream class>>initialize (in category 'initialize-release') -----
initialize
+ FileServices registerFileReader: self.
+ EncodeAndDecodeStdioFiles := true.
+ TheStdioHandles := Array new: 3.
+ Smalltalk
+ addToStartUpList: self after: SecurityManager; "the intent being before: AutoStart"
+ addToShutDownList: self after: SecurityManager!
- FileServices registerFileReader: self!
Item was added:
+ ----- Method: FileStream class>>newForStdio (in category 'stdio') -----
+ newForStdio
+ "This is a hook for subclasses to initialize themselves properly."
+
+ ^self new!
Item was added:
+ ----- Method: FileStream class>>shutDown: (in category 'system startup') -----
+ shutDown: quitting
+
+ quitting ifTrue: [ self flushAndVoidStdioFiles ]!
Item was added:
+ ----- Method: FileStream class>>standardIOStreamNamed:forWrite: (in category 'stdio') -----
+ standardIOStreamNamed: moniker forWrite: forWrite
+
+ | index |
+ index := #(stdin stdout stderr) identityIndexOf: moniker.
+ ^((StdioFiles ifNil: [ StdioFiles := Array new: 3 ]) at: index)
+ ifNil: [
+ StdioFiles
+ at: index
+ put: (
+ (TheStdioHandles at: index)
+ ifNil: [ ^self error: moniker, ' is unavailable' ]
+ ifNotNil: [ :handle |
+ self stdioStreamClass newForStdio
+ openOnHandle: handle
+ name: moniker
+ forWrite: forWrite ]) ]
+ !
Item was added:
+ ----- Method: FileStream class>>startUp: (in category 'system startup') -----
+ startUp: resuming
+
+ resuming ifTrue: [
+ self voidStdioFiles.
+ [ TheStdioHandles := self stdioHandles ]
+ on: Error
+ do: [:ex|
+ TheStdioHandles isArray ifFalse: [
+ TheStdioHandles := Array new: 3 ] ] ]!
Item was added:
+ ----- Method: FileStream class>>stderr (in category 'stdio') -----
+ stderr
+
+ ^Stderr ifNil: [ Stderr := self standardIOStreamNamed: #stderr forWrite: true ]!
Item was added:
+ ----- Method: FileStream class>>stdin (in category 'stdio') -----
+ stdin
+
+ ^Stdin ifNil: [ Stdin := self standardIOStreamNamed: #stdin forWrite: false ]!
Item was added:
+ ----- Method: FileStream class>>stdioHandles (in category 'stdio') -----
+ stdioHandles
+ <primitive: 'primitiveFileStdioHandles' module: 'FilePlugin' error: ec>
+ self primitiveFailed!
Item was added:
+ ----- Method: FileStream class>>stdioStreamClass (in category 'stdio') -----
+ stdioStreamClass
+
+ ^self encodeAndDecodeStdioFiles
+ ifTrue: [ MultiByteFileStream ]
+ ifFalse: [ StandardFileStream ]!
Item was added:
+ ----- Method: FileStream class>>stdout (in category 'stdio') -----
+ stdout
+
+ ^Stdout ifNil: [ Stdout := self standardIOStreamNamed: #stdout forWrite: true ]!
Item was added:
+ ----- Method: FileStream class>>updateStdioFiles (in category 'stdio') -----
+ updateStdioFiles
+ "Make sure that all existing stdio files are instances of #stdioStreamClass."
+
+ StdioFiles ifNil: [ ^self ].
+ Stdin := Stdout := Stderr := nil.
+ StdioFiles := StdioFiles collect: [ :file |
+ file ifNotNil: [
+ file class == self stdioStreamClass
+ ifTrue: [ file ]
+ ifFalse: [
+ self stdioStreamClass newForStdio
+ copyFrom: file;
+ yourself ] ] ]
+ !
Item was added:
+ ----- Method: FileStream class>>voidStdioFiles (in category 'stdio') -----
+ voidStdioFiles
+
+ Stdin := Stdout := Stderr := StdioFiles := nil!