FileUtilities Class Reference

#include <file_utilities.h>

Public Types

using WriteDirectoryFilterDelegate = Delegate< Bool(const Url &url)>
 
using ReadDirectoryTreeReceiver = ValueReceiver< const Block< const String > &, Int64, const DataDictionary & >
 

Static Public Member Functions

static MAXON_METHOD Result< void > ReadFileToMemory (UrlOrInputStream &&name, WritableArrayInterface< Char > &arr)
 
static MAXON_METHOD Result< void > ReadUtfFile (UrlOrInputStream &&url, WritableArrayInterface< Utf32Char > &arr, UTFTEXT_OPTIONS::TEXTENCODING defaultDecoding=UTFTEXT_OPTIONS::TEXTENCODING::UTF8)
 
static MAXON_METHOD Result< void > WriteUtfFile (const Url &url, const ArrayInterface< Utf32Char > &arr, UTFTEXT_OPTIONS::TEXTENCODING encoding=UTFTEXT_OPTIONS::TEXTENCODING::UTF8, Bool dontWriteHeader=false)
 
static MAXON_METHOD Result< void > CompareFiles (UrlOrInputStream &&file1, UrlOrInputStream &&file2)
 
template<typename T >
static Result< void > ReadToArray (UrlOrInputStream &&url, BaseArray< T > &dest)
 
static MAXON_METHOD Result< void > CopyStream (const InputStreamRef &from, const OutputStreamRef &to)
 
static MAXON_METHOD Result< void > CopyStreamProgress (const InputStreamRef &from, const OutputStreamRef &to, const IoProgressDelegate &progress)
 
static MAXON_METHOD Result< void > CopyFileOrDirectory (const Url &from, const Url &to)
 
static MAXON_METHOD Result< void > CopyFileOrDirectory (const Url &from, const String &to, const WriteArchiveRef &archive)
 
static MAXON_METHOD Result< void > WriteDirectoryTree (const Url &root, UrlOrOutputStream &&out, const WriteDirectoryFilterDelegate &filterDelegate)
 
static MAXON_METHOD Result< BoolReadDirectoryTree (UrlOrInputStream &&in, const ReadDirectoryTreeReceiver &receiver)
 
static MAXON_METHOD Result< OutputStreamRef > CreateCStringOutputStream (CString &str, Int maxLength=LIMIT< Int >::MAX)
 
static MAXON_METHOD Result< OutputStreamRef > CreateNullOutputStream ()
 
static MAXON_METHOD Result< void > WriteArray (UrlOrOutputStream &&out, const Block< Char > &buffer)
 
static MAXON_METHOD Result< void > WriteString (UrlOrOutputStream &&out, const String &string, const StringEncodingRef &encoding=GetUtf8DefaultEncoder())
 
static MAXON_METHOD Result< StringReadString (UrlOrInputStream &&in, const StringDecodingRef &decoding=GetUtf8DefaultDecoder())
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (FileUtilities, MAXON_REFERENCE_STATIC, "net.maxon.interface.fileutilities", MAXON_IMPLEMENTATION_MODULE("net.maxon.kernel"))
 

Member Typedef Documentation

◆ WriteDirectoryFilterDelegate

return true to add file to index, false to ignore in index

◆ ReadDirectoryTreeReceiver

using ReadDirectoryTreeReceiver = ValueReceiver<const Block<const String>&, Int64, const DataDictionary&>

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( FileUtilities  ,
MAXON_REFERENCE_STATIC  ,
"net.maxon.interface.fileutilities"  ,
MAXON_IMPLEMENTATION_MODULE("net.maxon.kernel")   
)
private

◆ ReadFileToMemory()

static MAXON_METHOD Result<void> ReadFileToMemory ( UrlOrInputStream &&  name,
WritableArrayInterface< Char > &  arr 
)
static

Reads a file into memory.

Parameters
[in]nameName or Stream of the file.
[out]arrArray holding the memory, will be initialized inside.
Returns
OK on success.

◆ ReadUtfFile()

static MAXON_METHOD Result<void> ReadUtfFile ( UrlOrInputStream &&  url,
WritableArrayInterface< Utf32Char > &  arr,
UTFTEXT_OPTIONS::TEXTENCODING  defaultDecoding = UTFTEXT_OPTIONS::TEXTENCODING::UTF8 
)
static

Reads a file into memory. If an UTF encoding is detected the proper decoding takes place.

Parameters
[in]urlName or Stream of the file.
[out]arrArray holding the memory, will be initialized inside.
[in]defaultDecodingThe character decoding that will be used if the file does not contain any Byte Order Mark (BOM).
Returns
OK on success.

◆ WriteUtfFile()

static MAXON_METHOD Result<void> WriteUtfFile ( const Url url,
const ArrayInterface< Utf32Char > &  arr,
UTFTEXT_OPTIONS::TEXTENCODING  encoding = UTFTEXT_OPTIONS::TEXTENCODING::UTF8,
Bool  dontWriteHeader = false 
)
static

