@@ -11,6 +11,9 @@ find files of those names at the top level of this repository. **/
1111#include " IString.h"
1212#include < iostream>
1313#include < fstream>
14+ #include < sstream>
15+
16+ #include " cpl_vsi.h"
1417
1518using namespace std ;
1619namespace Isis {
@@ -50,6 +53,36 @@ namespace Isis {
5053 * @throws Isis::iException::Io - Cannot open file
5154 */
5255 void FileList::read (FileName listFile) {
56+ QString path = listFile.toString ();
57+
58+ if (path.startsWith (" /vsi" )) {
59+ VSILFILE *fp = VSIFOpenL (path.toUtf8 ().constData (), " rb" );
60+ if (!fp) {
61+ QString message = Isis::Message::FileOpen (path);
62+ throw IException (IException::Io, message, _FILEINFO_);
63+ }
64+
65+ // Read the entire file in chunks (a cube list can be arbitrarily large,
66+ // so do not assume a fixed buffer size).
67+ std::string contents;
68+ char buffer[65536 ];
69+ size_t nRead;
70+ while ((nRead = VSIFReadL (buffer, 1 , sizeof (buffer), fp)) > 0 ) {
71+ contents.append (buffer, nRead);
72+ }
73+ VSIFCloseL (fp);
74+
75+ try {
76+ std::istringstream iss (contents);
77+ read (iss);
78+ }
79+ catch (IException &e) {
80+ QString msg = " File [" + path + " ] contains no data" ;
81+ throw IException (IException::User, msg, _FILEINFO_);
82+ }
83+ return ;
84+ }
85+
5386 // Open the file
5487 ifstream istm;
5588 istm.open (listFile.toString ().toLatin1 ().data (), std::ios::in);
@@ -156,6 +189,23 @@ namespace Isis {
156189 * @throws Isis::iException::Io File could not be created.
157190 */
158191 void FileList::write (FileName outputFileList) {
192+ QString path = outputFileList.toString ();
193+
194+ if (path.startsWith (" /vsi" )) {
195+ std::ostringstream oss;
196+ write (oss);
197+ std::string data = oss.str ();
198+
199+ VSILFILE *fp = VSIFOpenL (path.toUtf8 ().constData (), " wb" );
200+ if (!fp) {
201+ QString message = Message::FileOpen (path);
202+ throw IException (IException::Io, message, _FILEINFO_);
203+ }
204+ VSIFWriteL (data.data (), 1 , data.size (), fp);
205+ VSIFCloseL (fp);
206+ return ;
207+ }
208+
159209 // Open the file
160210 ofstream ostm;
161211 ostm.open (outputFileList.toString ().toLatin1 ().data (), std::ios::out);
0 commit comments