Back: File-testing Up: Base classes Forward: FileDescriptor class-initialization   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document

1.74 FileDescriptor

Defined in namespace Smalltalk
Superclass: Stream
Category: Streams-Files
My instances are what conventional programmers think of as files. My instance creation methods accept the name of a disk file (or any named file object, such as /dev/rmt0 on UNIX or MTA0: on VMS). In addition, they accept a virtual filesystem path like `configure.gz#ugz' which can be used to transparently extract or decompress files from archives, or do arbitrary processing on the files.

1.74.1 FileDescriptor class: initialization  (class)
1.74.2 FileDescriptor class: instance creation  (class)
1.74.3 FileDescriptor class: still unclassified  (class)
1.74.4 FileDescriptor: accessing  (instance)
1.74.5 FileDescriptor: basic  (instance)
1.74.6 FileDescriptor: binary I/O  (instance)
1.74.7 FileDescriptor: built ins  (instance)
1.74.8 FileDescriptor: class type methods  (instance)
1.74.9 FileDescriptor: initialize-release  (instance)
1.74.10 FileDescriptor: low-level access  (instance)
1.74.11 FileDescriptor: overriding inherited methods  (instance)
1.74.12 FileDescriptor: polymorphism  (instance)
1.74.13 FileDescriptor: positioning  (instance)
1.74.14 FileDescriptor: printing  (instance)
1.74.15 FileDescriptor: testing  (instance)


1.74.1 FileDescriptor class: initialization

initialize
Initialize the receiver's class variables

update: aspect
Close open files before quitting


1.74.2 FileDescriptor class: instance creation

append
Open for writing. The file is created if it does not exist. The stream is positioned at the end of the file.

create
Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file.

fopen: fileName mode: fileMode
Open fileName in the required mode - answered by #append, #create, #readWrite, #read or #write - and fail if the file cannot be opened. Else answer a new FileStream. For mode anyway you can use any standard C non-binary fopen mode. The file will be automatically closed upon GC if the object is not referenced anymore, but it is better to close it as soon as you're finished with it anyway, using #close. To keep a file open even when no references exist anymore, send it #removeToBeFinalized

fopen: fileName mode: fileMode ifFail: aBlock
Open fileName in the required mode - answered by #append, #create, #readWrite, #read or #write - and evaluate aBlock if the file cannot be opened. Else answer a new FileStream. For mode anyway you can use any The file will be automatically closed upon GC if the object is not referenced anymore, but it is better to close it as soon as you're finished with it anyway, using #close. To keep a file open even when no references exist anymore, send it #removeToBeFinalized

on: fd
Open a FileDescriptor on the given file descriptor. Read-write access is assumed.

open: fileName
Open fileName in read-write mode - fail if the file cannot be opened. Else answer a new FileStream. The file will be automatically closed upon GC if the object is not referenced anymore, but you should close it with #close anyway. To keep a file open, send it #removeToBeFinalized

open: fileName mode: fileMode ifFail: aBlock
Open fileName in the required mode - answered by #append, #create, #readWrite, #read or #write - and evaluate aBlock if the file cannot be opened. Else answer a new instance of the receiver. For mode anyway you can use any standard C non-binary fopen mode. fileName can be a `virtual filesystem' path, including URLs and '#' suffixes that are inspected by the virtual filesystem layers and replaced with tasks such as un-gzipping a file or extracting a file from an archive.

The file will be automatically closed upon GC if the object is not referenced anymore, but it is better to close it as soon as you're finished with it anyway, using #close. To keep a file open even when no references exist anymore, send it #removeToBeFinalized

openTemporaryFile: baseName
Open for writing a file whose name starts with baseName, followed by six random alphanumeric characters. The file is created with mode read/write and permissions 0666 or 0600 on most recent operating systems (beware, the former behavior might constitute a security problem). The file is opened with the O_EXCL flag, guaranteeing that when the method returns successfully we are the only user.

