0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LoadDataSourceFileLocal.cc
Go to the documentation of this file.
1 
22 #include "Common/Compat.h"
23 #include <fstream>
24 #include <iostream>
25 #include <cerrno>
26 #include <cctype>
27 #include <cstdlib>
28 #include <cstring>
29 
30 #include <boost/algorithm/string.hpp>
31 #include <boost/algorithm/string/predicate.hpp>
32 #include <boost/iostreams/filter/gzip.hpp>
33 #include <boost/shared_array.hpp>
34 
35 extern "C" {
36 #include <strings.h>
37 #include <sys/types.h>
38 #include <unistd.h>
39 }
40 
41 #include "Common/DynamicBuffer.h"
42 #include "Common/Error.h"
43 #include "Common/Logger.h"
44 #include "Common/FileUtils.h"
45 
46 #include "Key.h"
48 
49 using namespace boost::iostreams;
50 using namespace Hypertable;
51 using namespace std;
52 
56 LoadDataSourceFileLocal::LoadDataSourceFileLocal(const string &fname,
57  const string &header_fname, int row_uniquify_chars, int load_flags)
58  : LoadDataSource(header_fname, row_uniquify_chars, load_flags),
59  m_source(fname), m_fname(fname) {
60 
61  if (!FileUtils::exists(fname.c_str()))
63 
64  if (boost::algorithm::ends_with(fname, ".gz")) {
65  m_fin.push(gzip_decompressor());
66  m_zipped = true;
67  }
68 
69  return;
70 }
71 
72 void
74 {
75  m_fin.push(m_source);
77 }
78 
82 uint64_t
84 {
85  uint64_t consumed=0;
86  uint64_t new_offset = m_source.seek(0, BOOST_IOS::cur);
87  consumed = new_offset - m_offset;
88  m_offset = new_offset;
89  return consumed;
90 }
91 
static bool exists(const String &fname)
Checks if a file or directory exists.
Definition: FileUtils.cc:420
STL namespace.
static uint64_t size(const String &fname)
Returns the size of a file (0 on error)
Definition: FileUtils.cc:450
File system utility functions.
A dynamic, resizable memory buffer.
boost::iostreams::filtering_istream m_fin
Logging routines and macros.
Compatibility Macros for C/C++.
Hypertable definitions
boost::iostreams::file_source m_source
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
Definition: Error.h:478