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


Member Typedef Documentation

typedef Conduit copy copy
 

Definition at line 167 of file FileConduit.d.


Member Enumeration Documentation

enum SeekAnchor [inherited]
 

The anchor positions supported by ISeekable

Enumeration values:
Begin 
Current 
End 

Definition at line 518 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 175 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 186 of file FileConduit.d.

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

Create a FileConduit with the provided path and style.

Definition at line 197 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 220 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 242 of file FileConduit.d.

FilePath getPath  )  [inline]
 

Return the FilePath used by this file.

Definition at line 254 of file FileConduit.d.

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

References seek().

Referenced by length(), and FileConduit::Versionlinux::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 290 of file FileConduit.d.

References Buffer, and IBuffer::setConduit().

Referenced by testFile2(), testFile3(), testFile5(), testFileRegex(), VersionArrayReaderSupport::testToken4(), and Stdio::this().

long length  )  [inline]
 

Return the total length of this file.

Definition at line 306 of file FileConduit.d.

References getPosition(), and seek().

Referenced by ServletResponse::copyFile().

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 325 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 79 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 74 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 132 of file Conduit.d.

References IConduitSource::bind().

Referenced by testConduitFilters().

void attach IConduitSink  output  )  [inline, inherited]
 

Please refer to IConduit.attach for details

Reimplemented from IConduit.

Definition at line 144 of file Conduit.d.

References IConduitSink::bind().

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

Reimplemented from IConduitSink.

Definition at line 154 of file Conduit.d.

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

Reimplemented from IConduitSource.

Definition at line 162 of file Conduit.d.

void unbind  )  [inline, protected, inherited]
 

Reimplemented from IConduitSource.

Definition at line 170 of file Conduit.d.

int read IBuffer  target  )  [inline, inherited]
 

read from conduit into a target buffer

Reimplemented from IConduit.

Definition at line 180 of file Conduit.d.

Referenced by FileBucket::Record::read(), testDirectIO(), and testFile5().

int write IBuffer  source  )  [inline, inherited]
 

write to conduit from a source buffer

Reimplemented from IConduit.

Definition at line 193 of file Conduit.d.

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

bool isSeekable  )  [inline, inherited]
 

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

Reimplemented from IConduit.

Definition at line 212 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 223 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 234 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 246 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 266 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 280 of file Conduit.d.

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


The documentation for this class was generated from the following file:
Generated on Sun Nov 7 19:07:02 2004 for Mango by doxygen 1.3.6