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

FileConduit Class Reference

Inheritance diagram for FileConduit:

Conduit ISeekable List of all members.

Public Types

typedef Conduit copy copy

Public Member Functions

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

Protected Member Functions

override void closure ()

Private Types

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

Private Member Functions

 this (ConduitStyle style, bool seekable)
 this ()
abstract int reader (void[] dst)
abstract int writer (void[] src)
void attach (IConduitSource input)
void attach (IConduitSink output)
void bind (IConduitSink next)
void bind (IConduitSource next)
void unbind ()
int read (IBuffer target)
int write (IBuffer source)
bool isSeekable ()
bool isReadable ()
bool isWritable ()
IConduit copy (IConduit source)
IConduit flush (IBuffer source)
ConduitStyle getStyle ()
long seek (long offset, SeekAnchor anchor)

Private Attributes

FilePath path

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 factory for create 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 fc = new FileConduit ("test.txt"); // stream directly to console Stdio.stdout.copy (fc);

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 r = new Reader(fc); Writer w = new Writer(fc); int x=10, y=20; // write some data w.put(x).put(y); // flush output since IO is buffered w.flush(); // rewind to file start fc.seek (0); // read data back again, but swap destinations r.get(y).get(x); assert (y==10); assert (x==20); fc.close();

See FilePath, FileProxy, and FileSystem for additional functionality related to file manipulation. Note that classes CompositeWriter and CompositeReader may be more appropriate for the writing & reading of structured data. Doxygen has a hard time with D version() statements, so part of this class is documented within FileConduit::VersionWin32 instead.

Definition at line 177 of file FileConduit.d.


Member Typedef Documentation

typedef Conduit copy copy
 

Definition at line 183 of file FileConduit.d.


Member Enumeration Documentation

enum SeekAnchor [inherited]
 

The anchor positions supported by ISeekable

Enumeration values:
Begin 
Current 
End 

Definition at line 521 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 191 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 202 of file FileConduit.d.

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

Create a FileConduit with the provided path and style.

Definition at line 213 of file FileConduit.d.

References Resource::acquire().

package this FileDevice  device  )  [inline]
 

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

Definition at line 236 of file FileConduit.d.

References Resource::acquire().

override void closure  )  [inline, protected]
 

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

FilePath getPath  )  [inline]
 

Return the FilePath used by this file.

Definition at line 270 of file FileConduit.d.

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

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

long getPosition  )  [inline]
 

Return the current file position.

Reimplemented from ISeekable.

Definition at line 293 of file FileConduit.d.

References seek().

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

IBuffer createBuffer  )  [inline]
 

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

< default buffer size is 16K

Reimplemented from Conduit.

Definition at line 306 of file FileConduit.d.

References Buffer, and IBuffer::setConduit().

long length  )  [inline]
 

Return the total length of this file.

Definition at line 322 of file FileConduit.d.

References getPosition(), and seek().

Referenced by MappedFile::VersionWindows::this().

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

References FileConduit.

this ConduitStyle  style,
bool  seekable
[inline, inherited]
 

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

Definition at line 82 of file Conduit.d.

References Conduit::seekable.

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.

abstract int reader void[]  dst  )  [protected, pure virtual, inherited]
 

conduit-specific reader

Reimplemented from IConduitSource.

abstract int writer void[]  src  )  [protected, pure virtual, inherited]
 

conduit-specific writer

Reimplemented from IConduitSink.

void attach IConduitSource  input  )  [inline, inherited]
 

Please refer to IConduit.attach for details

Reimplemented from IConduit.

Definition at line 135 of file Conduit.d.

References IConduitSource::bind().

void attach IConduitSink  output  )  [inline, inherited]
 

Please refer to IConduit.attach for details

Reimplemented from IConduit.

Definition at line 147 of file Conduit.d.

References IConduitSink::bind().

void bind IConduitSink  next  )  [inline, protected, inherited]
 

Reimplemented from IConduitSink.

Definition at line 157 of file Conduit.d.

void bind IConduitSource  next  )  [inline, protected, inherited]
 

Reimplemented from IConduitSource.

Definition at line 165 of file Conduit.d.

void unbind  )  [inline, protected, inherited]
 

Reimplemented from IConduitSource.

Definition at line 173 of file Conduit.d.

int read IBuffer  target  )  [inline, inherited]
 

read from conduit into a target buffer

Reimplemented from IConduit.

Definition at line 183 of file Conduit.d.

References assert().

Referenced by FileBucket::Record::read().

int write IBuffer  source  )  [inline, inherited]
 

write to conduit from a source buffer

Reimplemented from IConduit.

Definition at line 196 of file Conduit.d.

References assert().

Referenced by Conduit::copy(), and Conduit::flush().

bool isSeekable  )  [inline, inherited]
 

Returns true if this conduit is seekable (whether it implements ISeekable)

Reimplemented from IConduit.

Definition at line 215 of file Conduit.d.

References Conduit::seekable.

bool isReadable  )  [inline, inherited]
 

Returns true is this conduit can be read from

Reimplemented from IConduit.

Definition at line 226 of file Conduit.d.

References ConduitStyle::access().

bool isWritable  )  [inline, inherited]
 

Returns true if this conduit can be written to

Reimplemented from IConduit.

Definition at line 237 of file Conduit.d.

References ConduitStyle::access().

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 249 of file Conduit.d.

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

IConduit flush IBuffer  source  )  [inline, inherited]
 

Flush buffer content out to this conduit.

Throws an IOException if flushing results in an Eof condition.

Reimplemented from IConduit.

Definition at line 269 of file Conduit.d.

References IBuffer::readable(), and Conduit::write().

Referenced by Conduit::copy(), and FileBucket::Record::write().

ConduitStyle getStyle  )  [inline, inherited]
 

Return the style used when creating this conduit

Definition at line 283 of file Conduit.d.

Referenced by MappedFile::VersionWindows::this().

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


The documentation for this class was generated from the following file:
Generated on Sun Mar 6 00:31:08 2005 for Mango by doxygen 1.3.6