popen: commandName dir: direction
Open a pipe on the given command and fail if the file cannot be opened. Else answer a new FileStream. The pipe will not be automatically closed upon GC, even if the object is not referenced anymore, because when you close a pipe you have to wait for the associated process to terminate. direction is returned by #read or #write ('r' or 'w') and is interpreted from the point of view of Smalltalk: reading means Smalltalk reads the standard output of the command, writing means Smalltalk writes the standard input of the command. The other channel (stdin when reading, stdout when writing) is the same as GST's, unless commandName alters it.

popen: commandName dir: direction ifFail: aBlock
Open a pipe on the given command and evaluate aBlock file cannot be opened. Else answer a new FileStream. The pipe will not be automatically closed upon GC, even if the object is not referenced anymore, because when you close a pipe you have to wait for the associated process to terminate. direction is interpreted from the point of view of Smalltalk: reading means that Smalltalk reads the standard output of the command, writing means that Smalltalk writes the standard input of the command

read
Open text file for reading. The stream is positioned at the beginning of the file.

readWrite
Open for reading and writing. The stream is positioned at the beginning of the file.

write
Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file.


1.74.3 FileDescriptor class: still unclassified

open: fileName mode: fileMode
Open fileName in the required mode - answered by #append, #create, #readWrite, #read or #write - and fail if the file cannot be opened. Else answer a new FileStream. For mode anyway you can use any standard C non-binary fopen mode. fileName can be a `virtual filesystem' path, including URLs and '#' suffixes that are inspected by the virtual filesystem layers and replaced with tasks such as un-gzipping a file or extracting a file from an archive.

The file will be automatically closed upon GC if the object is not referenced anymore, but it is better to close it as soon as you're finished with it anyway, using #close. To keep a file open even when no references exist anymore, send it #removeToBeFinalized


1.74.4 FileDescriptor: accessing

canRead
Answer whether the file is open and we can read from it

canWrite
Answer whether the file is open and we can write from it

ensureReadable
If the file is open, wait until data can be read from it. The wait allows other Processes to run.

ensureWriteable
If the file is open, wait until we can write to it. The wait allows other Processes to run.

exceptionalCondition
Answer whether the file is open and an exceptional condition (such as presence of out of band data) has occurred on it

fd
Return the OS file descriptor of the file

file
Return the name of the file

isOpen
Answer whether the file is still open

isPeerAlive
Present for compatibility with sockets. For files, it answers whether the file is still open

isPipe
Answer whether the file is a pipe or an actual disk file

name
Return the name of the file

waitForException
If the file is open, wait until an exceptional condition (such as presence of out of band data) has occurred on it. The wait allows other Processes to run.


1.74.5 FileDescriptor: basic

checkError
Perform error checking. By default, we call File class>>#checkError.

close
Close the file

contents
Answer the whole contents of the file

copyFrom: from to: to
Answer the contents of the file between the two given positions

finalize
Close the file if it is still open by the time the object becomes garbage.

invalidate
Invalidate a file descriptor

next
Return the next character in the file, or nil at eof

nextByte
Return the next byte in the file, or nil at eof

nextPut: aCharacter
Store aCharacter on the file

nextPutByte: anInteger
Store the byte, anInteger, on the file

nextPutByteArray: aByteArray
Store aByteArray on the file

peek
Returns the next element of the stream without moving the pointer. Returns nil when at end of stream.

peekFor: anObject
Returns whether the next element of the stream is equal to anObject, without moving the pointer if it is not.

position
Answer the zero-based position from the start of the file

position: n
Set the file pointer to the zero-based position n

reset
Reset the stream to its beginning

shutdown
Close the transmission side of a full-duplex connection. This is useful on read-write pipes.

size
Return the current size of the file, in bytes

truncate
Truncate the file at the current position


1.74.6 FileDescriptor: binary I/O

nextByteArray: numBytes
Return the next numBytes bytes in the byte array

nextDouble
Return the next 64-bit float in the byte array

nextFloat
Return the next 32-bit float in the byte array

nextLong
Return the next 4 bytes in the byte array, interpreted as a 32 bit signed int

nextLongLong
Return the next 8 bytes in the byte array, interpreted as a 64 bit signed int

nextPutDouble: aDouble
Store aDouble as a 64-bit float in the byte array

nextPutFloat: aFloat
Return the next 32-bit float in the byte array

