1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0032455: Data Exchange - replace OSD_OpenStream() usage with OSD_FileSystem::DefaultFileSystem()

- replaced OSD_OpenStream() usage with OSD_FileSystem::DefaultFileSystem()
This commit is contained in:
mkrylova 2021-07-14 15:06:35 +03:00 committed by bugmaster
parent 000c21fa0c
commit ad3f20c684
17 changed files with 150 additions and 152 deletions

@ -747,15 +747,16 @@ Standard_Boolean BRepTools::Read(TopoDS_Shape& Sh,
const BRep_Builder& B, const BRep_Builder& B,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
std::filebuf fic; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
std::istream in(&fic); opencascade::std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (File, std::ios::in);
OSD_OpenStream (fic, File, std::ios::in); if (aStream.get() == NULL)
if(!fic.is_open()) return Standard_False; {
return Standard_False;
}
BRepTools_ShapeSet SS(B); BRepTools_ShapeSet SS(B);
SS.Read(in, theProgress); SS.Read (*aStream, theProgress);
if(!SS.NbShapes()) return Standard_False; if(!SS.NbShapes()) return Standard_False;
SS.Read(Sh,in); SS.Read (Sh,*aStream);
return Standard_True; return Standard_True;
} }

@ -27,7 +27,7 @@
#include <Message_Messenger.hxx> #include <Message_Messenger.hxx>
#include <FSD_BinaryFile.hxx> #include <FSD_BinaryFile.hxx>
#include <FSD_FileHeader.hxx> #include <FSD_FileHeader.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_FileSystem.hxx>
#include <PCDM_Document.hxx> #include <PCDM_Document.hxx>
#include <PCDM_ReadWriter.hxx> #include <PCDM_ReadWriter.hxx>
#include <Standard_ErrorHandler.hxx> #include <Standard_ErrorHandler.hxx>
@ -77,15 +77,15 @@ void BinLDrivers_DocumentRetrievalDriver::Read
const Handle(PCDM_ReaderFilter)& theFilter, const Handle(PCDM_ReaderFilter)& theFilter,
const Message_ProgressRange& theRange) const Message_ProgressRange& theRange)
{ {
std::ifstream aFileStream; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFileStream, theFileName, std::ios::in | std::ios::binary); 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; 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()) if (!theRange.More())
{ {
myReaderStatus = PCDM_RS_UserBreak; myReaderStatus = PCDM_RS_UserBreak;

@ -17,6 +17,7 @@
#include <BinTools.hxx> #include <BinTools.hxx>
#include <BinTools_ShapeSet.hxx> #include <BinTools_ShapeSet.hxx>
#include <FSD_FileHeader.hxx> #include <FSD_FileHeader.hxx>
#include <OSD_FileSystem.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_OpenFile.hxx>
#include <Storage_StreamTypeMismatchError.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, Standard_Boolean BinTools::Read (TopoDS_Shape& theShape, const Standard_CString theFile,
const Message_ProgressRange& theRange) const Message_ProgressRange& theRange)
{ {
std::filebuf aBuf; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aBuf, theFile, std::ios::in | std::ios::binary); opencascade::std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (theFile, std::ios::in | std::ios::binary);
if (!aBuf.is_open()) if (aStream.get() == NULL)
{
return Standard_False; return Standard_False;
}
Standard_IStream aStream (&aBuf); Read (theShape, *aStream, theRange);
Read (theShape, aStream, theRange); return aStream->good();
return aStream.good();
} }

