DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
file.h
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_FILE_FILE_H_
8 #define PACKAGER_FILE_FILE_H_
9 
10 #include <stdint.h>
11 
12 #include <string>
13 
14 #include "packager/base/macros.h"
15 
16 namespace edash_packager {
17 namespace media {
18 
19 extern const char* kLocalFilePrefix;
20 
22 class File {
23  public:
30  static File* Open(const char* file_name, const char* mode);
31 
38  static File* OpenWithNoBuffering(const char* file_name, const char* mode);
39 
43  static bool Delete(const char* file_name);
44 
50  virtual bool Close() = 0;
51 
58  virtual int64_t Read(void* buffer, uint64_t length) = 0;
59 
64  virtual int64_t Write(const void* buffer, uint64_t length) = 0;
65 
68  virtual int64_t Size() = 0;
69 
75  virtual bool Flush() = 0;
76 
80  virtual bool Seek(uint64_t position) = 0;
81 
86  virtual bool Tell(uint64_t* position) = 0;
87 
89  const std::string& file_name() const { return file_name_; }
90 
91  // ************************************************************
92  // * Static Methods: File-on-the-filesystem status
93  // ************************************************************
94 
97  static int64_t GetFileSize(const char* file_name);
98 
103  static bool ReadFileToString(const char* file_name, std::string* contents);
104 
105  protected:
106  explicit File(const std::string& file_name) : file_name_(file_name) {}
109  virtual ~File() {}
110 
112  virtual bool Open() = 0;
113 
114  private:
115  friend class ThreadedIoFile;
116 
117  // This is a file factory method, it creates a proper file, e.g.
118  // LocalFile, MemFile based on prefix.
119  static File* Create(const char* file_name, const char* mode);
120 
121  static File* CreateInternalFile(const char* file_name, const char* mode);
122 
123  std::string file_name_;
124  DISALLOW_COPY_AND_ASSIGN(File);
125 };
126 
127 } // namespace media
128 } // namespace edash_packager
129 
130 #endif // PACKAGER_FILE_FILE_H_
static bool ReadFileToString(const char *file_name, std::string *contents)
Definition: file.cc:160
virtual bool Seek(uint64_t position)=0
virtual int64_t Read(void *buffer, uint64_t length)=0
static bool Delete(const char *file_name)
Definition: file.cc:138
Define an abstract file interface.
Definition: file.h:22
virtual bool Open()=0
Internal open. Should not be used directly.
const std::string & file_name() const
Definition: file.h:89
virtual bool Tell(uint64_t *position)=0
virtual int64_t Size()=0
Declaration of class which implements a thread-safe circular buffer.
virtual int64_t Write(const void *buffer, uint64_t length)=0
static int64_t GetFileSize(const char *file_name)
Definition: file.cc:151
static File * OpenWithNoBuffering(const char *file_name, const char *mode)
Definition: file.cc:127