Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

FileConduit Class Reference

Inheritance diagram for FileConduit:

DeviceConduit ISeekable List of all members.

Public Types

typedef DeviceConduit copy copy
typedef DeviceConduit read read
typedef DeviceConduit write write

Public Member Functions

 this (char[] name, FileStyle style=FileStyle.ReadExisting)
 this (FileProxy proxy, FileStyle style=FileStyle.ReadExisting)
 this (FilePath path, FileStyle style=FileStyle.ReadExisting)
FilePath getPath ()
long seek (long offset)
long getPosition ()
long length ()
FileConduit copy (FilePath source)

Protected Member Functions

override char[] getName ()

Private Types

enum  SeekAnchor { Begin = 0, Current = 1, End = 2 }

Private Member Functions

IConduit copy (IConduit source)
int read (void[] dst)
int read (IBuffer target)
int write (void[] src)
int write (IBuffer source)
 this (ConduitStyle style, bool seekable)
 this (FileDevice device)
 this ()
override void closure ()
IBuffer createBuffer ()
long seek (long offset, SeekAnchor anchor)

Private Attributes

FilePath path

Classes

class  VersionPosix
class  VersionWin32

Detailed Description

Implements a means of reading and writing a generic file. Conduits are the primary means of accessing external data, and are usually routed through a Buffer. File conduit extends the generic conduit by providing file-specific methods to set the file size, seek to a specific file position, and so on. Also provided is a class for creating a memory-mapped Buffer upon a file.

Serial input and output is straightforward. In this example we copy a file directly to the console:

        // open a file for reading
        FileConduit from = new FileConduit ("test.txt");

        // stream directly to console
        Stdout.conduit.copy (from);

And here we copy one file to another:

        // open a file for reading
        FileConduit from = new FileConduit ("test.txt");

        // open another for writing
        FileConduit to = new FileConduit ("copy.txt", FileStyle.WriteTruncate);

        // copy file
        to.copy (from);

FileConduit can just as easily handle random IO. Here we see how a Reader and Writer are used to perform simple input and output:

        // open a file for reading
        FileConduit fc = new FileConduit ("random.bin", FileStyle.ReadWriteCreate);

        // construct (binary) reader & writer upon this conduit
        Reader read = new Reader (fc);
        Writer write = new Writer (fc);

        int x=10, y=20;

        // write some data, and flush output since IO is buffered
        write (x) (y) ();

        // rewind to file start
        fc.seek (0);

        // read data back again, but swap destinations
        read (y) (x);

        assert (y==10);
        assert (x==20);

        fc.close();

FileConduits can also be used directly, without Readers, Writers, or Buffers. To load a file directly into local-memory one might do this:

        // open file for reading
        FileConduit fc = new FileConduit ("test.txt");

        // create an array to house the entire file
        char[] content = new char[fc.length];

        // read the file content. Return value is the number of bytes read
        int bytesRead = fc.read (content);

Conversely, one may write directly to a FileConduit, like so:

        // open file for writing
        FileConduit to = new FileConduit ("text.txt", FileStyle.WriteTruncate);

        // write an array of content to it
        int bytesWritten = fc.write (content);

See File, FilePath, FileProxy, FileConst, FileScan, and FileSystem for additional functionality related to file manipulation.

Doxygen has a hard time with D version() statements, so part of this class is documented within FileConduit::VersionWin32 instead.

Compile with -version=Win32SansUnicode to enable Win95 & Win32s file support.

Definition at line 200 of file FileConduit.d.


Member Typedef Documentation

typedef DeviceConduit copy copy
 

Reimplemented from DeviceConduit.

Definition at line 206 of file FileConduit.d.

typedef DeviceConduit read read
 

Reimplemented from DeviceConduit.

Definition at line 207 of file FileConduit.d.

typedef DeviceConduit write write
 

Reimplemented from DeviceConduit.

Definition at line 208 of file FileConduit.d.


Member Enumeration Documentation

enum SeekAnchor [inherited]
 

The anchor positions supported by ISeekable

Enumeration values:
Begin 
Current 
End 

Definition at line 527 of file IConduit.d.


Member Function Documentation

this char[]  name,
FileStyle  style = FileStyle.ReadExisting
[inline]
 

Create a FileConduit with the provided path and style.

Definition at line 216 of file FileConduit.d.

References FilePath.

this FileProxy  proxy,
FileStyle  style = FileStyle.ReadExisting
[inline]
 

Create a FileConduit from the provided proxy and style.

Definition at line 227 of file FileConduit.d.