nextPutInt64: anInteger
Store anInteger (range: -2^63..2^64-1) on the byte array as 8 bytes

nextPutLong: anInteger
Store anInteger (range: -2^31..2^32-1) on the byte array as 4 bytes

nextPutShort: anInteger
Store anInteger (range: -32768..65535) on the byte array as 2 bytes

nextShort
Return the next 2 bytes in the byte array, interpreted as a 16 bit signed int

nextSignedByte
Return the next byte in the byte array, interpreted as a 8 bit signed number

nextUint64
Return the next 8 bytes in the byte array, interpreted as a 64 bit unsigned int

nextUlong
Return the next 4 bytes in the byte array, interpreted as a 32 bit unsigned int

nextUshort
Return the next 2 bytes in the byte array, interpreted as a 16 bit unsigned int


1.74.7 FileDescriptor: built ins

fileIn
File in the contents of the receiver. During a file in operation, global variables (starting with an uppercase letter) that are not declared don't yield an `unknown variable' error. Instead, they are defined as nil in the `Undeclared' dictionary (a global variable residing in Smalltalk). As soon as you add the variable to a namespace (for example by creating a class) the Association will be removed from Undeclared and reused in the namespace, so that the old references will automagically point to the new value.

fileOp: ioFuncIndex
Private - Used to limit the number of primitives used by FileStreams

fileOp: ioFuncIndex ifFail: aBlock
Private - Used to limit the number of primitives used by FileStreams.

fileOp: ioFuncIndex with: arg1
Private - Used to limit the number of primitives used by FileStreams

fileOp: ioFuncIndex with: arg1 ifFail: aBlock
Private - Used to limit the number of primitives used by FileStreams.

fileOp: ioFuncIndex with: arg1 with: arg2
Private - Used to limit the number of primitives used by FileStreams

fileOp: ioFuncIndex with: arg1 with: arg2 ifFail: aBlock
Private - Used to limit the number of primitives used by FileStreams.

fileOp: ioFuncIndex with: arg1 with: arg2 with: arg3
Private - Used to limit the number of primitives used by FileStreams

fileOp: ioFuncIndex with: arg1 with: arg2 with: arg3 ifFail: aBlock
Private - Used to limit the number of primitives used by FileStreams.

fileOp: ioFuncIndex with: arg1 with: arg2 with: arg3 with: arg4
Private - Used to limit the number of primitives used by FileStreams

fileOp: ioFuncIndex with: arg1 with: arg2 with: arg3 with: arg4 ifFail: aBlock
Private - Used to limit the number of primitives used by FileStreams.


1.74.8 FileDescriptor: class type methods

isBinary
We answer characters, so answer false

isExternalStream
We stream on an external entity (a file), so answer true

isText
We answer characters, so answer true


1.74.9 FileDescriptor: initialize-release

addToBeFinalized
Add me to the list of open files.

initialize
Initialize the receiver's instance variables

readStream
Answer myself, or an alternate stream coerced for reading.

removeToBeFinalized
Remove me from the list of open files.


1.74.10 FileDescriptor: low-level access

next: n putAll: aCollection startingAt: position
Put the characters in the supplied range of aCollection in the file

nextAvailable: n into: aCollection startingAt: position
Ignoring any buffering, try to fill the given range of aCollection with the contents of the file


1.74.11 FileDescriptor: overriding inherited methods

isEmpty
Answer whether the receiver is empty

nextPutAllOn: aStream
Put all the characters of the receiver in aStream.

reverseContents
Return the contents of the file from the last byte to the first

setToEnd
Reset the file pointer to the end of the file

skip: anInteger
Skip anInteger bytes in the file


1.74.12 FileDescriptor: polymorphism

pastEnd
The end of the stream has been reached. Signal a Notification.


1.74.13 FileDescriptor: positioning

isPositionable
Answer true if the stream supports moving backwards with #skip:.


1.74.14 FileDescriptor: printing

printOn: aStream
Print a representation of the receiver on aStream


1.74.15 FileDescriptor: testing

atEnd
Answer whether data has come to an end



Back: FileDescriptor-printing Up: FileDescriptor Forward: FilePath   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document


This document was generated on February, 22 2012 using texi2html