Inheritance diagram for FileConduit:
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 |
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.
|
Definition at line 167 of file FileConduit.d. |
|
The anchor positions supported by ISeekable Definition at line 518 of file IConduit.d. |
|
Create a FileConduit with the provided path and style. Definition at line 175 of file FileConduit.d. References FilePath. |
|
Create a FileConduit from the provided proxy and style. Definition at line 186 of file FileConduit.d. |
|
Create a FileConduit with the provided path and style. Definition at line 197 of file FileConduit.d. References Resource::acquire(). |
|
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(). |
|
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. |
|
Return the FilePath used by this file. Definition at line 254 of file FileConduit.d. 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 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(). |
|
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(). |
|
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(). |
|
Return the total length of this file. Definition at line 306 of file FileConduit.d. References getPosition(), and seek(). Referenced by ServletResponse::copyFile(). |
|
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. |
|
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. |
|
Set the default lock to be this object Reimplemented in DatagramSocket, and SocketConduit. Definition at line 74 of file Resource.d. References Resource::_lock. |
|
conduit-specific reader Reimplemented from IConduitSource. |
|
conduit-specific writer Reimplemented from IConduitSink. |
|
Please refer to IConduit.attach for details Reimplemented from IConduit. Definition at line 132 of file Conduit.d. References IConduitSource::bind(). Referenced by testConduitFilters(). |
|
Please refer to IConduit.attach for details Reimplemented from IConduit. Definition at line 144 of file Conduit.d. References IConduitSink::bind(). |
|
Reimplemented from IConduitSink. |
|
Reimplemented from IConduitSource. |
|
Reimplemented from IConduitSource. |
|
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(). |
|
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(). |
|
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. |
|
Returns true is this conduit can be read from Reimplemented from IConduit. Definition at line 223 of file Conduit.d. References ConduitStyle::access(). |
|
Returns true if this conduit can be written to Reimplemented from IConduit. Definition at line 234 of file Conduit.d. References ConduitStyle::access(). |
|
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(). |
|
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(). |
|
Return the style used when creating this conduit |
|
Move the file position to the given offset from the provided anchor point, and return the adjusted position. |
|
Definition at line 164 of file FileConduit.d. |