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:

注意
To append to the end of a file use the flags maxon::OPENSTREAMFLAGS::WRITE_DONT_TRUNCATE and maxon::OPENSTREAMFLAGS::SEEK_TO_END .
// This example writes a maxon::String into a local file.

// 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 ;

if (isHTTP || isHTTPS) { // read data

// input stream const maxon::InputStreamRef inputStream = webFile.OpenInputStream() iferr_return ; const maxon::Int length = inputStream.GetStreamLength() iferr_return ;

maxon::BaseArray<maxon::Char> data; data. Resize (length) iferr_return ; inputStream.Read(data) iferr_return ; inputStream.Close() 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 ; }

延伸阅读

maxon::IODETECT::NONEXISTENT
@ NONEXISTENT
Url doesn't exist.
maxon::String
定义: string.h:1197
maxon::BaseArray::Resize
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
定义: basearray.h:1077
maxon::Bool
bool Bool
boolean type, possible values are only false/true, 8 bit
定义: apibase.h:177
maxon::Id
定义: apibaseid.h:250
iferr_return
#define iferr_return
定义: resultbase.h:1434
maxon::URLSCHEME_HTTPS
static const Id URLSCHEME_HTTPS
定义: url.h:663
maxon::BaseArray
定义: basearray.h:366
maxon::Url
定义: url.h:819
maxon::URLSCHEME_HTTP
static const Id URLSCHEME_HTTP
定义: url.h:658
maxon::Int
Int64 Int
signed 32/64 bit int, size depends on the platform
定义: apibase.h:184

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1