summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/FileCache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IceGrid/FileCache.cpp')
-rw-r--r--cpp/src/IceGrid/FileCache.cpp54
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;
+}