Inheritance diagram for FileConduit:
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 |
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.
|
Reimplemented from DeviceConduit. Definition at line 206 of file FileConduit.d. |
|
Reimplemented from DeviceConduit. Definition at line 207 of file FileConduit.d. |
|
Reimplemented from DeviceConduit. Definition at line 208 of file FileConduit.d. |
|
The anchor positions supported by ISeekable Definition at line 527 of file IConduit.d. |
|
Create a FileConduit with the provided path and style. Definition at line 216 of file FileConduit.d. References FilePath. |
|
Create a FileConduit from the provided proxy and style. Definition at line 227 of file FileConduit.d. |
|
Create a FileConduit with the provided path and style. Definition at line 238 of file FileConduit.d. References Resource::acquire(), and path. |
|
Return the FilePath used by this file. Definition at line 260 of file FileConduit.d. References path. Referenced by ServletResponse::copyFile(). |
|
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(), testConduitFilters(), testDirectIO(), VersionMappedFile::testMappedFile(), testRandomAccess(), FileBucket::this(), and FileBucket::Record::write(). |
|
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(). |
|
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(). |
|
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 fc, and FileConduit. |
|
Return the name used by this file. Reimplemented from DeviceConduit. Definition at line 326 of file FileConduit.d. References path, and FilePath::toString(). |
|
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(). |
|
conduit-specific reader Reimplemented from IConduit. Referenced by DeviceConduit::VersionPosix::read(). |
|
read from conduit into a target buffer Reimplemented from IConduit. Definition at line 184 of file Conduit.d. References assert(). |
|
conduit-specific writer Reimplemented from IConduit. Referenced by Conduit::copy(), and DeviceConduit::VersionPosix::write(). |
|
write to conduit from a source buffer Reimplemented from IConduit. Definition at line 197 of file Conduit.d. References assert(). |
|
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. |
|
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(). |
|
Set the default lock to be this object Reimplemented in DatagramSocket, and SocketConduit. Definition at line 77 of file Resource.d. References Resource::_lock. |
|
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. |
|
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(), testTeqParser(), and testToken4(). |
|
Move the file position to the given offset from the provided anchor point, and return the adjusted position. |
|
Definition at line 203 of file FileConduit.d. Referenced by getName(), getPath(), FileConduit::VersionPosix::open(), FileConduit::VersionWin32::open(), and this(). |