diff options
author | Benoit Foucher <benoit@zeroc.com> | 2006-11-17 15:10:01 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2006-11-17 15:10:01 +0000 |
commit | b888109a8b418c2c6e811366eab47be4e0ec9d61 (patch) | |
tree | 8deb20cefe723edd867750ff60d2403b1ba354da /cpp/src/IceGrid/FileCache.cpp | |
parent | Added support for viewing stderr/stdout files from nodes, registries, (diff) | |
download | ice-b888109a8b418c2c6e811366eab47be4e0ec9d61.tar.bz2 ice-b888109a8b418c2c6e811366eab47be4e0ec9d61.tar.xz ice-b888109a8b418c2c6e811366eab47be4e0ec9d61.zip |
Fix
Diffstat (limited to 'cpp/src/IceGrid/FileCache.cpp')
-rw-r--r-- | cpp/src/IceGrid/FileCache.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/cpp/src/IceGrid/FileCache.cpp b/cpp/src/IceGrid/FileCache.cpp new file mode 100644 index 00000000000..71087e0e899 --- /dev/null +++ b/cpp/src/IceGrid/FileCache.cpp @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <IceGrid/FileCache.h> +#include <IceGrid/Exception.h> + +#include <fstream> + +using namespace std; +using namespace IceGrid; + +FileCache::FileCache() +{ +} + +Ice::StringSeq +FileCache::read(const string& filename, Ice::Long offset, int count, Ice::Long& newOffset) +{ + ifstream is(filename.c_str()); + if(is.fail()) + { + throw FileNotAvailableException("failed to open file `" + filename + "'"); + } + + newOffset = offset; + is.seekg(0, ios::end); + if(offset >= is.tellg()) + { + newOffset = is.tellg(); + return Ice::StringSeq(); + } + + is.seekg(offset); + Ice::StringSeq lines; + for(int i = 0; i < count && is.good(); ++i) + { + assert(!is.eof()); + string line; + getline(is, line); + if(!is.fail()) + { + newOffset = is.tellg(); + assert(newOffset >= 0); + } + lines.push_back(line); + } + return lines; +} |