libhomegear-base
0.7
Base library for Homegear and Homegear family modules.
|
This class provides functions to make your life easier. More...
#include <Io.h>
Public Member Functions | |
Io () | |
Constructor. More... | |
virtual | ~Io () |
Destructor. More... | |
void | init (SharedObjects *baseLib) |
Initialized the object. More... | |
bool | copyFile (const std::string &source, const std::string &dest) |
Copys a file. More... | |
std::string | sha512 (const std::string &file) |
Calculates the SHA-2 SHA-512 of a given file. More... | |
Static Public Member Functions | |
static bool | directoryExists (const std::string &path) |
Checks if a directory exists. More... | |
static int32_t | isDirectory (const std::string &path, bool &result) |
Checks if a path is a directory. More... | |
static bool | linkExists (const std::string &path) |
Checks if a link exists. More... | |
static bool | createDirectory (const std::string &path, uint32_t mode) |
Creates a new directory. More... | |
static std::string | getFileContent (const std::string &filename) |
Reads a file and returns the content as a string. More... | |
static std::vector< char > | getBinaryFileContent (const std::string &filename, uint32_t maxBytes=0) |
Reads a file and returns the content as a signed binary array. More... | |
static std::vector< uint8_t > | getUBinaryFileContent (const std::string &filename) |
Reads a file and returns the content as an unsigned binary array. More... | |
static Security::SecureVector< uint8_t > | getUBinaryFileContentSecure (const std::string &filename) |
Reads a file and returns the content as an unsigned binary secure array, which is cleaned up automatically on destruction. More... | |
static bool | fileExists (const std::string &filename) |
Checks if a file exists. More... | |
static void | writeFile (const std::string &filename, const std::string &content) |
Writes a string to a file. More... | |
static void | writeFile (const std::string &filename, const std::vector< char > &content, uint32_t length) |
Writes binary data to a file. More... | |
static void | writeFile (const std::string &filename, const std::vector< uint8_t > &content, uint32_t length) |
Writes binary data to a file. More... | |
static void | appendToFile (const std::string &filename, const std::string &content) |
Writes binary data to a file. More... | |
static void | appendToFile (const std::string &filename, const std::vector< char > &content, uint32_t length) |
Writes binary data to a file. More... | |
static void | appendToFile (const std::string &filename, const std::vector< uint8_t > &content, uint32_t length) |
Writes binary data to a file. More... | |
static std::vector< std::string > | getFiles (const std::string &path, bool recursive=false) |
Returns an array of all files within a path. More... | |
static std::vector< std::string > | getDirectories (const std::string &path, bool recursive=false) |
Returns an array of all directories within a path. More... | |
static int32_t | getFileLastModifiedTime (const std::string &filename) |
Gets the last modified time of a file. More... | |
static bool | moveFile (const std::string &source, const std::string &dest) |
Moves a file. More... | |
static bool | deleteFile (const std::string &file) noexcept |
Deletes a file. More... | |
static bool | writeLockFile (int fileDescriptor, bool wait) |
Write locks a file using fcntl as defined in the Single Unix Specification. More... | |
static bool | readLockFile (int fileDescriptor, bool wait) |
Read locks a file using fcntl as defined in the Single Unix Specification. More... | |
This class provides functions to make your life easier.
BaseLib::Io::Io | ( | ) |
Constructor.
It does nothing. You need to call init() to initialize the object.
|
virtual |
Destructor.
Does nothing.
|
static |
Writes binary data to a file.
If the file doesn't exist, it will be created. If the file already exists the data will be appended.
filename | The path to the file to write. |
content | The content to write to the file. |
|
static |
Writes binary data to a file.
If the file doesn't exist, it will be created. If the file already exists the data will be appended.
filename | The path to the file to write. |
content | The content to write to the file. |
length | The number of bytes to write. |
|
static |
Writes binary data to a file.
If the file doesn't exist, it will be created. If the file already exists the data will be appended.
filename | The path to the file to write. |
content | The content to write to the file. |
length | The number of bytes to write. |
bool BaseLib::Io::copyFile | ( | const std::string & | source, |
const std::string & | dest | ||
) |
Copys a file.
source | The path to the file. |
dest | The destination path to copy the file to. |
|
static |
Creates a new directory.
Make sure, the directory doesn't exist.
path | The directory to create. |
mode | The creation mode. |
|
staticnoexcept |
Deletes a file.
file | The file to delete. |
|
static |
Checks if a directory exists.
path | The path to the directory. |
|
static |
Checks if a file exists.
filename | The path to the file. |
|
static |
Reads a file and returns the content as a signed binary array.
filename | The path to the file to read. |
maxBytes | Maximum number of bytes to read. |
|
static |
Returns an array of all directories within a path.
The directories are not prefixed with "path".
path | The path to get all directories for. |
recursive | Also return directories within subdirectories. The directories are prefixed with the subdirectory. |
|
static |
Reads a file and returns the content as a string.
filename | The path to the file to read. |
Throws | Exception on errors. |
|
static |
Gets the last modified time of a file.
filename | The file to get the last modified time for. |
|
static |
Returns an array of all files within a path.
The files are not prefixed with "path".
path | The path to get all files for. |
recursive | Also return files of subdirectories. The files are prefixed with the subdirectory. |
|
static |
Reads a file and returns the content as an unsigned binary array.
filename | The path to the file to read. |
|
static |
Reads a file and returns the content as an unsigned binary secure array, which is cleaned up automatically on destruction.
filename | The path to the file to read. |
void BaseLib::Io::init | ( | SharedObjects * | baseLib | ) |
Initialized the object.
baseLib | Pointer to the common base library object. |
|
static |
Checks if a path is a directory.
path | The path to check. | |
[out] | result | True when the path is a directory otherwise false |
|
static |
Checks if a link exists.
path | The path to check. |
|
static |
Moves a file.
source | The path to the file. |
dest | The destination path to move the file to. |
|
static |
Read locks a file using fcntl as defined in the Single Unix Specification.
Note that the file stays locked until the file descriptor is closed the first time.
fileDescriptor | The filedescriptor of the file to lock. |
wait | Wait for the lock to be acquired. |
std::string BaseLib::Io::sha512 | ( | const std::string & | file | ) |
Calculates the SHA-2 SHA-512 of a given file.
file | The file to calculate the SHA-512 for. |
|
static |
Writes a string to a file.
If the file already exists it will be overwritten.
filename | The path to the file to write. |
content | The content to write to the file. |
|
static |
Writes binary data to a file.
If the file already exists it will be overwritten.
filename | The path to the file to write. |
content | The content to write to the file. |
length | The number of bytes to write. |
|
static |
Writes binary data to a file.
If the file already exists it will be overwritten.
filename | The path to the file to write. |
content | The content to write to the file. |
length | The number of bytes to write. |
|
static |
Write locks a file using fcntl as defined in the Single Unix Specification.
Note that the file stays locked until the file descriptor is closed the first time.
fileDescriptor | The filedescriptor of the file to lock. |
wait | Wait for the lock to be acquired. |