0032455: Data Exchange - replace OSD_OpenStream() usage with OSD_FileSystem::DefaultF...
authormkrylova <mkrylova@opencascade.com>
Wed, 14 Jul 2021 12:06:35 +0000 (15:06 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 23 Jul 2021 15:28:23 +0000 (18:28 +0300)
- replaced OSD_OpenStream() usage with OSD_FileSystem::DefaultFileSystem()

17 files changed:
src/BRepTools/BRepTools.cxx
src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx
src/BinTools/BinTools.cxx
src/DBRep/DBRep.cxx
src/DDocStd/DDocStd_ApplicationCommands.cxx
src/Draw/Draw_VariableCommands.cxx
src/Image/Image_DDSParser.cxx
src/Image/Image_Texture.cxx
src/LDOM/LDOMParser.cxx
src/QABugs/QABugs_1.cxx
src/QABugs/QABugs_20.cxx
src/RWGltf/RWGltf_CafReader.cxx
src/RWGltf/RWGltf_CafWriter.cxx
src/RWStl/RWStl.cxx
src/RWStl/RWStl_Reader.cxx
src/TObjDRAW/TObjDRAW.cxx
src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx

index 61e7a90..156ca3f 100644 (file)
@@ -747,15 +747,16 @@ Standard_Boolean BRepTools::Read(TopoDS_Shape& Sh,
                                  const BRep_Builder& B,
                                  const Message_ProgressRange& theProgress)
 {
-  std::filebuf fic;
-  std::istream in(&fic);
-  OSD_OpenStream (fic, File, std::ios::in);
-  if(!fic.is_open()) return Standard_False;
-  
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (File, std::ios::in);
+  if (aStream.get() == NULL)
+  {
+    return Standard_False;
+  }
   BRepTools_ShapeSet SS(B);
-  SS.Read(in, theProgress);
+  SS.Read (*aStream, theProgress);
   if(!SS.NbShapes()) return Standard_False;
-  SS.Read(Sh,in);
+  SS.Read (Sh,*aStream);
   return Standard_True;
 }
 
index e50c315..b55f032 100644 (file)
@@ -27,7 +27,7 @@
 #include <Message_Messenger.hxx>
 #include <FSD_BinaryFile.hxx>
 #include <FSD_FileHeader.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <PCDM_Document.hxx>
 #include <PCDM_ReadWriter.hxx>
 #include <Standard_ErrorHandler.hxx>
@@ -77,15 +77,15 @@ void BinLDrivers_DocumentRetrievalDriver::Read
                           const Handle(PCDM_ReaderFilter)&  theFilter,
                           const Message_ProgressRange&      theRange)
 {
-  std::ifstream aFileStream;
-  OSD_OpenStream (aFileStream, theFileName, std::ios::in | std::ios::binary);
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::istream> aFileStream = aFileSystem->OpenIStream (theFileName, std::ios::in | std::ios::binary);
 
-  if (aFileStream.is_open() && aFileStream.good())
+  if (aFileStream.get() != NULL && aFileStream->good())
   {
     Handle(Storage_Data) dData;
-    TCollection_ExtendedString aFormat = PCDM_ReadWriter::FileFormat (aFileStream, dData);
+    TCollection_ExtendedString aFormat = PCDM_ReadWriter::FileFormat (*aFileStream, dData);
 
-    Read (aFileStream, dData, theNewDocument, theApplication, theFilter, theRange);
+    Read (*aFileStream, dData, theNewDocument, theApplication, theFilter, theRange);
     if (!theRange.More())
     {
       myReaderStatus = PCDM_RS_UserBreak;
index d5c5d3a..9bffcea 100644 (file)
@@ -17,6 +17,7 @@
 #include <BinTools.hxx>
 #include <BinTools_ShapeSet.hxx>
 #include <FSD_FileHeader.hxx>
+#include <OSD_FileSystem.hxx>
 #include <OSD_OpenFile.hxx>
 #include <Storage_StreamTypeMismatchError.hxx>
 
@@ -233,12 +234,13 @@ Standard_Boolean BinTools::Write (const TopoDS_Shape& theShape,
 Standard_Boolean BinTools::Read (TopoDS_Shape& theShape, const Standard_CString theFile,
                                  const Message_ProgressRange& theRange)
 {
-  std::filebuf aBuf;
-  OSD_OpenStream (aBuf, theFile, std::ios::in | std::ios::binary);
-  if (!aBuf.is_open())
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (theFile, std::ios::in | std::ios::binary);
+  if (aStream.get() == NULL)
+  {
     return Standard_False;
+  }
 
-  Standard_IStream aStream (&aBuf);
-  Read (theShape, aStream, theRange);
-  return aStream.good();
+  Read (theShape, *aStream, theRange);
+  return aStream->good();
 }
index 8e7e909..a13d586 100644 (file)
@@ -33,7 +33,7 @@
 #include <GProp.hxx>
 #include <GProp_GProps.hxx>
 #include <NCollection_Vector.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <Precision.hxx>
 #include <TColStd_Array1OfInteger.hxx>
 #include <TColStd_Array1OfReal.hxx>
@@ -1584,17 +1584,17 @@ static Standard_Integer readbrep (Draw_Interpretor& theDI,
   bool isBinaryFormat = true;
   {
     // probe file header to recognize format
-    std::ifstream aFile;
-    OSD_OpenStream (aFile, aFileName, std::ios::in | std::ios::binary);
-    if (!aFile.is_open())
+    const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+    opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (aFileName, std::ios::in | std::ios::binary);
+    if (aFile.get() == NULL)
     {
       theDI << "Error: cannot read the file '" << aFileName << "'";
       return 1;
     }
 
     char aStringBuf[255] = {};
-    aFile.read (aStringBuf, 255);
-    if (aFile.fail())
+    aFile->read (aStringBuf, 255);
+    if (aFile->fail())
     {
       theDI << "Error: cannot read the file '" << aFileName << "'";
       return 1;
index c923df9..a035d99 100644 (file)
@@ -33,6 +33,7 @@
 #include <TDF_Tool.hxx> 
 #include <PCDM_ReaderFilter.hxx>
 
+#include <OSD_FileSystem.hxx>
 #include <OSD_Path.hxx>
 #include <OSD_OpenFile.hxx>
 #include <TDocStd_PathParser.hxx>
@@ -179,10 +180,10 @@ static Standard_Integer DDocStd_Open (Draw_Interpretor& di,
     Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1);
     if (anUseStream)
     {
-      std::ifstream aFileStream;
-      OSD_OpenStream (aFileStream, path, std::ios::in | std::ios::binary);
+      const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+      opencascade::std::shared_ptr<std::istream> aFileStream = aFileSystem->OpenIStream (path, std::ios::in | std::ios::binary);
 
-      theStatus = A->Open (aFileStream, D, aFilter, aProgress->Start());
+      theStatus = A->Open (*aFileStream, D, aFilter, aProgress->Start());
     }
     else
     {
index 2dd7d81..bb502d7 100644 (file)
@@ -41,6 +41,7 @@ extern Draw_Viewer dout;
 #include <errno.h>
 
 #include <OSD_Environment.hxx>
+#include <OSD_FileSystem.hxx>
 #include <OSD_OpenFile.hxx>
 
 Standard_Boolean Draw_ParseFailed = Standard_True;
@@ -142,19 +143,17 @@ static Standard_Integer restore (Draw_Interpretor& theDI,
 
   const char* aFileName = theArgVec[1];
   const char* aVarName  = theArgVec[2];
-  
-  std::filebuf aFileBuf;
-  std::istream aStream (&aFileBuf);
-  OSD_OpenStream (aFileBuf, aFileName, std::ios::in);
-  if (!aFileBuf.is_open())
+
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (aFileName, std::ios::in);
+  if (aStream.get() == NULL)
   {
     theDI << "Error: cannot open file for reading: '" << aFileName << "'";
     return 1;
   }
-
   char aType[255] = {};
-  aStream >> aType;
-  if (aStream.fail())
+  *aStream >> aType;
+  if (aStream->fail())
   {
     theDI << "Error: cannot read file: '" << aFileName << "'";
     return 1;
@@ -163,12 +162,12 @@ static Standard_Integer restore (Draw_Interpretor& theDI,
   {
     Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
     Draw::SetProgressBar (aProgress);
-    Handle(Draw_Drawable3D) aDrawable = Draw_Drawable3D::Restore (aType, aStream);
+    Handle(Draw_Drawable3D) aDrawable = Draw_Drawable3D::Restore (aType, *aStream);
     if (aDrawable.IsNull())
     {
       // assume that this file stores a DBRep_DrawableShape variable
-      aStream.seekg (0, std::ios::beg);
-      aDrawable = Draw_Drawable3D::Restore ("DBRep_DrawableShape", aStream);
+      aStream->seekg (0, std::ios::beg);
+      aDrawable = Draw_Drawable3D::Restore ("DBRep_DrawableShape", *aStream);
     }
     if (aDrawable.IsNull())
     {
index 7addc93..c2716f4 100644 (file)
@@ -16,7 +16,7 @@
 #include <Image_PixMap.hxx>
 #include <Image_SupportedFormats.hxx>
 #include <Message.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(Image_CompressedPixMap, Standard_Transient)
 
@@ -67,21 +67,19 @@ Handle(Image_CompressedPixMap) Image_DDSParser::Load (const Handle(Image_Support
                                                       const Standard_Integer theFaceIndex,
                                                       const int64_t theFileOffset)
 {
-  std::ifstream aFile;
-  OSD_OpenStream (aFile, theFile.ToCString(), std::ios::in | std::ios::binary);
-
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (theFile, std::ios::in | std::ios::binary);
   char aHeader[128] = {};
-  if (!aFile.is_open()
-   || !aFile.good())
+  if (aFile.get() == NULL || !aFile->good())
   {
     return Handle(Image_CompressedPixMap)();
   }
   if (theFileOffset != 0)
   {
-    aFile.seekg ((std::streamoff )theFileOffset, std::ios::beg);
+    aFile->seekg ((std::streamoff )theFileOffset, std::ios::beg);
   }
-  aFile.read (aHeader, 128);
-  Standard_Size aNbReadBytes = (Standard_Size )aFile.gcount();
+  aFile->read (aHeader, 128);
+  Standard_Size aNbReadBytes = (Standard_Size )aFile->gcount();
   if (aNbReadBytes < 128
    || ::memcmp (aHeader, "DDS ", 4) != 0)
   {
@@ -115,11 +113,11 @@ Handle(Image_CompressedPixMap) Image_DDSParser::Load (const Handle(Image_Support
   const Standard_Size anOffset = aDef->FaceBytes() * theFaceIndex;
   if (anOffset != 0)
   {
-    aFile.seekg ((std::streamoff )anOffset, std::ios::cur);
+    aFile->seekg ((std::streamoff )anOffset, std::ios::cur);
   }
   Handle(NCollection_Buffer) aBuffer = new NCollection_Buffer (Image_PixMap::DefaultAllocator(), aDef->FaceBytes());
-  aFile.read ((char* )aBuffer->ChangeData(), aDef->FaceBytes());
-  aNbReadBytes = (Standard_Size )aFile.gcount();
+  aFile->read ((char* )aBuffer->ChangeData(), aDef->FaceBytes());
+  aNbReadBytes = (Standard_Size )aFile->gcount();
   if (aNbReadBytes < aDef->FaceBytes())
   {
     Message::SendFail (TCollection_AsciiString ("DDS Reader error - unable to read face #") + theFaceIndex + " data from file\n" + theFile);
index 7d1a168..df635ce 100644 (file)
@@ -19,6 +19,7 @@
 #include <Image_SupportedFormats.hxx>
 #include <Message.hxx>
 #include <Message_Messenger.hxx>
+#include <OSD_FileSystem.hxx>
 #include <OSD_OpenFile.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(Image_Texture, Standard_Transient)
@@ -185,22 +186,22 @@ Handle(Image_PixMap) Image_Texture::loadImageOffset (const TCollection_AsciiStri
     return Handle(Image_PixMap)();
   }
 
-  std::ifstream aFile;
-  OSD_OpenStream (aFile, thePath.ToCString(), std::ios::in | std::ios::binary);
-  if (!aFile)
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (thePath, std::ios::in | std::ios::binary);
+  if (aFile.get() == NULL)
   {
     Message::SendFail (TCollection_AsciiString ("Error: Image file '") + thePath + "' cannot be opened");
     return Handle(Image_PixMap)();
   }
-  aFile.seekg ((std::streamoff )theOffset, std::ios_base::beg);
-  if (!aFile.good())
+  aFile->seekg ((std::streamoff )theOffset, std::ios_base::beg);
+  if (!aFile->good())
   {
     Message::SendFail (TCollection_AsciiString ("Error: Image is defined with invalid file offset '") + thePath + "'");
     return Handle(Image_PixMap)();
   }
 
   Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
-  if (!anImage->Load (aFile, thePath))
+  if (!anImage->Load (*aFile, thePath))
   {
     return Handle(Image_PixMap)();
   }
@@ -251,24 +252,24 @@ TCollection_AsciiString Image_Texture::ProbeImageFileFormat() const
   }
   else
   {
-    std::ifstream aFileIn;
-    OSD_OpenStream (aFileIn, myImagePath.ToCString(), std::ios::in | std::ios::binary);
-    if (!aFileIn)
+    const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+    opencascade::std::shared_ptr<std::istream> aFileIn = aFileSystem->OpenIStream (myImagePath, std::ios::in | std::ios::binary);
+    if (aFileIn.get() == NULL)
     {
       Message::SendFail (TCollection_AsciiString ("Error: Unable to open file '") + myImagePath + "'");
       return false;
     }
     if (myOffset >= 0)
     {
-      aFileIn.seekg ((std::streamoff )myOffset, std::ios_base::beg);
-      if (!aFileIn.good())
+      aFileIn->seekg ((std::streamoff )myOffset, std::ios_base::beg);
+      if (!aFileIn->good())
       {
         Message::SendFail (TCollection_AsciiString ("Error: Image is defined with invalid file offset '") + myImagePath + "'");
         return false;
       }
     }
 
-    if (!aFileIn.read (aBuffer, THE_PROBE_SIZE))
+    if (!aFileIn->read (aBuffer, THE_PROBE_SIZE))
     {
       Message::SendFail (TCollection_AsciiString ("Error: unable to read image file '") + myImagePath + "'");
       return false;
@@ -355,9 +356,9 @@ Standard_Boolean Image_Texture::WriteImage (std::ostream& theStream,
     return true;
   }
 
-  std::ifstream aFileIn;
-  OSD_OpenStream (aFileIn, myImagePath.ToCString(), std::ios::in | std::ios::binary);
-  if (!aFileIn)
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::istream> aFileIn = aFileSystem->OpenIStream (myImagePath, std::ios::in | std::ios::binary);
+  if (aFileIn.get() == NULL)
   {
     Message::SendFail (TCollection_AsciiString ("Error: Unable to open file ") + myImagePath + "!");
     return false;
@@ -366,8 +367,8 @@ Standard_Boolean Image_Texture::WriteImage (std::ostream& theStream,
   int64_t aLen = myLength;
   if (myOffset >= 0)
   {
-    aFileIn.seekg ((std::streamoff )myOffset, std::ios_base::beg);
-    if (!aFileIn.good())
+    aFileIn->seekg ((std::streamoff )myOffset, std::ios_base::beg);
+    if (!aFileIn->good())
     {
       Message::SendFail (TCollection_AsciiString ("Error: Image is defined with invalid file offset '") + myImagePath + "'");
       return false;
@@ -375,9 +376,9 @@ Standard_Boolean Image_Texture::WriteImage (std::ostream& theStream,
   }
   else
   {
-    aFileIn.seekg (0, std::ios_base::end);
-    aLen = (int64_t )aFileIn.tellg();
-    aFileIn.seekg (0, std::ios_base::beg);
+    aFileIn->seekg (0, std::ios_base::end);
+    aLen = (int64_t )aFileIn->tellg();
+    aFileIn->seekg (0, std::ios_base::beg);
   }
 
   Standard_Integer aChunkSize = 4096;
@@ -388,7 +389,7 @@ Standard_Boolean Image_Texture::WriteImage (std::ostream& theStream,
     {
       aChunkSize = Standard_Integer(aLen - aChunkIter);
     }
-    if (!aFileIn.read ((char* )&aBuffer.ChangeFirst(), aChunkSize))
+    if (!aFileIn->read ((char* )&aBuffer.ChangeFirst(), aChunkSize))
     {
       Message::SendFail (TCollection_AsciiString ("Error: unable to read image file '") + myImagePath + "'");
       return false;
index adf8d9b..6ee1ecf 100644 (file)
@@ -24,7 +24,7 @@
 #include <LDOM_BasicText.hxx>
 #include <LDOM_CharReference.hxx>
 #include <TCollection_ExtendedString.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 
 #include <fcntl.h>
 #ifdef _MSC_VER
@@ -147,12 +147,12 @@ Standard_Boolean LDOMParser::parse (std::istream& anInput,
 
 Standard_Boolean LDOMParser::parse (const char * const aFileName)
 {
-  std::ifstream aFileStream;
-  OSD_OpenStream (aFileStream, aFileName, std::ios::in);
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::istream> aFileStream = aFileSystem->OpenIStream (aFileName, std::ios::in);
 
-  if (aFileStream.good())
+  if (aFileStream.get() != NULL && aFileStream->good())
   {
-    return parse (aFileStream);
+    return parse (*aFileStream);
   }
   else
   {
index 000446c..7890b3c 100644 (file)
@@ -389,7 +389,7 @@ static Standard_Integer OCC361bug (Draw_Interpretor& di, Standard_Integer nb, co
 
 #include <Graphic3d_Texture2Dmanual.hxx>
 #include <Image_AlienPixMap.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <Prs3d_ShadingAspect.hxx>
 #include <Standard_ArrayStreamBuffer.hxx>
 //=======================================================================
@@ -459,35 +459,34 @@ static Standard_Integer OCC30182 (Draw_Interpretor& , Standard_Integer theNbArgs
   }
   else
   {
-    std::ifstream aFile;
-    OSD_OpenStream (aFile, anImgPath.ToCString(), std::ios::in | std::ios::binary);
-    if (!aFile.is_open())
+    const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+    opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (anImgPath, std::ios::in | std::ios::binary);
+    if (aFile.get() == NULL)
     {
       std::cout << "Syntax error: image file '" << anImgPath << "' cannot be found\n";
       return 1;
     }
     if (anOffset != 0)
     {
-      aFile.seekg (anOffset);
+      aFile->seekg (anOffset);
     }
 
     if (aSrc == 2)
     {
-      aFile.seekg (0, std::ios::end);
-      Standard_Integer aLen = (Standard_Integer )aFile.tellg() - anOffset;
-      aFile.seekg (anOffset);
+      aFile->seekg (0, std::ios::end);
+      Standard_Integer aLen = (Standard_Integer )aFile->tellg() - anOffset;
+      aFile->seekg (anOffset);
       if (aLen <= 0)
       {
         std::cout << "Syntax error: wrong offset\n";
         return 1;
       }
       NCollection_Array1<Standard_Byte> aBuff (1, aLen);
-      if (!aFile.read ((char* )&aBuff.ChangeFirst(), aBuff.Size()))
+      if (!aFile->read ((char* )&aBuff.ChangeFirst(), aBuff.Size()))
       {
         std::cout << "Error: unable to read file\n";
         return 1;
       }
-      aFile.close();
       if (!anImage->Load (&aBuff.ChangeFirst(), aBuff.Size(), anImgPath))
       {
         return 0;
@@ -495,7 +494,7 @@ static Standard_Integer OCC30182 (Draw_Interpretor& , Standard_Integer theNbArgs
     }
     else
     {
-      if (!anImage->Load (aFile, anImgPath))
+      if (!anImage->Load (*aFile, anImgPath))
       {
         return 0;
       }
index 7c8391c..67da0fa 100644 (file)
@@ -2269,7 +2269,7 @@ static Standard_Integer OCC28829 (Draw_Interpretor&, Standard_Integer, const cha
 
 #include <NCollection_Buffer.hxx>
 #include <DDocStd_DrawDocument.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <Standard_ArrayStreamBuffer.hxx>
 #include <TDataStd_Name.hxx>
 #include <TDocStd_Application.hxx>
@@ -2290,22 +2290,22 @@ static Standard_Integer OCC28887 (Draw_Interpretor&, Standard_Integer theNbArgs,
   const TCollection_AsciiString aName     (theArgVec[2]);
   Handle(NCollection_Buffer) aBuffer;
   {
-    std::ifstream aFile;
-    OSD_OpenStream (aFile, aFilePath.ToCString(), std::ios::binary | std::ios::in);
-    if (!aFile.is_open())
+    const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+    opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (aFilePath, std::ios::binary | std::ios::in);
+    if (aFile.get() == NULL)
     {
       std::cout << "Error: input file '" << aFilePath << "' cannot be read\n";
       return 1;
     }
-    aFile.seekg (0, std::ios_base::end);
-    const int64_t aFileLength = int64_t (aFile.tellg());
+    aFile->seekg (0, std::ios_base::end);
+    const int64_t aFileLength = int64_t (aFile->tellg());
     if (aFileLength > int64_t (std::numeric_limits<ptrdiff_t>::max())
      || aFileLength < 1)
     {
       std::cout << "Error: input file '" << aFilePath << "' is too large\n";
       return 1;
     }
-    aFile.seekg (0, std::ios_base::beg);
+    aFile->seekg (0, std::ios_base::beg);
 
     aBuffer = new NCollection_Buffer (NCollection_BaseAllocator::CommonBaseAllocator());
     if (!aBuffer->Allocate (size_t(aFileLength)))
@@ -2314,8 +2314,8 @@ static Standard_Integer OCC28887 (Draw_Interpretor&, Standard_Integer theNbArgs,
       return 1;
     }
 
-    aFile.read ((char* )aBuffer->ChangeData(), aBuffer->Size());
-    if (!aFile.good())
+    aFile->read ((char* )aBuffer->ChangeData(), aBuffer->Size());
+    if (!aFile->good())
     {
       std::cout << "Error: input file '" << aFilePath << "' reading failure\n";
       return 1;
index 90f1b01..499ffdb 100644 (file)
@@ -23,7 +23,7 @@
 #include <Message_Messenger.hxx>
 #include <Message_ProgressScope.hxx>
 #include <OSD_CachedFileSystem.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <OSD_ThreadPool.hxx>
 
 #include <fstream>
@@ -189,10 +189,9 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t
   Message_ProgressScope aPSentry (theProgress, "Reading glTF", 2);
   aPSentry.Show();
 
-  std::ifstream aFile;
-  OSD_OpenStream (aFile, theFile.ToCString(), std::ios::in | std::ios::binary);
-  if (!aFile.is_open()
-   || !aFile.good())
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (theFile, std::ios::in | std::ios::binary);
+  if (aFile.get() == NULL || !aFile->good())
   {
     Message::SendFail (TCollection_AsciiString ("File '") + theFile + "' is not found");
     return false;
@@ -200,7 +199,7 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t
 
   bool isBinaryFile = false;
   char aGlbHeader[12] = {};
-  aFile.read (aGlbHeader, sizeof(aGlbHeader));
+  aFile->read (aGlbHeader, sizeof (aGlbHeader));
   int64_t aBinBodyOffset  = 0;
   int64_t aBinBodyLen     = 0;
   int64_t aJsonBodyOffset = 0;
@@ -219,7 +218,7 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t
       }
 
       char aHeader1[8] = {};
-      aFile.read (aHeader1, sizeof(aHeader1));
+      aFile->read (aHeader1, sizeof (aHeader1));
 
       const uint32_t* aSceneLen    = (const uint32_t* )(aHeader1 + 0);
       const uint32_t* aSceneFormat = (const uint32_t* )(aHeader1 + 4);
@@ -241,16 +240,16 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t
         Message::SendWarning (TCollection_AsciiString ("File '") + theFile + "' is written using unknown version " + int(*aVer));
       }
 
-      for (int aChunkIter = 0; !aFile.eof() && aChunkIter < 2; ++aChunkIter)
+      for (int aChunkIter = 0; !aFile->eof() && aChunkIter < 2; ++aChunkIter)
       {
         char aChunkHeader2[8] = {};
-        if (int64_t(aFile.tellg()) + int64_t(sizeof(aChunkHeader2)) > int64_t(*aLen))
+        if (int64_t (aFile->tellg()) + int64_t (sizeof (aChunkHeader2)) > int64_t (*aLen))
         {
           break;
         }
 
-        aFile.read (aChunkHeader2, sizeof(aChunkHeader2));
-        if (!aFile.good())
+        aFile->read (aChunkHeader2, sizeof (aChunkHeader2));
+        if (!aFile->good())
         {
           Message::SendFail (TCollection_AsciiString ("File '") + theFile + "' is written using unsupported format");
           return false;
@@ -260,26 +259,26 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t
         const uint32_t* aChunkType = (const uint32_t* )(aChunkHeader2 + 4);
         if (*aChunkType == 0x4E4F534A)
         {
-          aJsonBodyOffset = int64_t(aFile.tellg());
-          aJsonBodyLen    = int64_t(*aChunkLen);
+          aJsonBodyOffset = int64_t (aFile->tellg());
+          aJsonBodyLen    = int64_t (*aChunkLen);
         }
         else if (*aChunkType == 0x004E4942)
         {
-          aBinBodyOffset = int64_t(aFile.tellg());
-          aBinBodyLen    = int64_t(*aChunkLen);
+          aBinBodyOffset = int64_t (aFile->tellg());
+          aBinBodyLen    = int64_t (*aChunkLen);
         }
         if (*aChunkLen != 0)
         {
-          aFile.seekg (*aChunkLen, std::ios_base::cur);
+          aFile->seekg (*aChunkLen, std::ios_base::cur);
         }
       }
 
-      aFile.seekg ((std::streamoff )aJsonBodyOffset, std::ios_base::beg);
+      aFile->seekg ((std::streamoff )aJsonBodyOffset, std::ios_base::beg);
     }
   }
   else
   {
-    aFile.seekg (0, std::ios_base::beg);
+    aFile->seekg (0, std::ios_base::beg);
   }
 
   TCollection_AsciiString anErrPrefix = TCollection_AsciiString ("File '") + theFile + "' defines invalid glTF!\n";
@@ -303,7 +302,7 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t
 
 #ifdef HAVE_RAPIDJSON
   rapidjson::ParseResult aRes;
-  rapidjson::IStreamWrapper aFileStream (aFile);
+  rapidjson::IStreamWrapper aFileStream (*aFile);
   if (isBinaryFile)
   {
     aRes = aDoc.ParseStream<rapidjson::kParseStopWhenDoneFlag, rapidjson::UTF8<>, rapidjson::IStreamWrapper> (aFileStream);
index 3dedb7f..bf4e8d7 100644 (file)
@@ -18,6 +18,7 @@
 #include <Message_Messenger.hxx>
 #include <Message_ProgressScope.hxx>
 #include <NCollection_DataMap.hxx>
+#include <OSD_FileSystem.hxx>
 #include <OSD_OpenFile.hxx>
 #include <OSD_File.hxx>
 #include <OSD_Path.hxx>
@@ -724,19 +725,18 @@ bool RWGltf_CafWriter::writeJson (const Handle(TDocStd_Document)&  theDocument,
   if (aFullLen64 < std::numeric_limits<uint32_t>::max())
   {
     {
-      std::ifstream aBinFile;
-      OSD_OpenStream (aBinFile, myBinFileNameFull.ToCString(), std::ios::in | std::ios::binary);
-      if (!aBinFile.is_open()
-       || !aBinFile.good())
+      const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+      opencascade::std::shared_ptr<std::istream> aBinFile = aFileSystem->OpenIStream (myBinFileNameFull, std::ios::in | std::ios::binary);
+      if (aBinFile.get() == NULL || !aBinFile->good())
       {
         Message::SendFail (TCollection_AsciiString ("File '") + myBinFileNameFull + "' cannot be opened");
         return false;
       }
       char aBuffer[4096];
-      for (; aBinFile.good();)
+      for (; aBinFile->good();)
       {
-        aBinFile.read (aBuffer, 4096);
-        const Standard_Integer aReadLen = (Standard_Integer )aBinFile.gcount();
+        aBinFile->read (aBuffer, 4096);
+        const Standard_Integer aReadLen = (Standard_Integer )aBinFile->gcount();
         if (aReadLen == 0)
         {
           break;
index dd8cace..c830d77 100644 (file)
@@ -18,6 +18,7 @@
 #include <Message_ProgressScope.hxx>
 #include <NCollection_Vector.hxx>
 #include <OSD_File.hxx>
+#include <OSD_FileSystem.hxx>
 #include <OSD_OpenFile.hxx>
 #include <RWStl_Reader.hxx>
 
@@ -153,16 +154,15 @@ Handle(Poly_Triangulation) RWStl::ReadBinary (const OSD_Path& theFile,
   TCollection_AsciiString aPath;
   theFile.SystemName (aPath);
 
-  std::filebuf aBuf;
-  OSD_OpenStream (aBuf, aPath, std::ios::in | std::ios::binary);
-  if (!aBuf.is_open())
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (aPath, std::ios::in | std::ios::binary);
+  if (aStream.get() == NULL)
   {
     return Handle(Poly_Triangulation)();
   }
-  Standard_IStream aStream (&aBuf);
 
   Reader aReader;
-  if (!aReader.ReadBinary (aStream, theProgress))
+  if (!aReader.ReadBinary (*aStream, theProgress))
   {
     return Handle(Poly_Triangulation)();
   }
index 1ebfe92..69a70dc 100644 (file)
@@ -22,7 +22,7 @@
 #include <NCollection_DataMap.hxx>
 #include <NCollection_IncAllocator.hxx>
 #include <FSD_BinaryFile.hxx>
-#include <OSD_OpenFile.hxx>
+#include <OSD_FileSystem.hxx>
 #include <OSD_Timer.hxx>
 #include <Precision.hxx>
 #include <Standard_CLocaleSentry.hxx>
@@ -131,26 +131,23 @@ namespace
 Standard_Boolean RWStl_Reader::Read (const char* theFile,
                                      const Message_ProgressRange& theProgress)
 {
-  std::filebuf aBuf;
-  OSD_OpenStream (aBuf, theFile, std::ios::in | std::ios::binary);
-  if (!aBuf.is_open())
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (theFile, std::ios::in | std::ios::binary);
+  if (aStream.get() == NULL)
   {
     Message::SendFail (TCollection_AsciiString("Error: file '") + theFile + "' is not found");
     return Standard_False;
   }
-
-  Standard_IStream aStream (&aBuf);
-
   // get length of file to feed progress indicator in Ascii mode
-  aStream.seekg (0, aStream.end);
-  std::streampos theEnd = aStream.tellg();
-  aStream.seekg (0, aStream.beg);
+  aStream->seekg (0, aStream->end);
+  std::streampos theEnd = aStream->tellg();
+  aStream->seekg (0, aStream->beg);
 
   // binary STL files cannot be shorter than 134 bytes 
   // (80 bytes header + 4 bytes facet count + 50 bytes for one facet);
   // thus assume files shorter than 134 as Ascii without probing
   // (probing may bring stream to fail state if EOF is reached)
-  bool isAscii = ((size_t)theEnd < THE_STL_MIN_FILE_SIZE || IsAscii (aStream, true));
+  bool isAscii = ((size_t)theEnd < THE_STL_MIN_FILE_SIZE || IsAscii (*aStream, true));
 
   Standard_ReadLineBuffer aBuffer (THE_BUFFER_SIZE);
 
@@ -160,25 +157,25 @@ Standard_Boolean RWStl_Reader::Read (const char* theFile,
   // For this reason use infinite (logarithmic) progress scale,
   // but in special mode so that the first cycle will take ~ 70% of it
   Message_ProgressScope aPS (theProgress, NULL, 1, true);
-  while (aStream.good())
+  while (aStream->good())
   {
     if (isAscii)
     {
-      if (!ReadAscii (aStream, aBuffer, theEnd, aPS.Next(2)))
+      if (!ReadAscii (*aStream, aBuffer, theEnd, aPS.Next (2)))
       {
         break;
       }
     }
     else
     {
-      if (!ReadBinary (aStream, aPS.Next(2)))
+      if (!ReadBinary (*aStream, aPS.Next (2)))
       {
         break;
       }
     }
-    aStream >> std::ws; // skip any white spaces
+    *aStream >> std::ws; // skip any white spaces
   }
-  return ! aStream.fail();
+  return ! aStream->fail();
 }
 
 //==============================================================================
index 1a40073..a42e88f 100644 (file)
@@ -37,6 +37,7 @@
 
 #include <BinTObjDrivers.hxx>
 #include <XmlTObjDrivers.hxx>
+#include <OSD_FileSystem.hxx>
 #include <OSD_OpenFile.hxx>
 
 #include <stdio.h>
@@ -251,9 +252,9 @@ static Standard_Integer loadModel (Draw_Interpretor& di, Standard_Integer argc,
     aModel = new TObjDRAW_Model();
     if (anUseStream)
     {
-      std::ifstream aFileStream;
-      OSD_OpenStream (aFileStream, aPath, std::ios::in | std::ios::binary);
-      isLoaded = aModel->Load (aFileStream);
+      const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+      opencascade::std::shared_ptr<std::istream> aFileStream = aFileSystem->OpenIStream (aPath, std::ios::in | std::ios::binary);
+      isLoaded = aModel->Load (*aFileStream);
     }
     else
       isLoaded = aModel->Load (aPath);
index b554232..b931737 100644 (file)
@@ -22,8 +22,8 @@
 #include <LDOM_DocumentType.hxx>
 #include <LDOM_LDOMImplementation.hxx>
 #include <LDOMParser.hxx>
+#include <OSD_FileSystem.hxx>
 #include <OSD_Path.hxx>
-#include <OSD_OpenFile.hxx>
 #include <PCDM_Document.hxx>
 #include <PCDM_DOMHeaderParser.hxx>
 #include <Standard_Type.hxx>
@@ -175,12 +175,12 @@ void XmlLDrivers_DocumentRetrievalDriver::Read
   myReaderStatus = PCDM_RS_DriverFailure;
   myFileName = theFileName;
 
-  std::ifstream aFileStream;
-  OSD_OpenStream (aFileStream, myFileName, std::ios::in);
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::istream> aFileStream = aFileSystem->OpenIStream (myFileName, std::ios::in);
 
-  if (aFileStream.is_open() && aFileStream.good())
+  if (aFileStream.get() != NULL && aFileStream->good())
   {
-    Read (aFileStream, NULL, theNewDocument, theApplication, theFilter, theRange);
+    Read (*aFileStream, NULL, theNewDocument, theApplication, theFilter, theRange);
   }
   else
   {