OutputStream Manual
An output stream is used to write data to a resource defined with a maxon::Url . maxon::OutputStreamInterface is based on maxon::BaseStreamInterface .
maxon::BaseStreamInterface provides these simple functions:
// construct file URL const maxon::Url url = (targetFolder + maxon::Url ( "sometext.txt" _s)) iferr_return ;
// only proceed if file does not exist yet if (url.IoDetect() == maxon::IODETECT::NONEXISTENT ) { // define text const maxon::String data { "Hello World!" }; const maxon::BaseArray<maxon::Char> memory = data.GetCString() iferr_return ;
// write to file const maxon::OutputStreamRef stream = url.OpenOutputStream() iferr_return ; stream.Write(memory) iferr_return ; stream.Close() iferr_return ; }
// This example loads a file from the web and saves it to the local file system.
// check if the given URL references a file on the web const maxon::UrlScheme scheme = webFile.GetScheme(); const maxon::Bool isHTTP = scheme == maxon::URLSCHEME_HTTP ; const maxon::Bool isHTTPS = scheme == maxon::URLSCHEME_HTTPS ;
// input stream const maxon::InputStreamRef inputStream = webFile.OpenInputStream() iferr_return ; const maxon::Int length = inputStream.GetStreamLength() iferr_return ;
// save data to file
// prepare file name const maxon::Url localFile = (targetFolder + webFile.GetName()) iferr_return ; // output stream const maxon::OutputStreamRef outputStream = localFile.OpenOutputStream() iferr_return ; // write to file outputStream.Write(data) iferr_return ; outputStream.Close() iferr_return ; }