You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by om...@apache.org on 2018/05/03 20:44:07 UTC
orc git commit: ORC-357: Use orc::InputStream in getTimezoneByFilename
Repository: orc
Updated Branches:
refs/heads/master 48ba9241c -> 2d096b9ef
ORC-357: Use orc::InputStream in getTimezoneByFilename
Fixes #263
Signed-off-by: Owen O'Malley <om...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/orc/repo
Commit: http://git-wip-us.apache.org/repos/asf/orc/commit/2d096b9e
Tree: http://git-wip-us.apache.org/repos/asf/orc/tree/2d096b9e
Diff: http://git-wip-us.apache.org/repos/asf/orc/diff/2d096b9e
Branch: refs/heads/master
Commit: 2d096b9ef3e4f96fa3247b7da1a45fabcf988533
Parents: 48ba924
Author: rip-nsk <ri...@gmail.com>
Authored: Wed May 2 10:29:58 2018 -0700
Committer: Owen O'Malley <om...@apache.org>
Committed: Thu May 3 13:43:54 2018 -0700
----------------------------------------------------------------------
c++/src/Timezone.cc | 47 +++++++++--------------------------------------
1 file changed, 9 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/orc/blob/2d096b9e/c++/src/Timezone.cc
----------------------------------------------------------------------
diff --git a/c++/src/Timezone.cc b/c++/src/Timezone.cc
index 9d56d7f..42e8121 100644
--- a/c++/src/Timezone.cc
+++ b/c++/src/Timezone.cc
@@ -16,20 +16,16 @@
* limitations under the License.
*/
+#include "orc/OrcFile.hh"
#include "Timezone.hh"
#include <errno.h>
-#include <iostream>
-#include <fcntl.h>
#include <map>
#include <sstream>
#include <stdint.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/stat.h>
#include <time.h>
-#include <unistd.h>
namespace orc {
@@ -698,40 +694,15 @@ namespace orc {
if (itr != timezoneCache.end()) {
return *(itr->second).get();
}
- int in = open(filename.c_str(), O_RDONLY);
- if (in == -1) {
- std::stringstream buffer;
- buffer << "failed to open " << filename << " - " << strerror(errno);
- throw TimezoneError(buffer.str());
- }
- struct stat fileInfo;
- if (fstat(in, &fileInfo) == -1) {
- std::stringstream buffer;
- buffer << "failed to stat " << filename << " - " << strerror(errno);
- throw TimezoneError(buffer.str());
- }
- if ((fileInfo.st_mode & S_IFMT) != S_IFREG) {
- std::stringstream buffer;
- buffer << "non-file in tzfile reader " << filename;
- throw TimezoneError(buffer.str());
- }
- size_t size = static_cast<size_t>(fileInfo.st_size);
- std::vector<unsigned char> buffer(size);
- size_t posn = 0;
- while (posn < size) {
- ssize_t ret = read(in, &buffer[posn], size - posn);
- if (ret == -1) {
- throw TimezoneError(std::string("Failure to read timezone file ") +
- filename + " - " + strerror(errno));
- }
- posn += static_cast<size_t>(ret);
- }
- if (close(in) == -1) {
- std::stringstream err;
- err << "failed to close " << filename << " - " << strerror(errno);
- throw TimezoneError(err.str());
+ try {
+ ORC_UNIQUE_PTR<InputStream> file = readFile(filename);
+ size_t size = static_cast<size_t>(file->getLength());
+ std::vector<unsigned char> buffer(size);
+ file->read(&buffer[0], size, 0);
+ timezoneCache[filename] = std::shared_ptr<Timezone>(new TimezoneImpl(filename, buffer));
+ } catch(ParseError& err) {
+ throw TimezoneError(err.what());
}
- timezoneCache[filename] = std::shared_ptr<Timezone>(new TimezoneImpl(filename, buffer));
return *timezoneCache[filename].get();
}