@ -33,7 +33,7 @@
#include <GProp.hxx> #include <GProp.hxx>
#include <GProp_GProps.hxx> #include <GProp_GProps.hxx>
#include <NCollection_Vector.hxx> #include <NCollection_Vector.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_FileSystem.hxx>
#include <Precision.hxx> #include <Precision.hxx>
#include <TColStd_Array1OfInteger.hxx> #include <TColStd_Array1OfInteger.hxx>
#include <TColStd_Array1OfReal.hxx> #include <TColStd_Array1OfReal.hxx>
@ -1584,17 +1584,17 @@ static Standard_Integer readbrep (Draw_Interpretor& theDI,
bool isBinaryFormat = true; bool isBinaryFormat = true;
{ {
// probe file header to recognize format // probe file header to recognize format
std::ifstream aFile; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFile, aFileName, std::ios::in | std::ios::binary); opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (aFileName, std::ios::in | std::ios::binary);
if (!aFile.is_open()) if (aFile.get() == NULL)
{ {
theDI << "Error: cannot read the file '" << aFileName << "'"; theDI << "Error: cannot read the file '" << aFileName << "'";
return 1; return 1;
} }
char aStringBuf[255] = {}; char aStringBuf[255] = {};
aFile.read (aStringBuf, 255); aFile->read (aStringBuf, 255);
if (aFile.fail()) if (aFile->fail())
{ {
theDI << "Error: cannot read the file '" << aFileName << "'"; theDI << "Error: cannot read the file '" << aFileName << "'";
return 1; return 1;

@ -33,6 +33,7 @@
#include <TDF_Tool.hxx> #include <TDF_Tool.hxx>
#include <PCDM_ReaderFilter.hxx> #include <PCDM_ReaderFilter.hxx>
#include <OSD_FileSystem.hxx>
#include <OSD_Path.hxx> #include <OSD_Path.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_OpenFile.hxx>
#include <TDocStd_PathParser.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); Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1);
if (anUseStream) if (anUseStream)
{ {
std::ifstream aFileStream; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFileStream, path, std::ios::in | std::ios::binary); 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 else
{ {

@ -41,6 +41,7 @@ extern Draw_Viewer dout;
#include <errno.h> #include <errno.h>
#include <OSD_Environment.hxx> #include <OSD_Environment.hxx>
#include <OSD_FileSystem.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_OpenFile.hxx>
Standard_Boolean Draw_ParseFailed = Standard_True; Standard_Boolean Draw_ParseFailed = Standard_True;
@ -142,19 +143,17 @@ static Standard_Integer restore (Draw_Interpretor& theDI,
const char* aFileName = theArgVec[1]; const char* aFileName = theArgVec[1];
const char* aVarName = theArgVec[2]; const char* aVarName = theArgVec[2];
std::filebuf aFileBuf; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
std::istream aStream (&aFileBuf); opencascade::std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (aFileName, std::ios::in);
OSD_OpenStream (aFileBuf, aFileName, std::ios::in); if (aStream.get() == NULL)
if (!aFileBuf.is_open())
{ {
theDI << "Error: cannot open file for reading: '" << aFileName << "'"; theDI << "Error: cannot open file for reading: '" << aFileName << "'";
return 1; return 1;
} }
char aType[255] = {}; char aType[255] = {};
aStream >> aType; *aStream >> aType;
if (aStream.fail()) if (aStream->fail())
{ {
theDI << "Error: cannot read file: '" << aFileName << "'"; theDI << "Error: cannot read file: '" << aFileName << "'";
return 1; return 1;
@ -163,12 +162,12 @@ static Standard_Integer restore (Draw_Interpretor& theDI,
{ {
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1); Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
Draw::SetProgressBar (aProgress); Draw::SetProgressBar (aProgress);
Handle(Draw_Drawable3D) aDrawable = Draw_Drawable3D::Restore (aType, aStream); Handle(Draw_Drawable3D) aDrawable = Draw_Drawable3D::Restore (aType, *aStream);
if (aDrawable.IsNull()) if (aDrawable.IsNull())
{ {
// assume that this file stores a DBRep_DrawableShape variable // assume that this file stores a DBRep_DrawableShape variable
aStream.seekg (0, std::ios::beg); aStream->seekg (0, std::ios::beg);
aDrawable = Draw_Drawable3D::Restore ("DBRep_DrawableShape", aStream); aDrawable = Draw_Drawable3D::Restore ("DBRep_DrawableShape", *aStream);
} }
if (aDrawable.IsNull()) if (aDrawable.IsNull())
{ {

@ -16,7 +16,7 @@
#include <Image_PixMap.hxx> #include <Image_PixMap.hxx>
#include <Image_SupportedFormats.hxx> #include <Image_SupportedFormats.hxx>
#include <Message.hxx> #include <Message.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_FileSystem.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Image_CompressedPixMap, Standard_Transient) 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 Standard_Integer theFaceIndex,
const int64_t theFileOffset) const int64_t theFileOffset)
{ {
std::ifstream aFile; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFile, theFile.ToCString(), std::ios::in | std::ios::binary); opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (theFile, std::ios::in | std::ios::binary);
char aHeader[128] = {}; char aHeader[128] = {};
if (!aFile.is_open() if (aFile.get() == NULL || !aFile->good())
|| !aFile.good())
{ {
return Handle(Image_CompressedPixMap)(); return Handle(Image_CompressedPixMap)();
} }
if (theFileOffset != 0) if (theFileOffset != 0)
{ {
aFile.seekg ((std::streamoff )theFileOffset, std::ios::beg); aFile->seekg ((std::streamoff )theFileOffset, std::ios::beg);
} }
aFile.read (aHeader, 128); aFile->read (aHeader, 128);
Standard_Size aNbReadBytes = (Standard_Size )aFile.gcount(); Standard_Size aNbReadBytes = (Standard_Size )aFile->gcount();
if (aNbReadBytes < 128 if (aNbReadBytes < 128
|| ::memcmp (aHeader, "DDS ", 4) != 0) || ::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; const Standard_Size anOffset = aDef->FaceBytes() * theFaceIndex;
if (anOffset != 0) 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()); Handle(NCollection_Buffer) aBuffer = new NCollection_Buffer (Image_PixMap::DefaultAllocator(), aDef->FaceBytes());
aFile.read ((char* )aBuffer->ChangeData(), aDef->FaceBytes()); aFile->read ((char* )aBuffer->ChangeData(), aDef->FaceBytes());
aNbReadBytes = (Standard_Size )aFile.gcount(); aNbReadBytes = (Standard_Size )aFile->gcount();
if (aNbReadBytes < aDef->FaceBytes()) if (aNbReadBytes < aDef->FaceBytes())
{ {
Message::SendFail (TCollection_AsciiString ("DDS Reader error - unable to read face #") + theFaceIndex + " data from file\n" + theFile); Message::SendFail (TCollection_AsciiString ("DDS Reader error - unable to read face #") + theFaceIndex + " data from file\n" + theFile);

@ -19,6 +19,7 @@
#include <Image_SupportedFormats.hxx> #include <Image_SupportedFormats.hxx>
#include <Message.hxx> #include <Message.hxx>
#include <Message_Messenger.hxx> #include <Message_Messenger.hxx>
#include <OSD_FileSystem.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_OpenFile.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Image_Texture, Standard_Transient) IMPLEMENT_STANDARD_RTTIEXT(Image_Texture, Standard_Transient)
@ -185,22 +186,22 @@ Handle(Image_PixMap) Image_Texture::loadImageOffset (const TCollection_AsciiStri
return Handle(Image_PixMap)(); return Handle(Image_PixMap)();
} }
std::ifstream aFile; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFile, thePath.ToCString(), std::ios::in | std::ios::binary); opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (thePath, std::ios::in | std::ios::binary);
if (!aFile) if (aFile.get() == NULL)
{ {
Message::SendFail (TCollection_AsciiString ("Error: Image file '") + thePath + "' cannot be opened"); Message::SendFail (TCollection_AsciiString ("Error: Image file '") + thePath + "' cannot be opened");
return Handle(Image_PixMap)(); return Handle(Image_PixMap)();
} }
aFile.seekg ((std::streamoff )theOffset, std::ios_base::beg); aFile->seekg ((std::streamoff )theOffset, std::ios_base::beg);
if (!aFile.good()) if (!aFile->good())
{ {
Message::SendFail (TCollection_AsciiString ("Error: Image is defined with invalid file offset '") + thePath + "'"); Message::SendFail (TCollection_AsciiString ("Error: Image is defined with invalid file offset '") + thePath + "'");
return Handle(Image_PixMap)(); return Handle(Image_PixMap)();
} }
Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap(); Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
if (!anImage->Load (aFile, thePath)) if (!anImage->Load (*aFile, thePath))
{ {
return Handle(Image_PixMap)(); return Handle(Image_PixMap)();
} }
@ -251,24 +252,24 @@ TCollection_AsciiString Image_Texture::ProbeImageFileFormat() const
} }
else else
{ {
std::ifstream aFileIn; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFileIn, myImagePath.ToCString(), std::ios::in | std::ios::binary); opencascade::std::shared_ptr<std::istream> aFileIn = aFileSystem->OpenIStream (myImagePath, std::ios::in | std::ios::binary);
if (!aFileIn) if (aFileIn.get() == NULL)
{ {
Message::SendFail (TCollection_AsciiString ("Error: Unable to open file '") + myImagePath + "'"); Message::SendFail (TCollection_AsciiString ("Error: Unable to open file '") + myImagePath + "'");
return false; return false;
} }
if (myOffset >= 0) if (myOffset >= 0)
{ {
aFileIn.seekg ((std::streamoff )myOffset, std::ios_base::beg); aFileIn->seekg ((std::streamoff )myOffset, std::ios_base::beg);
if (!aFileIn.good()) if (!aFileIn->good())
{ {
Message::SendFail (TCollection_AsciiString ("Error: Image is defined with invalid file offset '") + myImagePath + "'"); Message::SendFail (TCollection_AsciiString ("Error: Image is defined with invalid file offset '") + myImagePath + "'");
return false; 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 + "'"); Message::SendFail (TCollection_AsciiString ("Error: unable to read image file '") + myImagePath + "'");
return false; return false;
@ -355,9 +356,9 @@ Standard_Boolean Image_Texture::WriteImage (std::ostream& theStream,
return true; return true;
} }
std::ifstream aFileIn; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFileIn, myImagePath.ToCString(), std::ios::in | std::ios::binary); opencascade::std::shared_ptr<std::istream> aFileIn = aFileSystem->OpenIStream (myImagePath, std::ios::in | std::ios::binary);
if (!aFileIn) if (aFileIn.get() == NULL)
{ {
Message::SendFail (TCollection_AsciiString ("Error: Unable to open file ") + myImagePath + "!"); Message::SendFail (TCollection_AsciiString ("Error: Unable to open file ") + myImagePath + "!");
return false; return false;
@ -366,8 +367,8 @@ Standard_Boolean Image_Texture::WriteImage (std::ostream& theStream,
int64_t aLen = myLength; int64_t aLen = myLength;
if (myOffset >= 0) if (myOffset >= 0)
{ {
aFileIn.seekg ((std::streamoff )myOffset, std::ios_base::beg); aFileIn->seekg ((std::streamoff )myOffset, std::ios_base::beg);
if (!aFileIn.good()) if (!aFileIn->good())
{ {
Message::SendFail (TCollection_AsciiString ("Error: Image is defined with invalid file offset '") + myImagePath + "'"); Message::SendFail (TCollection_AsciiString ("Error: Image is defined with invalid file offset '") + myImagePath + "'");
return false; return false;
@ -375,9 +376,9 @@ Standard_Boolean Image_Texture::WriteImage (std::ostream& theStream,
} }
else else
{ {
aFileIn.seekg (0, std::ios_base::end); aFileIn->seekg (0, std::ios_base::end);
aLen = (int64_t )aFileIn.tellg(); aLen = (int64_t )aFileIn->tellg();
aFileIn.seekg (0, std::ios_base::beg); aFileIn->seekg (0, std::ios_base::beg);
} }
Standard_Integer aChunkSize = 4096; Standard_Integer aChunkSize = 4096;
@ -388,7 +389,7 @@ Standard_Boolean Image_Texture::WriteImage (std::ostream& theStream,
{ {
aChunkSize = Standard_Integer(aLen - aChunkIter); 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 + "'"); Message::SendFail (TCollection_AsciiString ("Error: unable to read image file '") + myImagePath + "'");
return false; return false;

@ -24,7 +24,7 @@
#include <LDOM_BasicText.hxx> #include <LDOM_BasicText.hxx>
#include <LDOM_CharReference.hxx> #include <LDOM_CharReference.hxx>
#include <TCollection_ExtendedString.hxx> #include <TCollection_ExtendedString.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_FileSystem.hxx>
#include <fcntl.h> #include <fcntl.h>
#ifdef _MSC_VER #ifdef _MSC_VER
@ -147,12 +147,12 @@ Standard_Boolean LDOMParser::parse (std::istream& anInput,
Standard_Boolean LDOMParser::parse (const char * const aFileName) Standard_Boolean LDOMParser::parse (const char * const aFileName)
{ {
std::ifstream aFileStream; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFileStream, aFileName, std::ios::in); 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 else
{ {

@ -389,7 +389,7 @@ static Standard_Integer OCC361bug (Draw_Interpretor& di, Standard_Integer nb, co
#include <Graphic3d_Texture2Dmanual.hxx> #include <Graphic3d_Texture2Dmanual.hxx>
#include <Image_AlienPixMap.hxx> #include <Image_AlienPixMap.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_FileSystem.hxx>
#include <Prs3d_ShadingAspect.hxx> #include <Prs3d_ShadingAspect.hxx>
#include <Standard_ArrayStreamBuffer.hxx> #include <Standard_ArrayStreamBuffer.hxx>
//======================================================================= //=======================================================================
@ -459,35 +459,34 @@ static Standard_Integer OCC30182 (Draw_Interpretor& , Standard_Integer theNbArgs
} }
else else
{ {
std::ifstream aFile; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFile, anImgPath.ToCString(), std::ios::in | std::ios::binary); opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (anImgPath, std::ios::in | std::ios::binary);
if (!aFile.is_open()) if (aFile.get() == NULL)
{ {
std::cout << "Syntax error: image file '" << anImgPath << "' cannot be found\n"; std::cout << "Syntax error: image file '" << anImgPath << "' cannot be found\n";
return 1; return 1;
} }
if (anOffset != 0) if (anOffset != 0)
{ {
aFile.seekg (anOffset); aFile->seekg (anOffset);
} }
if (aSrc == 2) if (aSrc == 2)
{ {
aFile.seekg (0, std::ios::end); aFile->seekg (0, std::ios::end);
Standard_Integer aLen = (Standard_Integer )aFile.tellg() - anOffset; Standard_Integer aLen = (Standard_Integer )aFile->tellg() - anOffset;
aFile.seekg (anOffset); aFile->seekg (anOffset);
if (aLen <= 0) if (aLen <= 0)
{ {
std::cout << "Syntax error: wrong offset\n"; std::cout << "Syntax error: wrong offset\n";
return 1; return 1;
} }
NCollection_Array1<Standard_Byte> aBuff (1, aLen); 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"; std::cout << "Error: unable to read file\n";
return 1; return 1;
} }
aFile.close();
if (!anImage->Load (&aBuff.ChangeFirst(), aBuff.Size(), anImgPath)) if (!anImage->Load (&aBuff.ChangeFirst(), aBuff.Size(), anImgPath))
{ {
return 0; return 0;
@ -495,7 +494,7 @@ static Standard_Integer OCC30182 (Draw_Interpretor& , Standard_Integer theNbArgs
} }
else else
{ {
if (!anImage->Load (aFile, anImgPath)) if (!anImage->Load (*aFile, anImgPath))
{ {
return 0; return 0;
} }

@ -2269,7 +2269,7 @@ static Standard_Integer OCC28829 (Draw_Interpretor&, Standard_Integer, const cha
#include <NCollection_Buffer.hxx> #include <NCollection_Buffer.hxx>
#include <DDocStd_DrawDocument.hxx> #include <DDocStd_DrawDocument.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_FileSystem.hxx>
#include <Standard_ArrayStreamBuffer.hxx> #include <Standard_ArrayStreamBuffer.hxx>
#include <TDataStd_Name.hxx> #include <TDataStd_Name.hxx>
#include <TDocStd_Application.hxx> #include <TDocStd_Application.hxx>
@ -2290,22 +2290,22 @@ static Standard_Integer OCC28887 (Draw_Interpretor&, Standard_Integer theNbArgs,
const TCollection_AsciiString aName (theArgVec[2]); const TCollection_AsciiString aName (theArgVec[2]);
Handle(NCollection_Buffer) aBuffer; Handle(NCollection_Buffer) aBuffer;
{ {
std::ifstream aFile; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFile, aFilePath.ToCString(), std::ios::binary | std::ios::in); opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (aFilePath, std::ios::binary | std::ios::in);
if (!aFile.is_open()) if (aFile.get() == NULL)
{ {
std::cout << "Error: input file '" << aFilePath << "' cannot be read\n"; std::cout << "Error: input file '" << aFilePath << "' cannot be read\n";
return 1; return 1;
} }
aFile.seekg (0, std::ios_base::end); aFile->seekg (0, std::ios_base::end);
const int64_t aFileLength = int64_t (aFile.tellg()); const int64_t aFileLength = int64_t (aFile->tellg());
if (aFileLength > int64_t (std::numeric_limits<ptrdiff_t>::max()) if (aFileLength > int64_t (std::numeric_limits<ptrdiff_t>::max())
|| aFileLength < 1) || aFileLength < 1)
{ {
std::cout << "Error: input file '" << aFilePath << "' is too large\n"; std::cout << "Error: input file '" << aFilePath << "' is too large\n";
return 1; return 1;
} }
aFile.seekg (0, std::ios_base::beg); aFile->seekg (0, std::ios_base::beg);
aBuffer = new NCollection_Buffer (NCollection_BaseAllocator::CommonBaseAllocator()); aBuffer = new NCollection_Buffer (NCollection_BaseAllocator::CommonBaseAllocator());
if (!aBuffer->Allocate (size_t(aFileLength))) if (!aBuffer->Allocate (size_t(aFileLength)))
@ -2314,8 +2314,8 @@ static Standard_Integer OCC28887 (Draw_Interpretor&, Standard_Integer theNbArgs,
return 1; return 1;
} }
aFile.read ((char* )aBuffer->ChangeData(), aBuffer->Size()); aFile->read ((char* )aBuffer->ChangeData(), aBuffer->Size());
if (!aFile.good()) if (!aFile->good())
{ {
std::cout << "Error: input file '" << aFilePath << "' reading failure\n"; std::cout << "Error: input file '" << aFilePath << "' reading failure\n";
return 1; return 1;

@ -23,7 +23,7 @@
#include <Message_Messenger.hxx> #include <Message_Messenger.hxx>
#include <Message_ProgressScope.hxx> #include <Message_ProgressScope.hxx>
#include <OSD_CachedFileSystem.hxx> #include <OSD_CachedFileSystem.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_FileSystem.hxx>
#include <OSD_ThreadPool.hxx> #include <OSD_ThreadPool.hxx>
#include <fstream> #include <fstream>
@ -189,10 +189,9 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t
Message_ProgressScope aPSentry (theProgress, "Reading glTF", 2); Message_ProgressScope aPSentry (theProgress, "Reading glTF", 2);
aPSentry.Show(); aPSentry.Show();
std::ifstream aFile; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFile, theFile.ToCString(), std::ios::in | std::ios::binary); opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (theFile, std::ios::in | std::ios::binary);
if (!aFile.is_open() if (aFile.get() == NULL || !aFile->good())
|| !aFile.good())
{ {
Message::SendFail (TCollection_AsciiString ("File '") + theFile + "' is not found"); Message::SendFail (TCollection_AsciiString ("File '") + theFile + "' is not found");
return false; return false;
@ -200,7 +199,7 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t
bool isBinaryFile = false; bool isBinaryFile = false;
char aGlbHeader[12] = {}; char aGlbHeader[12] = {};
aFile.read (aGlbHeader, sizeof(aGlbHeader)); aFile->read (aGlbHeader, sizeof (aGlbHeader));
int64_t aBinBodyOffset = 0; int64_t aBinBodyOffset = 0;
int64_t aBinBodyLen = 0; int64_t aBinBodyLen = 0;
int64_t aJsonBodyOffset = 0; int64_t aJsonBodyOffset = 0;
@ -219,7 +218,7 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t
} }
char aHeader1[8] = {}; 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* aSceneLen = (const uint32_t* )(aHeader1 + 0);
const uint32_t* aSceneFormat = (const uint32_t* )(aHeader1 + 4); 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)); 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] = {}; 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; break;
} }
aFile.read (aChunkHeader2, sizeof(aChunkHeader2)); aFile->read (aChunkHeader2, sizeof (aChunkHeader2));
if (!aFile.good()) if (!aFile->good())
{ {
Message::SendFail (TCollection_AsciiString ("File '") + theFile + "' is written using unsupported format"); Message::SendFail (TCollection_AsciiString ("File '") + theFile + "' is written using unsupported format");
return false; return false;
@ -260,26 +259,26 @@ Standard_Boolean RWGltf_CafReader::performMesh (const TCollection_AsciiString& t
const uint32_t* aChunkType = (const uint32_t* )(aChunkHeader2 + 4); const uint32_t* aChunkType = (const uint32_t* )(aChunkHeader2 + 4);
if (*aChunkType == 0x4E4F534A) if (*aChunkType == 0x4E4F534A)
{ {
aJsonBodyOffset = int64_t(aFile.tellg()); aJsonBodyOffset = int64_t (aFile->tellg());
aJsonBodyLen = int64_t(*aChunkLen); aJsonBodyLen = int64_t (*aChunkLen);
} }
else if (*aChunkType == 0x004E4942) else if (*aChunkType == 0x004E4942)
{ {
aBinBodyOffset = int64_t(aFile.tellg()); aBinBodyOffset = int64_t (aFile->tellg());
aBinBodyLen = int64_t(*aChunkLen); aBinBodyLen = int64_t (*aChunkLen);
} }
if (*aChunkLen != 0) 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 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"; 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 #ifdef HAVE_RAPIDJSON
rapidjson::ParseResult aRes; rapidjson::ParseResult aRes;
rapidjson::IStreamWrapper aFileStream (aFile); rapidjson::IStreamWrapper aFileStream (*aFile);
if (isBinaryFile) if (isBinaryFile)
{ {
aRes = aDoc.ParseStream<rapidjson::kParseStopWhenDoneFlag, rapidjson::UTF8<>, rapidjson::IStreamWrapper> (aFileStream); aRes = aDoc.ParseStream<rapidjson::kParseStopWhenDoneFlag, rapidjson::UTF8<>, rapidjson::IStreamWrapper> (aFileStream);

@ -18,6 +18,7 @@
#include <Message_Messenger.hxx> #include <Message_Messenger.hxx>
#include <Message_ProgressScope.hxx> #include <Message_ProgressScope.hxx>
#include <NCollection_DataMap.hxx> #include <NCollection_DataMap.hxx>
#include <OSD_FileSystem.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_OpenFile.hxx>
#include <OSD_File.hxx> #include <OSD_File.hxx>
#include <OSD_Path.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()) if (aFullLen64 < std::numeric_limits<uint32_t>::max())
{ {
{ {
std::ifstream aBinFile; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aBinFile, myBinFileNameFull.ToCString(), std::ios::in | std::ios::binary); opencascade::std::shared_ptr<std::istream> aBinFile = aFileSystem->OpenIStream (myBinFileNameFull, std::ios::in | std::ios::binary);
if (!aBinFile.is_open() if (aBinFile.get() == NULL || !aBinFile->good())
|| !aBinFile.good())
{ {
Message::SendFail (TCollection_AsciiString ("File '") + myBinFileNameFull + "' cannot be opened"); Message::SendFail (TCollection_AsciiString ("File '") + myBinFileNameFull + "' cannot be opened");
return false; return false;
} }
char aBuffer[4096]; char aBuffer[4096];
for (; aBinFile.good();) for (; aBinFile->good();)
{ {
aBinFile.read (aBuffer, 4096); aBinFile->read (aBuffer, 4096);
const Standard_Integer aReadLen = (Standard_Integer )aBinFile.gcount(); const Standard_Integer aReadLen = (Standard_Integer )aBinFile->gcount();
if (aReadLen == 0) if (aReadLen == 0)
{ {
break; break;

@ -18,6 +18,7 @@
#include <Message_ProgressScope.hxx> #include <Message_ProgressScope.hxx>
#include <NCollection_Vector.hxx> #include <NCollection_Vector.hxx>
#include <OSD_File.hxx> #include <OSD_File.hxx>
#include <OSD_FileSystem.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_OpenFile.hxx>
#include <RWStl_Reader.hxx> #include <RWStl_Reader.hxx>
@ -153,16 +154,15 @@ Handle(Poly_Triangulation) RWStl::ReadBinary (const OSD_Path& theFile,
TCollection_AsciiString aPath; TCollection_AsciiString aPath;
theFile.SystemName (aPath); theFile.SystemName (aPath);
std::filebuf aBuf; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aBuf, aPath, std::ios::in | std::ios::binary); opencascade::std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (aPath, std::ios::in | std::ios::binary);
if (!aBuf.is_open()) if (aStream.get() == NULL)
{ {
return Handle(Poly_Triangulation)(); return Handle(Poly_Triangulation)();
} }
Standard_IStream aStream (&aBuf);
Reader aReader; Reader aReader;
if (!aReader.ReadBinary (aStream, theProgress)) if (!aReader.ReadBinary (*aStream, theProgress))
{ {
return Handle(Poly_Triangulation)(); return Handle(Poly_Triangulation)();
} }

@ -22,7 +22,7 @@
#include <NCollection_DataMap.hxx> #include <NCollection_DataMap.hxx>
#include <NCollection_IncAllocator.hxx> #include <NCollection_IncAllocator.hxx>
#include <FSD_BinaryFile.hxx> #include <FSD_BinaryFile.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_FileSystem.hxx>
#include <OSD_Timer.hxx> #include <OSD_Timer.hxx>
#include <Precision.hxx> #include <Precision.hxx>
#include <Standard_CLocaleSentry.hxx> #include <Standard_CLocaleSentry.hxx>
@ -131,26 +131,23 @@ namespace
Standard_Boolean RWStl_Reader::Read (const char* theFile, Standard_Boolean RWStl_Reader::Read (const char* theFile,
const Message_ProgressRange& theProgress) const Message_ProgressRange& theProgress)
{ {
std::filebuf aBuf; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aBuf, theFile, std::ios::in | std::ios::binary); opencascade::std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (theFile, std::ios::in | std::ios::binary);
if (!aBuf.is_open()) if (aStream.get() == NULL)
{ {
Message::SendFail (TCollection_AsciiString("Error: file '") + theFile + "' is not found"); Message::SendFail (TCollection_AsciiString("Error: file '") + theFile + "' is not found");
return Standard_False; return Standard_False;
} }
Standard_IStream aStream (&aBuf);
// get length of file to feed progress indicator in Ascii mode // get length of file to feed progress indicator in Ascii mode
aStream.seekg (0, aStream.end); aStream->seekg (0, aStream->end);
std::streampos theEnd = aStream.tellg(); std::streampos theEnd = aStream->tellg();
aStream.seekg (0, aStream.beg); aStream->seekg (0, aStream->beg);
// binary STL files cannot be shorter than 134 bytes // binary STL files cannot be shorter than 134 bytes
// (80 bytes header + 4 bytes facet count + 50 bytes for one facet); // (80 bytes header + 4 bytes facet count + 50 bytes for one facet);
// thus assume files shorter than 134 as Ascii without probing // thus assume files shorter than 134 as Ascii without probing
// (probing may bring stream to fail state if EOF is reached) // (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); 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, // For this reason use infinite (logarithmic) progress scale,
// but in special mode so that the first cycle will take ~ 70% of it // but in special mode so that the first cycle will take ~ 70% of it
Message_ProgressScope aPS (theProgress, NULL, 1, true); Message_ProgressScope aPS (theProgress, NULL, 1, true);
while (aStream.good()) while (aStream->good())
{ {
if (isAscii) if (isAscii)
{ {
if (!ReadAscii (aStream, aBuffer, theEnd, aPS.Next(2))) if (!ReadAscii (*aStream, aBuffer, theEnd, aPS.Next (2)))
{ {
break; break;
} }
} }
else else
{ {
if (!ReadBinary (aStream, aPS.Next(2))) if (!ReadBinary (*aStream, aPS.Next (2)))
{ {
break; break;
} }
} }
aStream >> std::ws; // skip any white spaces *aStream >> std::ws; // skip any white spaces
} }
return ! aStream.fail(); return ! aStream->fail();
} }
//============================================================================== //==============================================================================

@ -37,6 +37,7 @@
#include <BinTObjDrivers.hxx> #include <BinTObjDrivers.hxx>
#include <XmlTObjDrivers.hxx> #include <XmlTObjDrivers.hxx>
#include <OSD_FileSystem.hxx>
#include <OSD_OpenFile.hxx> #include <OSD_OpenFile.hxx>
#include <stdio.h> #include <stdio.h>
@ -251,9 +252,9 @@ static Standard_Integer loadModel (Draw_Interpretor& di, Standard_Integer argc,
aModel = new TObjDRAW_Model(); aModel = new TObjDRAW_Model();
if (anUseStream) if (anUseStream)
{ {
std::ifstream aFileStream; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFileStream, aPath, std::ios::in | std::ios::binary); opencascade::std::shared_ptr<std::istream> aFileStream = aFileSystem->OpenIStream (aPath, std::ios::in | std::ios::binary);
isLoaded = aModel->Load (aFileStream); isLoaded = aModel->Load (*aFileStream);
} }
else else
isLoaded = aModel->Load (aPath); isLoaded = aModel->Load (aPath);

@ -22,8 +22,8 @@
#include <LDOM_DocumentType.hxx> #include <LDOM_DocumentType.hxx>
#include <LDOM_LDOMImplementation.hxx> #include <LDOM_LDOMImplementation.hxx>
#include <LDOMParser.hxx> #include <LDOMParser.hxx>
#include <OSD_FileSystem.hxx>
#include <OSD_Path.hxx> #include <OSD_Path.hxx>
#include <OSD_OpenFile.hxx>
#include <PCDM_Document.hxx> #include <PCDM_Document.hxx>
#include <PCDM_DOMHeaderParser.hxx> #include <PCDM_DOMHeaderParser.hxx>
#include <Standard_Type.hxx> #include <Standard_Type.hxx>
@ -175,12 +175,12 @@ void XmlLDrivers_DocumentRetrievalDriver::Read
myReaderStatus = PCDM_RS_DriverFailure; myReaderStatus = PCDM_RS_DriverFailure;
myFileName = theFileName; myFileName = theFileName;
std::ifstream aFileStream; const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
OSD_OpenStream (aFileStream, myFileName, std::ios::in); 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 else
{ {