0032490: Data Exchange - provide OSD_FileSystem::OpenOStream() for output streams
[occt.git] / src / BinTools / BinTools.cxx
index 9bffcea..686a0c6 100644 (file)
@@ -18,7 +18,6 @@
 #include <BinTools_ShapeSet.hxx>
 #include <FSD_FileHeader.hxx>
 #include <OSD_FileSystem.hxx>
-#include <OSD_OpenFile.hxx>
 #include <Storage_StreamTypeMismatchError.hxx>
 
 //=======================================================================
@@ -215,15 +214,15 @@ Standard_Boolean BinTools::Write (const TopoDS_Shape& theShape,
                                   const BinTools_FormatVersion theVersion,
                                   const Message_ProgressRange& theRange)
 {
-  std::ofstream aStream;
-  aStream.precision (15);
-  OSD_OpenStream (aStream, theFile, std::ios::out | std::ios::binary);
-  if (!aStream.good())
+  const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
+  opencascade::std::shared_ptr<std::ostream> aStream = aFileSystem->OpenOStream (theFile, std::ios::out | std::ios::binary);
+  aStream->precision (15);
+  if (aStream.get() == NULL || !aStream->good())
     return Standard_False;
 
-  Write (theShape, aStream, theWithTriangles, theWithNormals, theVersion, theRange);
-  aStream.close();
-  return aStream.good();
+  Write (theShape, *aStream, theWithTriangles, theWithNormals, theVersion, theRange);
+  aStream->flush();
+  return aStream->good();
 }
 
 //=======================================================================