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.Bits style=FileStyle.ReadExisting)
 this (FileProxy proxy, FileStyle.Bits style=FileStyle.ReadExisting)
 this (FilePath path, FileStyle.Bits style=FileStyle.ReadExisting)
FilePath getPath ()
ulong getPosition ()
ulong 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)
uint read (void[] dst)
uint write (void[] src)
 this (ConduitStyle.Bits style, bool seekable)
 this (FileDevice device)
void close ()
uint bufferSize ()
ulong seek (ulong offset, SeekAnchor anchor=SeekAnchor.Begin)

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 238 of file FileConduit.d.


Member Typedef Documentation

typedef DeviceConduit copy copy
 

Reimplemented from DeviceConduit.

Definition at line 244 of file FileConduit.d.

typedef DeviceConduit read read
 

Reimplemented from DeviceConduit.

Definition at line 245 of file FileConduit.d.

typedef DeviceConduit write write
 

Reimplemented from DeviceConduit.

Definition at line 246 of file FileConduit.d.


Member Enumeration Documentation

enum SeekAnchor [inherited]
 

The anchor positions supported by ISeekable

Enumeration values:
Begin 
Current 
End 

Definition at line 295 of file IConduit.d.


Member Function Documentation

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

Create a FileConduit with the provided path and style.

Definition at line 254 of file FileConduit.d.

References FilePath.

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

Create a FileConduit from the provided proxy and style.

Definition at line 265 of file FileConduit.d.

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

Create a FileConduit with the provided path and style.

Definition at line 276 of file FileConduit.d.

References path.

FilePath getPath  )  [inline]
 

Return the FilePath used by this file.

Definition at line 294 of file FileConduit.d.

References path.

Referenced by ServletResponse::copyFile().

ulong getPosition  )  [inline]
 

Return the current file position.

Reimplemented from ISeekable.

Definition at line 305 of file FileConduit.d.

References ISeekable::seek().

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

ulong length  )  [inline]
 

Return the total length of this file.

Definition at line 316 of file FileConduit.d.

References getPosition(), and ISeekable::seek().

Referenced by ServletResponse::copyFile(), MappedBuffer::VersionWin32::this(), UnicodeFile(), 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 335 of file FileConduit.d.

References Conduit::close(), and FileConduit.

override char [] getName  )  [inline, protected]
 

Return the name used by this file.

Reimplemented from DeviceConduit.

Definition at line 352 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 245 of file Conduit.d.

References Buffer, and buffer.

uint read void[]  dst  )  [inline, inherited]
 

read from conduit into a target buffer

Reimplemented from IConduit.

Definition at line 177 of file Conduit.d.

References Conduit::filter, and IConduitFilter::reader().

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

uint write void[]  src  )  [inline, inherited]
 

write to conduit from a source buffer

Reimplemented from IConduit.

Definition at line 188 of file Conduit.d.

References Conduit::filter, and IConduitFilter::writer().

Referenced by Conduit::flush(), and DeviceConduit::VersionPosix::writer().

this ConduitStyle.Bits  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 69 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 Console::ConsoleConduit.

Definition at line 82 of file DeviceConduit.d.

void close  )  [inline, 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 98 of file DeviceConduit.d.

Referenced by FileBucket::close(), ServletResponse::copyFile(), Properties::load(), and UnicodeFileTemplate().

uint bufferSize  )  [inline, inherited]
 

Return a preferred size for buffering conduit I/O

Reimplemented from Conduit.

Definition at line 122 of file DeviceConduit.d.

ulong seek ulong  offset,
SeekAnchor  anchor = SeekAnchor.Begin
[inherited]
 

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

Referenced by FileBucket::Record::createBucket(), getPosition(), length(), FileBucket::Record::read(), FileBucket::this(), and FileBucket::Record::write().


Member Data Documentation

FilePath path [private]
 

Definition at line 241 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 Sat Dec 24 17:28:38 2005 for Mango by  doxygen 1.4.0