#include <GZCSVPathWriter.h>
Public Member Functions | |
| STANDARD_TYPEDEF (sella::file::GZCSVPathWriter) | |
| GZCSVPathWriter (const std::string &path, char delimiter=DefaultDelimiter, char seperator=DefaultSeperator) THROWS(IOException) | |
| void | write (const std::vector< std::vector< std::string >> &data) THROWS(IOException) |
Static Public Attributes | |
| static const char * | FileSuffix = ".csv.gz" |
| The file suffix for matching files in the directory for reading. | |
| static const char | DefaultDelimiter = 0x1e |
| The default delimiter used between the fields of a record; the ASCII record seperator character. | |
| static const char | DefaultSeperator = 0x1d |
| The default seperator used between the records of a file; the ASCII group seperator character. | |
A GZIP compressed CSV path writer.
Definition at line 31 of file GZCSVPathWriter.h.
| GZCSVPathWriter::GZCSVPathWriter | ( | const std::string & | path, | |
| char | delimiter = DefaultDelimiter, |
|||
| char | seperator = DefaultSeperator | |||
| ) |
The base constructor for a path writer.
| [in] | path | The full path to write files to. |
| [in] | delimiter | The field delimiter character for files. |
| [in] | seperator | The record seperator character for files. |
| IOException | if the path cannot be opened for writing. |
Definition at line 28 of file GZCSVPathWriter.cpp.
00028 : 00029 path(path), 00030 00031 delimiter(delimiter), 00032 seperator(seperator), 00033 00034 sequence(::time(NULL) << 16) 00035 { 00036 /* Ensure the supplied path is valid. */ 00037 DIR * directory = ::opendir(this->path.c_str()); 00038 00039 if (directory == NULL) { 00040 THROW(IOException, "failed to open directory '%s' for writing", this->path.c_str()); 00041 } 00042 ::closedir(directory); 00043 00044 /* Remove any trailing slash characters from the path. */ 00045 while (*(this->path.rbegin()) == '/') { 00046 this->path.erase(this->path.length() - 1, 1); 00047 } 00048 }
| void GZCSVPathWriter::write | ( | const std::vector< std::vector< std::string >> & | data | ) |
Create a database file and write all supplied records to it.
| [in] | data | The vector which contains all records to write to a file. |
| IOException | if unabled to write any record for any reason. |
Definition at line 57 of file GZCSVPathWriter.cpp.
References FileSuffix.
00057 { 00058 char file[2][4096]; 00059 00060 snprintf(file[0], sizeof(file[0]), "%s/%08lx.%s-incomplete", this->path.c_str(), this->sequence, GZCSVPathWriter::FileSuffix); 00061 snprintf(file[1], sizeof(file[1]), "%s/%08lx.%s", this->path.c_str(), this->sequence++, GZCSVPathWriter::FileSuffix); 00062 00063 GZCSVFileWriter writer(file[0], this->delimiter, this->seperator); 00064 00065 for (auto iter = data.begin(); iter != data.end(); ++iter) { 00066 writer.write(*iter); 00067 } 00068 writer.close(file[1]); 00069 }
1.6.1