2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
19 * @brief This is the header file for the %File class.
21 * This header file contains the declarations of the %File class.
27 #include <FBaseObject.h>
28 #include <FBaseString.h>
29 #include <FBaseByteBuffer.h>
30 #include <FBaseDateTime.h>
31 #include <FBaseColIList.h>
32 #include <FBaseResult.h>
33 #include <FIoFileAttributes.h>
34 #include <FIoFileLock.h>
36 namespace Tizen { namespace Io
40 * @enum FileSeekPosition
42 * Defines the file seek position.
48 FILESEEKPOSITION_BEGIN, /**<The beginning of the file */
49 FILESEEKPOSITION_CURRENT, /**<The current position of the file */
50 FILESEEKPOSITION_END /**<The end of the file */
55 * @brief This class provides the basic file I/O operations, such as read, write, create, and remove.
59 * @final This class is not intended for extension.
61 * The %File class provides the basic file I/O operations, such as read, write, create, and remove.
62 * It only provides synchronous file read-write with raw data bytes (UTF-8) or string data.
63 * It is constructed using the Construct() method to access files and control file I/O operations.
64 * There is no method like Close() to close the opened file instances.
65 * The only way to close an opened file is by invoking the destructor of the %File class.
66 * Therefore, if the %File class is instantiated as a local variable, it is not closed until it goes out of scope.
67 * To get a detailed information on a file or directory, use the FileAttributes and Directory classes.
69 * When an application is installed, the application has its own storage area, which is application root directory.
70 * The application root directory path can be obtained by calling Tizen::App::App::GetAppRootPath().
71 * The following are some of the sub-directories of the application root directory:
72 * - data - Used to store and access private data of an application (read-write permission) @n
73 * To access this directory, use Tizen::App::App::GetInstance()->GetAppRootPath() + L"data"
74 * or Tizen::App::App::GetInstance()->GetAppDataPath().
75 * - res - Used to read resource files that are delivered with the application package (read-only permission) @n
76 * To access this directory, use Tizen::App::App::GetInstance()->GetAppRootPath() + L"res"
77 * or Tizen::App::App::GetInstance()->GetAppResourcePath().
78 * - shared - Used to share data and resource files with other applications @n
79 * There are data and res directories under the shared directory.
80 * Use Tizen::App::App::GetInstance()->GetAppRootPath() + L"shared" to access its own shared directory and
81 * use Tizen::App::AppManager::GetAppSharedPath() to access other application's shared directory. @n
83 * For more information on the path,
84 * see <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/io_overview.htm">I/O Overview</a>.
86 * For more information on class features,
87 * see <a href="../org.tizen.native.appprogramming/html/guide/io/io_namespace.htm">Io Guide</a>.
89 * The following example demonstrates how to use the %File class.
97 using namespace Tizen::Base;
98 using namespace Tizen::Io;
99 using namespace Tizen::App;
103 String fileName(L"test.txt");
109 result r = E_SUCCESS;
112 r = file.Construct(App::GetInstance()->GetAppDataPath() + fileName, "w+");
118 for (i = 0; i < 10; i++)
120 buffer[i] = (char) i;
123 // Writes to the file
124 r = file.Write(buffer, 10);
130 // Repositions the file pointer
131 r = file.Seek(FILESEEKPOSITION_CURRENT, -5);
138 readCnt = file.Read(buffer2, 5);
149 // Checks the correctness of the read data
150 for (i = 0; i < readCnt; i++)
160 AppLog("Succeeded!");
173 * @page CompIoPathPage Compatibility for path
174 * @section CompIoPathPageIssueSection Issues
175 * The path argument of this method in OSP compatible applications has the following issue: @n
177 * -# The path should begin with an allowed path prefix such as '/Home', '/Home/Share', '/Res', '/Share/[@e appid]',
178 * '/Media', and '/Storagecard/Media'.
180 * @section CompIoPathPageSolutionSection Resolutions
182 * - There are no specific allowed path prefixes in Tizen.
184 * @par When working in Tizen:
185 * - For accessing its own data directory, use Tizen::App::App::GetInstance()->GetAppRootPath() + L"data" @n
186 * or Tizen::App::App::GetInstance()->GetAppDataPath().
187 * - For accessing its own resource directory, use Tizen::App::App::GetInstance()->GetAppRootPath() + L"res" @n
188 * or Tizen::App::App::GetInstance()->GetAppResourcePath().
189 * - For accessing its own shared directory, use Tizen::App::App::GetInstance()->GetAppRootPath() + L"shared/data".
190 * - For accessing the media directory, use Tizen::System::Environment::GetMediaPath().
191 * - For accessing the external storage, use Tizen::System::Environment::GetExternalStoragePath().
193 * For more information on the path,
194 * see <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/io_overview.htm">I/O Overview</a>.
198 class _OSP_EXPORT_ File
199 : public Tizen::Base::Object
204 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
211 * This destructor overrides Tizen::Base::Object::~Object().
219 * Initializes this instance of %File with the specified parameters. @n
220 * This method opens an existing file or creates a new one according to the specified file opening mode.
223 * @brief <i> [Deprecated] [Compatibility] </i>
225 * @deprecated This method is deprecated. Instead of using this method, use Directory::Create(const Tizen::Base::String &dirPath,
226 * bool createParentDirectories=false) and File::Construct(const Tizen::Base::String& filePath, const Tizen::Base::String& openMode).
229 * @compatibility This method has compatibility issues with OSP compatible applications. @n
230 * For more information, see @ref CompIoPathPage "here".
233 * @return An error code
234 * @param[in] filePath The path of the file to open or create
235 * @param[in] openMode The file opening mode @n
236 * It can be one of the following:
237 * - r : Open for reading.
238 * - r+: Open for reading and writing.
239 * - w : Open for writing. The file is created if it does not exist,
240 * otherwise it is truncated to zero length.
241 * - w+: Open for writing and reading. The file is created if it does not exist,
242 * otherwise it is truncated to zero length.
243 * - a : Open for appending. The file is created if it does not exist.
244 * - a+: Open for appending and reading. The file is created if it does not exist.
245 * @param[in] createParentDirectories Set to @c true to automatically create non-existent parent directories up to destination, @n
247 * This parameter is useful only if the specified @c openMode allows creation of an absent
248 * file. For example, the following modes: "w", "w+", "a" and "a+". @n
249 * If the value of @c openMode is not any one of these, E_INVALID_ARG exception is thrown.
250 * @exception E_SUCCESS The method is successful.
251 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
252 * - The overall length of the specified path is equal to @c 0 or
253 * exceeds system limitations. @n
254 * - The combination of the specified @c openMode is not allowed. @n
255 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
256 * For example, opening a read-only file in the write mode such as "w" or "a".
257 * @exception E_FILE_NOT_FOUND The specified @c filePath cannot be found.
258 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
259 * @exception E_STORAGE_FULL The disk space is full.
260 * @exception E_IO Either of the following conditions has occurred: @n
261 * - An unexpected device failure has occurred as the media ejected suddenly. @n
262 * - %File corruption is detected.
263 * @remarks The following file opening mode strings are recognized by this method: "w+", "wb+", "w+b", "w", "wb", "a+",
264 * "ab+", "a+b", "a", "ab", "r+", "rb+", "r+b", "r", "rb". @n
265 * Other strings lead to E_INVALID_ARG. However, "b"(binary) open mode is ignored internally.
268 result Construct(const Tizen::Base::String& filePath, const Tizen::Base::String& openMode, bool createParentDirectories);
271 * Initializes this instance of %File with the specified parameters. @n
272 * This method opens an existing file or creates a new one according to the specified file opening mode.
275 * @brief <i> [Compatibility] </i>
279 * @compatibility This method has compatibility issues with OSP compatible applications. @n
280 * For more information, see @ref CompIoPathPage "here".
283 * @return An error code
284 * @param[in] filePath The path of the file to open or create
285 * @param[in] openMode The file opening mode @n
286 * It can be one of the following:
287 * - r : Open for reading.
288 * - r+: Open for reading and writing.
289 * - w : Open for writing. The file is created if it does not exist,
290 * otherwise it is truncated to zero length.
291 * - w+: Open for writing and reading. The file is created if it does not exist,
292 * otherwise it is truncated to zero length.
293 * - a : Open for appending. The file is created if it does not exist.
294 * - a+: Open for appending and reading. The file is created if it does not exist.
295 * @exception E_SUCCESS The method is successful.
296 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
297 * - The overall length of the specified path is equal to @c 0 or
298 * exceeds system limitations. @n
299 * - The combination of the specified @c openMode is not allowed. @n
300 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
301 * For example, opening a read-only file in the write mode such as "w" or "a".
302 * @exception E_FILE_NOT_FOUND The specified @c filePath cannot be found.
303 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
304 * @exception E_STORAGE_FULL The disk space is full.
305 * @exception E_IO Either of the following conditions has occurred: @n
306 * - An unexpected device failure has occurred as the media ejected suddenly. @n
307 * - %File corruption is detected.
308 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
309 * @remarks The following file opening mode strings are recognized by this method: "w+", "wb+", "w+b", "w", "wb", "a+",
310 * "ab+", "a+b", "a", "ab", "r+", "rb+", "r+b", "r", "rb". @n
311 * Other strings lead to E_INVALID_ARG. However, "b"(binary) open mode is ignored internally.
313 result Construct(const Tizen::Base::String& filePath, const Tizen::Base::String& openMode);
316 * Initializes this instance of %File with the specified parameters. @n
317 * This method opens an existing file or creates a new one according to the specified file opening mode.
321 * @return An error code
322 * @param[in] filePath The path of the file to open or create
323 * @param[in] pOpenMode The file opening mode @n
324 * It can be one of the following:
325 * - r : Open for reading.
326 * - r+: Open for reading and writing.
327 * - w : Open for writing. The file is created if it does not exist,
328 * otherwise it is truncated to zero length.
329 * - w+: Open for writing and reading. The file is created if it does not exist,
330 * otherwise it is truncated to zero length.
331 * - a : Open for appending. The file is created if it does not exist.
332 * - a+: Open for appending and reading. The file is created if it does not exist.
333 * @exception E_SUCCESS The method is successful.
334 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
335 * - The overall length of the specified path is equal to @c 0 or
336 * exceeds system limitations. @n
337 * - The combination of the specified @c pOpenMode is not allowed. @n
338 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
339 * For example, opening a read-only file in the write mode such as "w" or "a".
340 * @exception E_FILE_NOT_FOUND The specified @c filePath cannot be found.
341 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
342 * @exception E_STORAGE_FULL The disk space is full.
343 * @exception E_IO Either of the following conditions has occurred: @n
344 * - An unexpected device failure has occurred as the media ejected suddenly. @n
345 * - %File corruption is detected.
346 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
347 * @remarks The following file opening mode strings are recognized by this method: "w+", "wb+", "w+b", "w", "wb", "a+",
348 * "ab+", "a+b", "a", "ab", "r+", "rb+", "r+b", "r", "rb". @n
349 * Other strings lead to E_INVALID_ARG. However, "b"(binary) open mode is ignored internally.
351 result Construct(const Tizen::Base::String& filePath, const char* pOpenMode);
354 * Initializes this instance of %File with the specified parameters. @n
355 * This method opens an existing secure file or creates a new one according to the specified file opening mode. @n
356 * The contents written to the secure file is automatically encrypted and the contents read from the secure file is automatically
357 * decrypted by the platform. @n
358 * Applications using this method can access the secure files that are created by other applications with the identical key value
359 * in same device. However, the secure files created by this method cannot be accessed in other devices.
363 * @return An error code
364 * @param[in] filePath The path of the file to open or create
365 * @param[in] pOpenMode The file opening mode @n
366 * It can be one of the following:
367 * - r : Open for reading.
368 * - r+: Open for reading and writing.
369 * - w : Open for writing. The file is created if it does not exist,
370 * otherwise it is truncated to zero length.
371 * - w+: Open for writing and reading. The file is created if it does not exist,
372 * otherwise it is truncated to zero length.
373 * - a : Open for appending. The file is created if it does not exist.
374 * - a+: Open for appending and reading. The file is created if it does not exist.
375 * @param[in] secretKey A key used to encrypt data of a file or decrypt a secure file @n
376 * If a secure file is created with a specific key value,
377 * other applications can access the same secure file with the identical key value.
378 * @exception E_SUCCESS The method is successful.
379 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
380 * - The overall length of the specified path is equal to @c 0 or
381 * exceeds system limitations.
382 * - The combination of the specified @c pOpenMode is not allowed. @n
383 * - The specified @c secretKey is incorrect or the secure file is corrupted.
384 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
385 * For example, opening a read-only file in the write mode such as "w" or "a".
386 * @exception E_FILE_NOT_FOUND The specified @c filePath cannot be found.
387 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
388 * @exception E_STORAGE_FULL The disk space is full.
389 * @exception E_IO Either of the following conditions has occurred: @n
390 * - An unexpected device failure has occurred as the media ejected suddenly. @n
391 * - %File corruption is detected. @n
392 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
393 * @remarks The following file opening mode strings are recognized by this method: "w+", "wb+", "w+b", "w", "wb", "a+",
394 * "ab+", "a+b", "a", "ab", "r+", "rb+", "r+b", "r", "rb". @n
395 * Other strings lead to E_INVALID_ARG. However, "b"(binary) open mode is ignored internally.
397 result Construct(const Tizen::Base::String& filePath, const char* pOpenMode, const Tizen::Base::ByteBuffer& secretKey);
400 * Reads the byte data from the current file pointer. @n
401 * The user-specified ByteBuffer is filled with the byte data from the current position in the file.
402 * The read operation continues until the specified ByteBuffer is filled or end-of-file is met. @n
403 * In the secure mode, the byte data read from the secure file is automatically decrypted by a platform security module.
407 * @return An error code
408 * @param[in, out] buffer A reference to the buffer that is used to receive the byte data read from the file
409 * @exception E_SUCCESS The method is successful.
410 * @exception E_INVALID_ARG The specified @c buffer has no space to store the read data.
411 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
412 * - The file is not opened for read operation. @n
413 * - Access is denied due to insufficient permission.
414 * @exception E_END_OF_FILE The file pointer has reached end-of-file.
415 * @exception E_IO Either of the following conditions has occurred: @n
416 * - An unexpected device failure has occurred as the media ejected suddenly. @n
417 * - %File corruption is detected.
418 * @remarks The ByteBuffer should be constructed before being passed to the method.
420 result Read(Tizen::Base::ByteBuffer& buffer);
423 * Reads the byte data from the current file pointer and copies it into the specified buffer. @n
424 * In the secure mode, the byte data read from the secure file is automatically decrypted by a platform security module.
428 * @return The length of the data read in bytes, @n
429 * else @c 0 in case of failure
430 * @param[out] buffer A pointer to the user-supplied buffer where the read data is copied
431 * @param[in] length The buffer length in bytes
432 * @exception E_SUCCESS The method is successful.
433 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
434 * - The specified @c buffer contains a @c null pointer. @n
435 * - The length of the specified @c buffer is equal to or smaller than @c 0. @n
436 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
437 * - The file is not opened for read operation. @n
438 * - Access is denied due to insufficient permission.
439 * @exception E_END_OF_FILE The file pointer has reached end-of-file.
440 * @exception E_IO Either of the following conditions has occurred: @n
441 * - An unexpected device failure has occurred as the media ejected suddenly. @n
442 * - %File corruption is detected.
443 * @remarks The specific error code can be accessed using the GetLastResult() method.
445 int Read(void* buffer, int length);
448 * Reads the string data from the current file pointer and copies the string to the specified buffer (it is assumed that the
449 * file is in the UTF-8 format). @n
450 * The read operation continues until new line character or end-of-file is met. @n
451 * In the secure mode, the string data read from the secure file is automatically decrypted by a platform security module.
455 * @return An error code
456 * @param[out] buffer A reference to the buffer where the data is copied
457 * @exception E_SUCCESS The method is successful.
458 * @exception E_INVALID_ARG The specified @c buffer is invalid.
459 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
460 * - The file is not opened for read operation. @n
461 * - Access is denied due to insufficient permission.
462 * @exception E_END_OF_FILE The file pointer reached end-of-file.
463 * @exception E_IO Either of the following conditions has occurred:
464 * - An unexpected device failure has occurred as the media ejected suddenly. @n
465 * - %File corruption is detected.
466 * @remarks To get the expected string value
467 * from a file, which is not in the UTF-8 format (Unicode or any other format),
468 * user should use other encoding or decoding methods of the Tizen::Text namespace after reading the content of
469 * a file in binary format. @n
470 * The maximum length of characters read by this method is defined as 4096. @n
471 * Therefore, if the length of a single line (considering new line character or end-of-file) from the current
472 * file position is longer than 4096, the rest of the characters remain as not read. @n
473 * 'ByteBuffer' or 'void*' version of the File::Read() API can be used to overcome this limitation.
475 result Read(Tizen::Base::String& buffer);
478 * Writes the byte data from the specified ByteBuffer into a file beginning at the current position to the limit of the
480 * In the secure mode, the byte data written by a user is automatically encrypted to the secure file by a platform security module. @n
481 * The size of a secure file can be greater than the size of a normal (original) file
482 * because of the encryption.
483 * However, the file pointer for the secure file is equal to the file pointer for the original file.
487 * @return An error code
488 * @param[in] buffer A reference to the buffer that contains byte data to write
489 * @exception E_SUCCESS The method is successful.
490 * @exception E_INVALID_ARG The specified @c buffer is invalid.
491 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
492 * - The file is not opened for write operation. @n
493 * - Access is denied due to insufficient permission.
494 * @exception E_STORAGE_FULL The disk space is full.
495 * @exception E_IO Either of the following conditions has occurred: @n
496 * - An unexpected device failure has occurred as the media ejected suddenly. @n
497 * - %File corruption is detected.
499 result Write(const Tizen::Base::ByteBuffer& buffer);
502 * Writes the byte data into a file. @n
503 * In the secure mode, the byte data written by a user is automatically encrypted to the secure file by a platform security module. @n
504 * The size of a secure file can be greater than the size of a normal (original) file
505 * because of the encryption.
506 * However, the file pointer for the secure file is equal to the file pointer for the original file.
510 * @return An error code
511 * @param[in] buffer A pointer to the user-supplied buffer that contains @c byte data to write
512 * @param[in] length The buffer length in bytes
513 * @exception E_SUCCESS The method is successful.
514 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
515 * - The file is not opened for write operation. @n
516 * - Access is denied due to insufficient permission.
517 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
518 * - The specified @c buffer contains a @c null pointer. @n
519 * - The specified @c buffer length is equal or smaller than @c 0. @n
520 * @exception E_STORAGE_FULL The disk space is full.
521 * @exception E_IO Either of the following conditions has occurred: @n
522 * - An unexpected device failure has occurred as the media ejected suddenly. @n
523 * - %File corruption is detected.
525 result Write(const void* buffer, int length);
528 * Writes the string data into a file. @n
529 * In the secure mode, the string data written by a user is automatically encrypted to the secure file by a platform security
531 * The size of a secure file can be greater than the size of a normal (original) file
532 * because of the encryption.
533 * However, the file pointer for the secure file is equal to the file pointer for the original file.
537 * @return An error code
538 * @param[in] buffer A reference to the buffer that contains string data to write
539 * @exception E_SUCCESS The method is successful.
540 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
541 * - The file is not opened for write operation. @n
542 * - Access is denied due to insufficient permission.
543 * @exception E_INVALID_ARG The specified @c buffer contains an empty string.
544 * @exception E_STORAGE_FULL The disk space is full.
545 * @exception E_IO Either of the following conditions has occurred: @n
546 * - An unexpected device failure has occurred as the media ejected suddenly. @n
547 * - %File corruption is detected.
549 result Write(const Tizen::Base::String& buffer);
552 * Flushes the internally buffered data to kernel memory of the underlying operating system.
556 * @return An error code
557 * @exception E_SUCCESS The method is successful.
558 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
559 * @exception E_STORAGE_FULL The disk space is full.
560 * @exception E_IO Either of the following conditions has occurred: @n
561 * - An unexpected device failure has occurred as the media ejected suddenly. @n
562 * - %File corruption is detected.
567 * Gets the offset of the current file pointer relative to the beginning of the file. @n
568 * The size of a secure file can be greater than the size of a normal (original) file
569 * because of the encryption.
570 * However, the file pointer for the secure file is equal to the file pointer for the original file.
574 * @return The offset of the current file pointer, @n
575 * else @c -1L if an error occurs
576 * @exception E_SUCCESS The method is successful.
577 * @exception E_IO Either of the following conditions has occurred: @n
578 * - An unexpected device failure has occurred as the media ejected suddenly. @n
579 * - %File corruption is detected.
580 * @remarks The specific error code can be accessed using the GetLastResult() method.
583 int Tell(void) const;
586 * Repositions the file pointer associated with an opened file. @n
587 * Each opened file has its own file pointer, and it points to the next byte to be read or written in the file.
588 * The repositioning offset can be specified with respect to the beginning of file, current position, or end of the file.
589 * If the file pointer is over the end-of-file, it expands the file size to the specified position and the expanded area is
590 * filled with zero. @n
591 * The size of a secure file can be greater than the size of a normal (original) file
592 * because of the encryption.
593 * However, the file pointer for the secure file is equal to the file pointer for the original file.
597 * @return An error code
598 * @param[in] position The origin from where to start the repositioning a file pointer
599 * @param[in] offset The number of bytes to move a file pointer @n
600 * A negative offset moves the pointer backwards.
601 * @exception E_SUCCESS The method is successful.
602 * @exception E_INVALID_ARG The specified @c position or @c offset is invalid.
603 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
604 * @exception E_STORAGE_FULL The disk space is full.
605 * @exception E_IO Either of the following conditions has occurred: @n
606 * - An unexpected device failure has occurred as the media ejected suddenly. @n
607 * - %File corruption is detected.
608 * @see FileSeekPosition
610 result Seek(FileSeekPosition position, long offset);
613 * Truncates the file size to the specified length. @n
614 * If the specified length is less than the length of file, the bytes present between the @c length and size of a file are
616 * If the file size is small, its size is increased. @n
617 * The size of a secure file can be greater than the size of a normal (original) file
618 * because of the encryption.
619 * However, the file pointer for a secure file is equal to the file pointer for an original file.
623 * @return An error code
624 * @param[in] length The required file size in bytes after this method is executed
625 * @exception E_SUCCESS The method is successful.
626 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
627 * - The file is not opened for write operation. @n
628 * - Access is denied due to insufficient permission.
629 * @exception E_INVALID_ARG The specified @c length has a negative value.
630 * @exception E_STORAGE_FULL The disk space is full.
631 * @exception E_IO Either of the following conditions has occurred: @n
632 * - An unexpected device failure has occurred as the media ejected suddenly. @n
633 * - %File corruption is detected.
635 result Truncate(int length);
638 * Gets the path associated with a constructed %File.
642 * @return The file path to the currently constructed %File if successful, @n
643 * else an empty string in case of failure
645 Tizen::Base::String GetName(void) const;
648 * Acquires the file lock on the current opened whole file if it is not acquired.
649 * If the file lock is already acquired by another process, the current process is blocked until the file lock is
654 * @return The pointer to %FileLock instance, @n
655 * else @c null pointer in case of failure
656 * @param[in] lockType The type of file lock to be created
657 * @exception E_SUCCESS The method is successful.
658 * @exception E_INVALID_ARG The specified @c lockType is invalid.
659 * @exception E_INVALID_OPERATION Either of the following conditions has occurred: @n
660 * - The specified @c lockType cannot be FILE_LOCK_SHARED if the current
661 * file is not open for reading. @n
662 * - The specified @c lockType cannot be FILE_LOCK_EXCLUSIVE if the current
663 * file is not open for writing. @n
664 * @exception E_WOULD_DEADLOCK The method would cause a deadlock. @n
665 * The lock is blocked by a lock from another process, and putting the
666 * calling process to sleep to wait for that lock to become free would
668 * @exception E_MAX_EXCEEDED The number of file lock exceeds system limitations.
669 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
670 * @remarks The %FileLock instance is invalid if the associated %File instance is deleted. @n
671 * The specific error code can be accessed using the GetLastResult() method.
673 FileLock* LockN(FileLockType lockType);
676 * Acquires the file lock on the specified region of the current opened file if it is not acquired.
677 * If the file lock is already acquired by another process, the current process is blocked until the file lock is
682 * @return The pointer to %FileLock instance, @n
683 * else @c null pointer in case of failure
684 * @param[in] lockType The type of file lock to be created
685 * @param[in] offset The starting offset for the locked region
686 * @param[in] length The length of the locked region in bytes
687 * @exception E_SUCCESS The method is successful.
688 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
689 * - The specified @c lockType is invalid.
690 * - The specified @c offset or @c length is negative or is greater than
691 * the system limitation.
692 * @exception E_INVALID_OPERATION Either of the following conditions has occurred: @n
693 * - The specified @c lockType cannot be FILE_LOCK_SHARED if the current
694 * file is not open for reading. @n
695 * - The specified @c lockType cannot be FILE_LOCK_EXCLUSIVE if the current
696 * file is not open for writing. @n
697 * @exception E_WOULD_DEADLOCK The method would cause a deadlock. @n
698 * The lock is blocked by a lock from another process, and putting the
699 * calling process to sleep to wait for that lock to become free would
701 * @exception E_MAX_EXCEEDED The number of file lock exceeds system limitations.
702 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
703 * @remarks The %FileLock instance is invalid if the associated %File instance is deleted. @n
704 * The specific error code can be accessed using the GetLastResult() method.
706 FileLock* LockN(FileLockType lockType, int offset, int length);
709 * Tries to acquire the file lock on the current opened whole file.
710 * If the file lock is already acquired by another process, E_OBJECT_LOCKED is returned.
714 * @return The pointer to %FileLock instance, @n
715 * else @c null pointer in case of failure
716 * @param[in] lockType The type of file lock to be created
717 * @exception E_SUCCESS The method is successful.
718 * @exception E_INVALID_ARG The specified @c lockType is invalid.
719 * @exception E_INVALID_OPERATION Either of the following conditions has occurred: @n
720 * - The specified @c lockType cannot be FILE_LOCK_SHARED if the current
721 * file is not open for reading. @n
722 * - The specified @c lockType cannot be FILE_LOCK_EXCLUSIVE if the current
723 * file is not open for writing. @n
724 * @exception E_OBJECT_LOCKED Either of the following conditions has occurred: @n
725 * - The file lock is already held by another process. @n
726 * - The file to be locked has been memory-mapped by another process.
727 * @exception E_MAX_EXCEEDED The number of file lock exceeds system limitations.
728 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
729 * @remarks The %FileLock instance is invalid if the associated %File instance is deleted. @n
730 * The specific error code can be accessed using the GetLastResult() method.
732 FileLock* TryToLockN(FileLockType lockType);
735 * Tries to acquire the file lock on the specified region of the current opened file.
736 * If the file lock is already acquired by another process, E_OBJECT_LOCKED is returned.
740 * @return The pointer to %FileLock instance, @n
741 * else @c null pointer in case of failure
742 * @param[in] lockType The type of file lock to be created
743 * @param[in] offset The starting offset for the locked region
744 * @param[in] length The length of the locked region in bytes
745 * @exception E_SUCCESS The method is successful.
746 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
747 * - The specified @c lockType is invalid.
748 * - The specified @c offset or @c length is negative or is greater than
749 * the system limitation.
750 * @exception E_INVALID_OPERATION Either of the following conditions has occurred: @n
751 * - The specified @c lockType cannot be FILE_LOCK_SHARED if the current
752 * file is not open for reading. @n
753 * - The specified @c lockType cannot be FILE_LOCK_EXCLUSIVE if the current
754 * file is not open for writing. @n
755 * @exception E_OBJECT_LOCKED Either of the following conditions has occurred: @n
756 * - The file lock is already held by another process. @n
757 * - The file to be locked has been memory-mapped by another process.
758 * @exception E_MAX_EXCEEDED The number of file lock exceeds system limitations.
759 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
760 * @remarks The %FileLock instance is invalid if the associated %File instance is deleted. @n
761 * The specific error code can be accessed using the GetLastResult() method.
763 FileLock* TryToLockN(FileLockType lockType, int offset, int length);
766 * Deletes the file specified. @n
767 * The opened file cannot be deleted. This method is static.
770 * @brief <i> [Compatibility] </i>
774 * @compatibility This method has compatibility issues with OSP compatible applications. @n
775 * For more information, see @ref CompIoPathPage "here".
778 * @return An error code
779 * @param[in] filePath The path of the file to delete
780 * @exception E_SUCCESS The method is successful.
781 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
782 * - The overall length of the specified path is equal to @c 0 or
783 * exceeds system limitations. @n
784 * - The specified path is invalid.
785 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
786 * For example, opening a read-only file in the write mode.
787 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
788 * @exception E_IO Either of the following conditions has occurred: @n
789 * - An unexpected device failure has occurred as the media ejected suddenly. @n
790 * - %File corruption is detected.
791 * @remarks The opened file cannot be deleted.
793 static result Remove(const Tizen::Base::String& filePath);
796 * Moves the specified file to another location. @n
797 * The opened files cannot be moved. This method is static.
800 * @brief <i> [Compatibility] </i>
804 * @compatibility This method has compatibility issues with OSP compatible applications. @n
805 * For more information, see @ref CompIoPathPage "here".
808 * @return An error code
809 * @param[in] oldFilePath The old file path
810 * @param[in] newFilePath The new file path
811 * @exception E_SUCCESS The method is successful.
812 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
813 * - The overall length of the specified path is equal to @c 0 or
814 * exceeds system limitations. @n
815 * - The specified path is invalid.
816 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
817 * For example, opening a read-only file in the write mode.
818 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
819 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
820 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
821 * @exception E_STORAGE_FULL The disk space is full.
822 * @exception E_IO Either of the following conditions has occurred: @n
823 * - An unexpected device failure has occurred as the media ejected suddenly. @n
824 * - %File corruption is detected.
828 static result Move(const Tizen::Base::String& oldFilePath, const Tizen::Base::String& newFilePath);
831 * Copies the existing source file to the destined location. @n
832 * This method is static.
836 * @return An error code
837 * @param[in] srcFilePath The source file path
838 * @param[in] destFilePath The destination file path
839 * @param[in] failIfExist Set to @c true to return an error if the destination file already exists, @n
841 * @exception E_SUCCESS The method is successful.
842 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
843 * - The overall length of the specified path is equal to @c 0 or
844 * exceeds system limitations. @n
845 * - The specified path is invalid.
846 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
847 * For example, opening a read-only file in the write mode.
848 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
849 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
850 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
851 * @exception E_STORAGE_FULL The disk space is full.
852 * @exception E_IO Either of the following conditions has occurred: @n
853 * - An unexpected device failure has occurred as the media ejected suddenly. @n
854 * - %File corruption is detected.
858 static result Copy(const Tizen::Base::String& srcFilePath, const Tizen::Base::String& destFilePath, bool failIfExist);
861 * Reads the file information such as size, attribute, creation date, and so on. @n
862 * This method is static.
865 * @brief <i> [Compatibility] </i>
869 * @compatibility This method has compatibility issues with OSP compatible applications. @n
870 * For more information, see @ref CompIoPathPage "here".
873 * @return An error code
874 * @param[in] filePath The path of the file @n
875 * @param[out] attribute A %File attribute instance
876 * @exception E_SUCCESS The method is successful.
877 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
878 * - The overall length of the specified path is equal to @c 0 or
879 * exceeds system limitations. @n
880 * - The specified path is invalid.
881 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
882 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
883 * @exception E_IO Either of the following conditions has occurred: @n
884 * - An unexpected device failure has occurred as the media ejected suddenly. @n
885 * - %File corruption is detected.
887 static result GetAttributes(const Tizen::Base::String& filePath, FileAttributes& attribute);
890 * Gets only the file name from the specified file path. @n
891 * For example, if the file path passed is 'xxx/file.txt', 'file.txt' is returned.
894 * @brief <i> [Compatibility] </i>
898 * @compatibility This method has compatibility issues with OSP compatible applications. @n
899 * For more information, see @ref CompIoPathPage "here".
902 * @return The file name of type String
903 * @param[in] filePath The path of the file
904 * @exception E_SUCCESS The method is successful.
905 * @exception E_INVALID_ARG The length of the specified path is @c 0 or exceeds system limitations.
906 * @remarks The specific error code can be accessed using the GetLastResult() method.
907 * @see GetFileExtension()
909 static Tizen::Base::String GetFileName(const Tizen::Base::String& filePath);
912 * Gets the file extension of the specified file path.
915 * @brief <i> [Compatibility] </i>
919 * @compatibility This method has compatibility issues with OSP compatible applications. @n
920 * For more information, see @ref CompIoPathPage "here".
923 * @return The file extension, @n
924 * else an empty string if the file has no extension
925 * @param[in] filePath The path of the file
926 * @exception E_SUCCESS The method is successful.
927 * @exception E_INVALID_ARG The length of the specified path is @c 0 or exceeds system limitations.
928 * @remarks The specific error code can be accessed using the GetLastResult() method.
931 static Tizen::Base::String GetFileExtension(const Tizen::Base::String& filePath);
934 * Checks whether the specified file or directory exists.
937 * @brief <i> [Compatibility] </i>
941 * @compatibility This method has compatibility issues with OSP compatible applications. @n
942 * For more information, see @ref CompIoPathPage "here".
945 * @return @c true if file or directory exists, @n
947 * @param[in] filePath The path of the file or directory
948 * @exception E_SUCCESS The method is successful.
949 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
950 * - The overall length of the specified path is equal to @c 0 or
951 * exceeds system limitations. @n
952 * - The specified path is invalid.
953 * @exception E_ILLEGAL_ACCESS The specified path is not permitted, or
954 * access is denied due to insufficient permission.
955 * @remarks The specific error code can be accessed using the GetLastResult() method.
957 static bool IsFileExist(const Tizen::Base::String& filePath);
960 * Converts a normal file to a secure file. @n
961 * A secure file that is converted by this method can be shared among applications with the same key value.
962 * This method is static.
965 * @brief <i> [Compatibility] </i>
969 * @compatibility This method has compatibility issues with OSP compatible applications. @n
970 * For more information, see @ref CompIoPathPage "here".
973 * @return An error code
974 * @param[in] plainFilePath The normal (non-encrypted) file path
975 * @param[in] secureFilePath The secure (encrypted) file path to create
976 * @param[in] key A key that encrypts a secure file @n
977 * If the secure file is converted with a specific key value,
978 * applications can access the same secure file with the identical key value.
979 * @exception E_SUCCESS The method is successful.
980 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
981 * - The overall length of the specified path is equal to @c 0 or
982 * exceeds system limitations. @n
983 * - The specified path is invalid. @n
984 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
985 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
986 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
987 * @exception E_STORAGE_FULL The disk space is full.
988 * @exception E_IO Either of the following conditions has occurred: @n
989 * - An unexpected device failure has occurred as the media ejected suddenly. @n
990 * - %File corruption is detected. @n
991 * - The number of opened files has exceeded the maximum limit.
993 static result ConvertToSecureFile(const Tizen::Base::String& plainFilePath, const Tizen::Base::String& secureFilePath, const Tizen::Base::ByteBuffer& key);
997 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
1001 File(const File& rhs);
1004 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
1008 File& operator =(const File& rhs);
1010 class _FileImpl* __pFileImpl;
1012 friend class _FileImpl;
1018 #endif // _FIO_FILE_H_