FileStream.st
changeset 7091 b399f3d19084
parent 7053 13e04c48e23c
child 7100 7cabf9fc8fd4
equal deleted inserted replaced
7090:7afcbe4a5264 7091:b399f3d19084
   267 
   267 
   268 !FileStream class methodsFor:'initialization'!
   268 !FileStream class methodsFor:'initialization'!
   269 
   269 
   270 initialize
   270 initialize
   271     OpenErrorSignal isNil ifTrue:[
   271     OpenErrorSignal isNil ifTrue:[
   272 	"/
   272         "/
   273 	"/ this is temporary - for now allow an openError to
   273         "/ this is temporary - for now allow an openError to
   274 	"/ be unhandled and proceed by returning a nil from the
   274         "/ be unhandled and proceed by returning a nil from the
   275 	"/ stream creation method.
   275         "/ stream creation method.
   276 	"/ In the future, this will be a hard signal.
   276         "/ In the future, this will be a hard signal.
   277 	"/
   277         "/
   278 	OpenErrorSignal := QuerySignal new.
   278         OpenErrorSignal := QuerySignal new.
   279 	OpenErrorSignal parent:(super openErrorSignal) mayProceed:true.
   279         OpenErrorSignal parent:(super openErrorSignal) mayProceed:true.
   280 	OpenErrorSignal nameClass:self message:#openErrorSignal.
   280         OpenErrorSignal nameClass:self message:#openErrorSignal.
   281 	OpenErrorSignal notifierString:'open error'.
   281         OpenErrorSignal notifierString:'open error'.
   282 
   282 "/        OpenErrorSignal defaultAnswer:['OpenError from:' errorPrintCR.
   283 	UserInitiatedFileSaveQuerySignal := QuerySignal new defaultAnswer:true.
   283 "/                                       thisContext fullPrintAll. nil].
   284 	UserInitiatedFileSaveQuerySignal nameClass:self message:#userInitiatedFileSaveQuerySignal.
   284 
       
   285         UserInitiatedFileSaveQuerySignal := QuerySignal new defaultAnswer:true.
       
   286         UserInitiatedFileSaveQuerySignal nameClass:self message:#userInitiatedFileSaveQuerySignal.
   285     ]
   287     ]
   286 
   288 
   287     "Modified: 8.10.1997 / 11:56:39 / cg"
   289     "Modified: 8.10.1997 / 11:56:39 / cg"
   288 ! !
   290 ! !
   289 
   291 
   323 fileNamed:filename
   325 fileNamed:filename
   324     "return a stream on file filename - if the file does not
   326     "return a stream on file filename - if the file does not
   325      already exist, create it.
   327      already exist, create it.
   326      The file is opened for read/write access."
   328      The file is opened for read/write access."
   327 
   329 
   328     |stream|
   330     [
   329 
   331         ^ self oldFileNamed:filename.
   330     stream := self oldFileNamed:filename.
   332     ] on:self openErrorSignal do:[:ex| ].
   331     stream isNil ifTrue:[
   333 
   332 	stream := self newFileNamed:filename
   334     ^ self newFileNamed:filename
   333     ].
       
   334     ^ stream
       
   335 !
   335 !
   336 
   336 
   337 fileNamed:filename in:aDirectory
   337 fileNamed:filename in:aDirectory
   338     "return a stream on file filename - if the file does not
   338     "return a stream on file filename - if the file does not
   339      already exist, create it.
   339      already exist, create it.
   340      The file is opened for read/write access."
   340      The file is opened for read/write access."
   341 
   341 
   342     |stream|
   342     [
   343 
   343         ^ self oldFileNamed:filename in:aDirectory.
   344     stream := self oldFileNamed:filename in:aDirectory.
   344     ] on:self openErrorSignal do:[:ex| ].
   345     stream isNil ifTrue:[
   345 
   346 	stream := self newFileNamed:filename in:aDirectory
   346     ^ self newFileNamed:filename in:aDirectory
   347     ].
       
   348     ^ stream
       
   349 !
   347 !
   350 
   348 
   351 newFileForWritingNamed:filename
   349 newFileForWritingNamed:filename
   352     "return a FileStream for new file named filename, aString.
   350     "return a FileStream for new file named filename, aString.
   353      If the file exists, it is truncated, otherwise created.
   351      If the file exists, it is truncated, otherwise created.
   400     "return a FileStream for existing file named filename, aString.
   398     "return a FileStream for existing file named filename, aString.
   401      The file is opened for read/write access."
   399      The file is opened for read/write access."
   402 
   400 
   403     |newStream|
   401     |newStream|
   404 
   402 
   405     (OperatingSystem isReadable:filename) ifFalse:[^nil].
   403 "/ We can do the following, but is is an extra OS-systemcall:
       
   404 "/    (OperatingSystem isReadable:filename) ifFalse:[^ self new openError].
       
   405 
   406     newStream := self new pathName:filename.
   406     newStream := self new pathName:filename.
   407     newStream readwrite.
   407     newStream readwrite.
   408     newStream openForReadWrite isNil ifTrue:[^nil].
   408     newStream openForReadWrite isNil ifTrue:[^nil].
   409 "
   409 "
   410     this is not a good idea; someone else might be appending ...
   410     this is not a good idea; someone else might be appending ...
   433 readonlyFileNamed:filename
   433 readonlyFileNamed:filename
   434     "return a readonly FileStream for existing file named filename, aString"
   434     "return a readonly FileStream for existing file named filename, aString"
   435 
   435 
   436     |newStream|
   436     |newStream|
   437 
   437 
   438     (OperatingSystem isReadable:filename) ifFalse:[^nil].
   438 "/ We can do the following, but is is an extra OS-systemcall:
       
   439 "/    (OperatingSystem isReadable:filename) ifFalse:[^ self new openError].
   439 
   440 
   440     newStream := self new pathName:filename.
   441     newStream := self new pathName:filename.
   441     newStream openForReading isNil ifTrue:[^nil].
   442     newStream openForReading isNil ifTrue:[^nil].
   442 "
   443 "
   443     this is not a good idea; someone else might be appending ...
   444     this is not a good idea; someone else might be appending ...
   492 !
   493 !
   493 
   494 
   494 write:filename mode:modeSymbol
   495 write:filename mode:modeSymbol
   495     "return a writable FileStream for the file named filename, aString.
   496     "return a writable FileStream for the file named filename, aString.
   496      The modeSymbol controls how the file is opened; currently supported are:
   497      The modeSymbol controls how the file is opened; currently supported are:
   497 	#append
   498         #append
   498     "
   499     "
   499 
   500 
   500     modeSymbol == #append ifTrue:[
   501     modeSymbol == #append ifTrue:[
   501 	^ self appendingOldFileNamed:filename
   502         ^ self appendingOldFileNamed:filename
   502     ].
   503     ].
   503     self halt:'unsupported mode'.
   504     "/ self openErrorSignal is a Notification. This will change..
       
   505     "/ We want to raise a real error here
       
   506     super openErrorSignal raiseRequestErrorString:' - unsupported mode'.
   504     ^ nil
   507     ^ nil
   505 !
   508 !
   506 
   509 
   507 write:filename text:textModeBoolean
   510 write:filename text:textModeBoolean
   508     "return a writable FileStream for the file named filename, aString.
   511     "return a writable FileStream for the file named filename, aString.
   631     "/ now, it is best to provide an exceptionHandler AND check the
   634     "/ now, it is best to provide an exceptionHandler AND check the
   632     "/ return value. 
   635     "/ return value. 
   633     "/ Sorry about that.
   636     "/ Sorry about that.
   634     "/
   637     "/
   635     LastErrorNumber := lastErrorNumber.
   638     LastErrorNumber := lastErrorNumber.
   636     super openError.
   639     ^ super openError.
   637     ^ nil
   640 
       
   641     "
       
   642         '/dasGIBtEsbeStimmtNiChT' asFilename readStream
       
   643     "
   638 ! !
   644 ! !
   639 
   645 
   640 !FileStream methodsFor:'instance release'!
   646 !FileStream methodsFor:'instance release'!
   641 
   647 
   642 closeFile
   648 closeFile
  1361 ! !
  1367 ! !
  1362 
  1368 
  1363 !FileStream class methodsFor:'documentation'!
  1369 !FileStream class methodsFor:'documentation'!
  1364 
  1370 
  1365 version
  1371 version
  1366     ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.90 2003-02-25 10:16:57 cg Exp $'
  1372     ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.91 2003-03-02 19:19:58 stefan Exp $'
  1367 ! !
  1373 ! !
  1368 
  1374 
  1369 FileStream initialize!
  1375 FileStream initialize!