CARMA C++
FileUtils.h
Go to the documentation of this file.
1 
13 #ifndef CARMA_UTIL_FILEUTILS_H
14 #define CARMA_UTIL_FILEUTILS_H
15 
16 #include "carma/util/StringUtils.h"
17 #include "carma/util/Time.h"
18 
19 #include <string>
20 #include <sys/stat.h>
21 #include <vector>
22 
23 namespace carma {
24  namespace util {
25 
32 class FileUtils {
33 public:
34 
41  static std::string computeMessageDigest(const std::string& fileName,
42  const DigestType& digestType);
43 
47  static std::string computeSha1Sum(const std::string& fileName);
48 
54  static bool exists(const std::string& fileName);
55 
62  static void rename( const std::string & from, const std::string & to );
63 
69  static void removeFile( const std::string & target );
70 
78  static void makeDirectory( const std::string & path,
79  mode_t mode = S_IRWXU | S_IRWXG | S_IROTH );
80 
87  static void hardLink( const std::string & target,
88  const std::string & link );
89 
97  static unsigned lineCount(const std::string& fileName);
98 
99 
103  static off_t size(const std::string& fileName);
104  static off64_t size64(const std::string& fileName);
105 
110  static std::string getError(const std::string& fileName);
111 
120  static time_t modificationTime(const std::string& fileName);
121 
129  static time_t changeTime(const std::string& fileName);
130 
138  static time_t accessTime(const std::string& fileName);
139 
148  (FILE * & file, const carma::util::frameType& frameCount,
149  const std::string& signature);
150 
159  (const std::string& fileName, carma::util::frameType& frameCount,
160  std::string& signature);
161 
169  static unsigned getMonitorDataFlatFileHeaderLength(const unsigned& sigLength);
170 
175  static std::vector<std::string> scandir( const std::string & dir );
176 
177 };
178 }}
179 #endif // CARMA_UTIL_FILEUTILS_H
static std::string getError(const std::string &fileName)
get file error diagnostic message
Common time functions.
static void rename(const std::string &from, const std::string &to)
Rename a file or directory.
static void makeDirectory(const std::string &path, mode_t mode=S_IRWXU|S_IRWXG|S_IROTH)
Make a directory.
unsigned int frameType
Half second frames since Jan 1, 2000.
Definition: types.h:29
static void hardLink(const std::string &target, const std::string &link)
Create a hard link to a file.
Common file functions Additional file-related functions can be added here.
Definition: FileUtils.h:32
static void writeMonitorDataFlatFileHeader(FILE *&file, const carma::util::frameType &frameCount, const std::string &signature)
write the header of a monitor data flat file
static bool exists(const std::string &fileName)
does the specified file exist?
static off_t size(const std::string &fileName)
the total size of the file in bytes
DigestType
digest type &lt;ui&gt; MD5 md5 SHA1 sha1
Definition: StringUtils.h:30
Common string functions.
static time_t changeTime(const std::string &fileName)
static std::string computeSha1Sum(const std::string &fileName)
compute the SHA1 sum of the file
static unsigned getMonitorDataFlatFileHeaderLength(const unsigned &sigLength)
get the length in bytes, including the new line character, of a monitor data flat file having a signa...
static std::string computeMessageDigest(const std::string &fileName, const DigestType &digestType)
compute the specified message digest for the specified file
static std::vector< std::string > scandir(const std::string &dir)
Return contents of a directory as a vector of strings.
static void removeFile(const std::string &target)
Delete a file.
static time_t accessTime(const std::string &fileName)
static time_t modificationTime(const std::string &fileName)
static unsigned lineCount(const std::string &fileName)
get the number of lines in the specified file
static void readMonitorDataFlatFileHeader(const std::string &fileName, carma::util::frameType &frameCount, std::string &signature)
read and parse the header of a monitor data flat file