#include <FileAccessor.h>
Inheritance diagram for Core::FileAccessor:
Public Member Functions | |
FileAccessor (int fd) | |
Creates FileAccessor instance on existing and openned file descriptor. | |
FileAccessor (String *pathname, int rwMode, int creationRule) | |
Creates FileAccessor instance on file specified by path and name. | |
FileAccessor (const char *pathname, int rwMode, int creationRule) | |
virtual String * | className (void) const |
Answer receiver class name. | |
virtual void | close (void) |
virtual void | commit (void) |
virtual long | dataSize (void) |
virtual LineEndConvention | lineEndConvention (void) |
virtual int | readInto (ByteArray *buffer) |
virtual int | readInto (ByteArray *buffer, long startIndex, long count) |
virtual int | writeFrom (ByteArray *buffer) |
virtual int | writeFrom (ByteArray *buffer, long startIndex, long count) |
virtual void | seekTo (long position) |
virtual void | changeDescriptorTo (int fd) |
Duplicates file descriptor to given number and then closes original one. | |
virtual bool | isSeekable (void) |
Static Public Member Functions | |
static FileAccessor * | openFileReadOnly (String *pathname) |
static FileAccessor * | openFileWriteOnly (String *pathname) |
Protected Attributes | |
String * | name |
Name (and optionally path) of the file. | |
int | descriptor |
File descriptor of openned file. |
|
Creates FileAccessor instance on existing and openned file descriptor. This constructor is provided for creating accessors to standard input (fd = 0), standard output (fd = 1) and standard error output (fd = 2). It should not be used in any application.
Definition at line 36 of file FileAccessor.cc. References descriptor, name, and nil. Referenced by openFileReadOnly(), and openFileWriteOnly(). 00037 { 00038 name = nil; 00039 descriptor = fd; 00040 }
|
|
Creates FileAccessor instance on file specified by path and name.
Definition at line 42 of file FileAccessor.cc. References Core::String::asCString(), descriptor, Core::Object::error(), name, and Core::GenericException::raise(). 00043 { 00044 name = pathname; 00045 descriptor = open(pathname->asCString(), rwMode | creationRule, 00046 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 00047 if (descriptor < 0) { 00048 FileOpenFailed *error; 00049 error = new FileOpenFailed(new String(sys_errlist[errno]), 00050 __PRETTY_FUNCTION__, pathname); 00051 error->raise(); 00052 } 00053 }
|
|
Definition at line 55 of file FileAccessor.cc. References descriptor, Core::Object::error(), name, nil, and Core::GenericException::raise(). 00056 { 00057 name = nil; 00058 descriptor = open(pathname, rwMode | creationRule, 00059 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 00060 if (descriptor < 0) { 00061 FileOpenFailed *error; 00062 error = new FileOpenFailed(new String(sys_errlist[errno]), 00063 __PRETTY_FUNCTION__, new String(pathname)); 00064 error->raise(); 00065 } 00066 }
|
|
Duplicates file descriptor to given number and then closes original one.
In fact it calls Reimplemented from Core::IOAccessor. Definition at line 138 of file FileAccessor.cc. References close(), and descriptor. Referenced by OS::Process::privateExecuteJob(). 00139 { 00140 dup2(descriptor, fd); 00141 close(); 00142 descriptor = fd; 00143 }
|
|
Answer receiver class name. Because there isn't any standard way to obtain class name this method comes to place. Every class should rewrite this method but many didn't (yet). Reimplemented from Core::IOAccessor. Definition at line 69 of file FileAccessor.cc. 00070 { 00071 return new String("FileAccessor"); 00072 }
|
|
Reimplemented from Core::IOAccessor. Definition at line 86 of file FileAccessor.cc. References descriptor. Referenced by changeDescriptorTo(), OS::UnixPipe::closeInput(), OS::UnixPipe::closeOutput(), and Tools::Filename::privateCopy(). 00087 { 00088 ::close(descriptor); 00089 descriptor = -1; 00090 }
|
|
Reimplemented from Core::IOAccessor. Definition at line 93 of file FileAccessor.cc. References descriptor. 00094 { 00095 fsync(descriptor); 00096 }
|
|
Reimplemented from Core::IOAccessor. Definition at line 98 of file FileAccessor.cc. References descriptor. 00099 { 00100 struct stat buf; 00101 fstat(descriptor, &buf); 00102 return buf.st_size; 00103 }
|
|
Reimplemented from Core::IOAccessor. Definition at line 146 of file FileAccessor.cc. 00147 { 00148 return true; 00149 }
|
|
Reimplemented from Core::IOAccessor. Definition at line 105 of file FileAccessor.cc. References Core::LineEndLF. 00106 { 00107 return LineEndLF; 00108 }
|
|
Definition at line 75 of file FileAccessor.cc. References FileAccessor(). 00076 { 00077 return new FileAccessor(pathname, O_RDONLY, 0); 00078 }
|
|
Definition at line 80 of file FileAccessor.cc. References FileAccessor(). 00081 { 00082 return new FileAccessor(pathname, O_WRONLY, O_CREAT | O_TRUNC); 00083 }
|
|
Reimplemented from Core::IOAccessor. Definition at line 111 of file FileAccessor.cc. References descriptor, Core::Object::error(), and Core::ByteArray::replace(). 00112 { 00113 unsigned char buf[count + 1]; 00114 long size; 00115 00116 size = read(descriptor, buf, count); 00117 if (size < 0) { 00118 perror(__PRETTY_FUNCTION__); 00119 error(new String("File read error"), new String(__PRETTY_FUNCTION__)); 00120 } 00121 buffer->replace(startIndex, startIndex+size, buf); 00122 return size; 00123 }
|
|
Reimplemented from Core::IOAccessor. Definition at line 78 of file FileAccessor.h. References Core::IOAccessor::readInto(). Referenced by Tools::Filename::privateCopy(), and OS::UnixPipe::readInto(). 00079 { return IOAccessor::readInto(buffer); }
|
|
Reimplemented from Core::IOAccessor. Definition at line 132 of file FileAccessor.cc. References descriptor. 00133 { 00134 lseek(descriptor, position, SEEK_SET); 00135 }
|
|
Reimplemented from Core::IOAccessor. Definition at line 125 of file FileAccessor.cc. References descriptor. 00126 { 00127 const unsigned char *buf = buffer->rawBytesReadOnly(); 00128 return write(descriptor, &buf[startIndex], count); 00129 }
|
|
Reimplemented from Core::IOAccessor. Definition at line 82 of file FileAccessor.h. References Core::IOAccessor::writeFrom(). Referenced by Tools::Filename::privateCopy(), and OS::UnixPipe::writeFrom(). 00083 { return IOAccessor::writeFrom(buffer); }
|
|
File descriptor of openned file.
Definition at line 41 of file FileAccessor.h. Referenced by changeDescriptorTo(), close(), commit(), dataSize(), FileAccessor(), readInto(), seekTo(), and writeFrom(). |
|
Name (and optionally path) of the file.
Definition at line 39 of file FileAccessor.h. Referenced by FileAccessor(). |