this FilePath  path,
FileStyle  style = FileStyle.ReadExisting
[inline]
 

Create a FileConduit with the provided path and style.

Definition at line 238 of file FileConduit.d.

References Resource::acquire(), and path.

FilePath getPath  )  [inline]
 

Return the FilePath used by this file.

Definition at line 260 of file FileConduit.d.

References path.

Referenced by ServletResponse::copyFile().

long seek long  offset  )  [inline]
 

Move the file position to the given offset (from the file start) and return the adjusted postion.

Reimplemented from ISeekable.

Definition at line 272 of file FileConduit.d.

Referenced by FileBucket::Record::createBucket(), getPosition(), length(), FileBucket::Record::read(), testCompositeIO(), testConduitFilters(), testDirectIO(), testMappedFile(), testRandomAccess(), FileBucket::this(), and FileBucket::Record::write().

long getPosition  )  [inline]
 

Return the current file position.

Reimplemented from ISeekable.

Definition at line 283 of file FileConduit.d.

References seek().

Referenced by length(), and FileConduit::VersionPosix::truncate().

long length  )  [inline]
 

Return the total length of this file.

Definition at line 294 of file FileConduit.d.

References getPosition(), and seek().

Referenced by ServletResponse::copyFile(), File::read(), VersionMapped::MappedFile::VersionWin32::this(), and FileBucket::Record::write().

FileConduit copy FilePath  source  )  [inline]
 

Transfer the content of another file to this one. Returns a reference to this class on success, or throws an IOException upon failure.

Definition at line 313 of file FileConduit.d.

References FileConduit.

override char [] getName  )  [inline, protected]
 

Return the name used by this file.

Reimplemented from DeviceConduit.

Definition at line 326 of file FileConduit.d.

References path, and FilePath::toString().

IConduit copy IConduit  source  )  [inline, inherited]
 

Transfer the content of another conduit to this one. Returns a reference to this class, and throws IOException on failure.

Reimplemented from IConduit.

Definition at line 250 of file Conduit.d.

References Conduit::createBuffer(), IBuffer::flush(), IConduit::read(), and Conduit::write().

int read void[]  dst  )  [inherited]
 

conduit-specific reader

Reimplemented from IConduit.

Referenced by DeviceConduit::VersionPosix::read().

int read IBuffer  target  )  [inline, inherited]
 

read from conduit into a target buffer

Reimplemented from IConduit.

Definition at line 184 of file Conduit.d.

References assert().

int write void[]  src  )  [inherited]
 

conduit-specific writer

Reimplemented from IConduit.

Referenced by Conduit::copy(), and DeviceConduit::VersionPosix::write().

int write IBuffer  source  )  [inline, inherited]
 

write to conduit from a source buffer

Reimplemented from IConduit.

Definition at line 197 of file Conduit.d.

References assert().

this ConduitStyle  style,
bool  seekable
[inline, inherited]
 

Construct a conduit with the given style and seek abilities. Conduits are either seekable or non-seekable.

Reimplemented from Conduit.

Definition at line 114 of file DeviceConduit.d.

this FileDevice  device  )  [inline, inherited]
 

Create a FileConduit on the provided FileDevice. This is strictly for adapting existing devices such as Stdout and friends.

Reimplemented in ConsoleConduit.

Definition at line 127 of file DeviceConduit.d.

References Resource::acquire().

this  )  [inline, inherited]
 

Set the default lock to be this object

Reimplemented in DatagramSocket, and SocketConduit.

Definition at line 77 of file Resource.d.

References Resource::_lock.

override void closure  )  [inline, protected, inherited]
 

Callback to close the file. This is invoked from the Resource base-class when the resource is being closed.

Reimplemented from Conduit.

Definition at line 146 of file DeviceConduit.d.

IBuffer createBuffer  )  [inline, inherited]
 

Create a Buffer of the default FileConduit size, and associate it with this conduit

Reimplemented from Conduit.

Definition at line 159 of file DeviceConduit.d.

References Buffer, and IBuffer::setConduit().

Referenced by testFile2(), testFile3(), testFile5(), and testToken4().

long seek long  offset,
SeekAnchor  anchor
[inherited]
 

Move the file position to the given offset from the provided anchor point, and return the adjusted position.


Member Data Documentation

FilePath path [private]
 

Definition at line 203 of file FileConduit.d.

Referenced by getName(), getPath(), FileConduit::VersionPosix::open(), FileConduit::VersionWin32::open(), and this().


The documentation for this class was generated from the following file:
Generated on Fri May 27 18:12:00 2005 for Mango by  doxygen 1.4.0