Writes a Utf32Char array from memory to disc in a UTF-encoded format.

Parameters
[in]urlThe file to be written.
[in]arrArray holding the data.
[in]encodingThe character encoding to be used.
[in]dontWriteHeaderIf true the utf8 header will not be written.
Returns
OK on success.

◆ CompareFiles()

static MAXON_METHOD Result<void> CompareFiles ( UrlOrInputStream &&  file1,
UrlOrInputStream &&  file2 
)
static

Compares the content of 2 files for binary equality.

Parameters
[in]file1Name or Stream of the file 1.
[in]file2Name or Stream of the file 2.
Returns
Success and result of the comparison. If the files don't match or cannot be read an error is returned.

◆ ReadToArray()

Result< void > ReadToArray ( UrlOrInputStream &&  url,
BaseArray< T > &  dest 
)
static

Reads stream directly into an array

Parameters
[in]urlpath to stream
[out]destBaseArray where the data is stored

◆ CopyStream()

static MAXON_METHOD Result<void> CopyStream ( const InputStreamRef &  from,
const OutputStreamRef &  to 
)
static

Copies all bytes from from to #to. This function reads bytes as long as possible. It doesn't call the Close() method on from or #to.

Parameters
[in]fromThe stream from which the bytes shall be read.
[in]toThe stream to which the bytes shall be written.
Returns
Success of operation.

◆ CopyStreamProgress()

static MAXON_METHOD Result<void> CopyStreamProgress ( const InputStreamRef &  from,
const OutputStreamRef &  to,
const IoProgressDelegate progress 
)
static

Copies all bytes from from to #to. This function reads bytes as long as possible. It doesn't call the Close() method on from or #to.

Parameters
[in]fromThe stream from which the bytes shall be read.
[in]toThe stream to which the bytes shall be written.
[in]progressProgress delegate which is called to notify about the progress.
Returns
Success of operation.

◆ CopyFileOrDirectory() [1/2]

static MAXON_METHOD Result<void> CopyFileOrDirectory ( const Url from,
const Url to 
)
static

Copies the file or directory from to #to. If it doesn't already exist, a file or directory is created for the Url #to. For a file its content is copied, for a directory a recursive copy happens. Symbolic links are skipped.

Parameters
[in]fromThe source Url.
[in]toThe destination Url.
Returns
Success of operation.

◆ CopyFileOrDirectory() [2/2]

static MAXON_METHOD Result<void> CopyFileOrDirectory ( const Url from,
const String to,
const WriteArchiveRef &  archive 
)
static

Copies the file or directory from into an archive #archive/#to. If it doesn't already exist, a file or directory is created for the Url #to. For a file its content is copied, for a directory a recursive copy happens. Symbolic links are skipped.

Parameters
[in]fromThe source Url.
[in]toThe relative destination Url in the archive.
[in]archiveArchive to write to.
Returns
Success of operation.

◆ WriteDirectoryTree()

static MAXON_METHOD Result<void> WriteDirectoryTree ( const Url root,
UrlOrOutputStream &&  out,
const WriteDirectoryFilterDelegate filterDelegate 
)
static

◆ ReadDirectoryTree()

static MAXON_METHOD Result<Bool> ReadDirectoryTree ( UrlOrInputStream &&  in,
const ReadDirectoryTreeReceiver receiver 
)
static

◆ CreateCStringOutputStream()

static MAXON_METHOD Result<OutputStreamRef> CreateCStringOutputStream ( CString str,
Int  maxLength = LIMITInt >::MAX 
)
static

Creates an output stream which writes to the given CString. Whenever bytes are written to the stream, these will be appended to str.

Parameters
[out]strThe string to write to. You have to keep the object alive as long as the stream is in use. Previously existing content of str is kept.
[in]maxLengthThe maximum length of the string. When this limit is exceeded, no further characters will be appended.
Returns
New output stream.

◆ CreateNullOutputStream()

static MAXON_METHOD Result<OutputStreamRef> CreateNullOutputStream ( )
static

Creates an output stream which just discards any bytes written to it without reporting errors (similar to the null device of operating systems, e.g. {/dev/null}).

Returns
New output stream.

◆ WriteArray()

static MAXON_METHOD Result<void> WriteArray ( UrlOrOutputStream &&  out,
const Block< Char > &  buffer 
)
static

◆ WriteString()

static MAXON_METHOD Result<void> WriteString ( UrlOrOutputStream &&  out,
const String string,
const StringEncodingRef &  encoding = GetUtf8DefaultEncoder() 
)
static

◆ ReadString()

static MAXON_METHOD Result<String> ReadString ( UrlOrInputStream &&  in,
const StringDecodingRef &  decoding = GetUtf8DefaultDecoder() 
)
static