0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LoadDataSourceFileDfs.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
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"
47 #include "LoadDataSourceFileDfs.h"
48 
49 using namespace boost::iostreams;
50 using namespace Hypertable;
51 using namespace std;
52 
56 LoadDataSourceFileDfs::LoadDataSourceFileDfs(FsBroker::Lib::ClientPtr &client,
57  const string &fname, const string &header_fname, int row_uniquify_chars, int load_flags)
58  : LoadDataSource(header_fname, row_uniquify_chars, load_flags), m_cur_offset(0) {
59 
60  HT_ASSERT(client);
61  m_source = new FsBroker::Lib::FileSource(client, fname);
62 
63  if (boost::algorithm::ends_with(fname, ".gz")) {
64  m_fin.push(gzip_decompressor());
65  m_zipped = true;
66  }
67 
68  return;
69 }
70 
71 void
73 {
74  m_fin.push(*m_source);
76 }
77 
81 uint64_t
83 {
84  size_t new_offset = m_source->bytes_read();
85  uint64_t consumed = new_offset - m_cur_offset;
86  m_cur_offset = new_offset;
87  return consumed;
88 }
89 
STL namespace.
#define HT_ASSERT(_e_)
Definition: Logger.h:396
File system utility functions.
A dynamic, resizable memory buffer.
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
Definition: Client.h:233
boost::iostreams::filtering_istream m_fin
Logging routines and macros.
Compatibility Macros for C/C++.
Hypertable definitions
FsBroker::Lib::FileSource * m_source
Error codes, Exception handling, error logging.