2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @brief This is the header file for the %File class.
22 * This header file contains the declarations of the %File class.
28 #include <FBaseObject.h>
29 #include <FBaseString.h>
30 #include <FBaseByteBuffer.h>
31 #include <FBaseDateTime.h>
32 #include <FBaseColIList.h>
33 #include <FBaseResult.h>
34 #include <FIoFileAttributes.h>
35 #include <FIoFileLock.h>
37 namespace Tizen { namespace Io
41 * @enum FileSeekPosition
43 * Defines the file seek position.
49 FILESEEKPOSITION_BEGIN, /**<The beginning of the file */
50 FILESEEKPOSITION_CURRENT, /**<The current position of the file */
51 FILESEEKPOSITION_END /**<The end of the file */
56 * @brief This class provides the basic file I/O operations, such as read, write, create, and remove.
60 * @final This class is not intended for extension.
62 * The %File class provides the basic file I/O operations, such as read, write, create, and remove.
63 * It only provides synchronous file read-write with raw data bytes (UTF-8) or string data.
64 * It is constructed using the Construct() method to access files and control file I/O operations.
65 * There is no method like Close() to close the opened file instances.
66 * The only way to close an opened file is by invoking the destructor of the %File class.
67 * Therefore, if the %File class is instantiated as a local variable, it is not closed until it goes out of scope.
68 * To get a detailed information on a file or directory, use the FileAttributes and Directory classes.
70 * When an application is installed, the application has its own storage area, which is application root directory.
71 * The application root directory path can be obtained by calling Tizen::App::App::GetAppRootPath().
72 * The following are some of the sub-directories of the application root directory:
73 * - data - Used to store and access private data of an application (read-write permission) @n
74 * To access this directory, use Tizen::App::App::GetInstance()->GetAppRootPath() + L"data"
75 * or Tizen::App::App::GetInstance()->GetAppDataPath().
76 * - res - Used to read resource files that are delivered with the application package (read-only permission) @n
77 * To access this directory, use Tizen::App::App::GetInstance()->GetAppRootPath() + L"res"
78 * or Tizen::App::App::GetInstance()->GetAppResourcePath().
79 * - shared - Used to share data and resource files with other applications @n
80 * There are data and res directories under the shared directory.
81 * Use Tizen::App::App::GetInstance()->GetAppRootPath() + L"shared" to access its own shared directory and
82 * use Tizen::App::AppManager::GetAppSharedPath() to access other application's shared directory. @n
84 * For more information on the path,
85 * see <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/io_overview.htm">I/O Overview</a>.
87 * For more information on class features,
88 * see <a href="../org.tizen.native.appprogramming/html/guide/io/io_namespace.htm">Io Guide</a>.
90 * The following example demonstrates how to use the %File class.
98 using namespace Tizen::Base;
99 using namespace Tizen::Io;
100 using namespace Tizen::App;
104 String fileName(L"test.txt");
110 result r = E_SUCCESS;
113 r = file.Construct(App::GetInstance()->GetAppDataPath() + fileName, "w+");
119 for (i = 0; i < 10; i++)
121 buffer[i] = (char) i;
124 // Writes to the file
125 r = file.Write(buffer, 10);
131 // Repositions the file pointer
132 r = file.Seek(FILESEEKPOSITION_CURRENT, -5);
139 readCnt = file.Read(buffer2, 5);
150 // Checks the correctness of the read data
151 for (i = 0; i < readCnt; i++)
161 AppLog("Succeeded!");
174 * @page CompIoPathPage Compatibility for path
175 * @section CompIoPathPageIssueSection Issues
176 * The path argument of this method in OSP compatible applications has the following issue: @n
178 * -# The path should begin with an allowed path prefix such as '/Home', '/Home/Share', '/Res', '/Share/[@e appid]',
179 * '/Media', and '/Storagecard/Media'.
181 * @section CompIoPathPageSolutionSection Resolutions
183 * - There are no specific allowed path prefixes in Tizen.
185 * @par When working in Tizen:
186 * - For accessing its own data directory, use Tizen::App::App::GetInstance()->GetAppRootPath() + L"data" @n
187 * or Tizen::App::App::GetInstance()->GetAppDataPath().
188 * - For accessing its own resource directory, use Tizen::App::App::GetInstance()->GetAppRootPath() + L"res" @n
189 * or Tizen::App::App::GetInstance()->GetAppResourcePath().
190 * - For accessing its own shared directory, use Tizen::App::App::GetInstance()->GetAppRootPath() + L"shared/data".
191 * - For accessing the media directory, use Tizen::System::Environment::GetMediaPath().
192 * - For accessing the external storage, use Tizen::System::Environment::GetExternalStoragePath().
194 * For more information on the path,
195 * see <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/io_overview.htm">I/O Overview</a>.
199 class _OSP_EXPORT_ File
200 : public Tizen::Base::Object
205 * 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.
212 * This destructor overrides Tizen::Base::Object::~Object().
221 * Initializes this instance of %File with the specified parameters. @n
222 * This method opens an existing file or creates a new one according to the specified file opening mode.
225 * @brief <i> [Deprecated] [Compatibility] </i>
227 * @deprecated This method is deprecated. Instead of using this method, use Directory::Create(const Tizen::Base::String &dirPath,
228 * bool createParentDirectories=false) and File::Construct(const Tizen::Base::String& filePath, const Tizen::Base::String& openMode).
231 * @compatibility This method has compatibility issues with OSP compatible applications. @n
232 * For more information, see @ref CompIoPathPage "here".
235 * @return An error code
236 * @param[in] filePath The path of the file to open or create
237 * @param[in] openMode The file opening mode @n
238 * It can be one of the following:
239 * - r : Open for reading.
240 * - r+: Open for reading and writing.
241 * - w : Open for writing. The file is created if it does not exist,
242 * otherwise it is truncated to zero length.
243 * - w+: Open for writing and reading. The file is created if it does not exist,
244 * otherwise it is truncated to zero length.
245 * - a : Open for appending. The file is created if it does not exist.
246 * - a+: Open for appending and reading. The file is created if it does not exist.
247 * @param[in] createParentDirectories Set to @c true to automatically create non-existent parent directories up to destination, @n
249 * This parameter is useful only if the specified @c openMode allows creation of an absent
250 * file. For example, the following modes: "w", "w+", "a" and "a+". @n
251 * If the value of @c openMode is not any one of these, E_INVALID_ARG exception is thrown.
252 * @exception E_SUCCESS The method is successful.
253 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
254 * - The overall length of the specified path is equal to @c 0 or
255 * exceeds system limitations. @n
256 * - The combination of the specified @c openMode is not allowed. @n
257 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
258 * For example, opening a read-only file in the write mode such as "w" or "a".
259 * @exception E_FILE_NOT_FOUND The specified @c filePath cannot be found.
260 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
261 * @exception E_STORAGE_FULL The disk space is full.
262 * @exception E_IO Either of the following conditions has occurred: @n
263 * - An unexpected device failure has occurred as the media ejected suddenly. @n
264 * - %File corruption is detected.
265 * @remarks The following file opening mode strings are recognized by this method: "w+", "wb+", "w+b", "w", "wb", "a+",
266 * "ab+", "a+b", "a", "ab", "r+", "rb+", "r+b", "r", "rb". @n
267 * Other strings lead to E_INVALID_ARG. However, "b"(binary) open mode is ignored internally.
271 result Construct(const Tizen::Base::String& filePath, const Tizen::Base::String& openMode, bool createParentDirectories);
274 * Initializes this instance of %File with the specified parameters. @n
275 * This method opens an existing file or creates a new one according to the specified file opening mode.
278 * @brief <i> [Compatibility] </i>
282 * @compatibility This method has compatibility issues with OSP compatible applications. @n
283 * For more information, see @ref CompIoPathPage "here".
286 * @return An error code
287 * @param[in] filePath The path of the file to open or create
288 * @param[in] openMode The file opening mode @n
289 * It can be one of the following:
290 * - r : Open for reading.
291 * - r+: Open for reading and writing.
292 * - w : Open for writing. The file is created if it does not exist,
293 * otherwise it is truncated to zero length.
294 * - w+: Open for writing and reading. The file is created if it does not exist,
295 * otherwise it is truncated to zero length.
296 * - a : Open for appending. The file is created if it does not exist.
297 * - a+: Open for appending and reading. The file is created if it does not exist.
298 * @exception E_SUCCESS The method is successful.
299 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
300 * - The overall length of the specified path is equal to @c 0 or
301 * exceeds system limitations. @n
302 * - The combination of the specified @c openMode is not allowed. @n
303 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
304 * For example, opening a read-only file in the write mode such as "w" or "a".
305 * @exception E_FILE_NOT_FOUND The specified @c filePath cannot be found.
306 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
307 * @exception E_STORAGE_FULL The disk space is full.
308 * @exception E_IO Either of the following conditions has occurred: @n
309 * - An unexpected device failure has occurred as the media ejected suddenly. @n
310 * - %File corruption is detected.
311 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
312 * @remarks The following file opening mode strings are recognized by this method: "w+", "wb+", "w+b", "w", "wb", "a+",
313 * "ab+", "a+b", "a", "ab", "r+", "rb+", "r+b", "r", "rb". @n
314 * Other strings lead to E_INVALID_ARG. However, "b"(binary) open mode is ignored internally.
316 result Construct(const Tizen::Base::String& filePath, const Tizen::Base::String& openMode);
319 * Initializes this instance of %File with the specified parameters. @n
320 * This method opens an existing file or creates a new one according to the specified file opening mode.
324 * @return An error code
325 * @param[in] filePath The path of the file to open or create
326 * @param[in] pOpenMode The file opening mode @n
327 * It can be one of the following:
328 * - r : Open for reading.
329 * - r+: Open for reading and writing.
330 * - w : Open for writing. The file is created if it does not exist,
331 * otherwise it is truncated to zero length.
332 * - w+: Open for writing and reading. The file is created if it does not exist,
333 * otherwise it is truncated to zero length.
334 * - a : Open for appending. The file is created if it does not exist.
335 * - a+: Open for appending and reading. The file is created if it does not exist.
336 * @exception E_SUCCESS The method is successful.
337 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
338 * - The overall length of the specified path is equal to @c 0 or
339 * exceeds system limitations. @n
340 * - The combination of the specified @c pOpenMode is not allowed. @n
341 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
342 * For example, opening a read-only file in the write mode such as "w" or "a".
343 * @exception E_FILE_NOT_FOUND The specified @c filePath cannot be found.
344 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
345 * @exception E_STORAGE_FULL The disk space is full.
346 * @exception E_IO Either of the following conditions has occurred: @n
347 * - An unexpected device failure has occurred as the media ejected suddenly. @n
348 * - %File corruption is detected.
349 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
350 * @remarks The following file opening mode strings are recognized by this method: "w+", "wb+", "w+b", "w", "wb", "a+",
351 * "ab+", "a+b", "a", "ab", "r+", "rb+", "r+b", "r", "rb". @n
352 * Other strings lead to E_INVALID_ARG. However, "b"(binary) open mode is ignored internally.
354 result Construct(const Tizen::Base::String& filePath, const char* pOpenMode);
357 * Initializes this instance of %File with the specified parameters. @n
358 * This method opens an existing secure file or creates a new one according to the specified file opening mode. @n
359 * The contents written to the secure file is automatically encrypted and the contents read from the secure file is automatically
360 * decrypted by the platform. @n
361 * Applications using this method can access the secure files that are created by other applications with the identical key value
362 * in same device. However, the secure files created by this method cannot be accessed in other devices.
366 * @return An error code
367 * @param[in] filePath The path of the file to open or create
368 * @param[in] pOpenMode The file opening mode @n
369 * It can be one of the following:
370 * - r : Open for reading.
371 * - r+: Open for reading and writing.
372 * - w : Open for writing. The file is created if it does not exist,
373 * otherwise it is truncated to zero length.
374 * - w+: Open for writing and reading. The file is created if it does not exist,
375 * otherwise it is truncated to zero length.
376 * - a : Open for appending. The file is created if it does not exist.
377 * - a+: Open for appending and reading. The file is created if it does not exist.
378 * @param[in] secretKey A key used to encrypt data of a file or decrypt a secure file @n
379 * If a secure file is created with a specific key value,
380 * other applications can access the same secure file with the identical key value.
381 * @exception E_SUCCESS The method is successful.
382 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
383 * - The overall length of the specified path is equal to @c 0 or
384 * exceeds system limitations.
385 * - The combination of the specified @c pOpenMode is not allowed. @n
386 * - The specified @c secretKey is incorrect or the secure file is corrupted.
387 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
388 * For example, opening a read-only file in the write mode such as "w" or "a".
389 * @exception E_FILE_NOT_FOUND The specified @c filePath cannot be found.
390 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
391 * @exception E_STORAGE_FULL The disk space is full.
392 * @exception E_IO Either of the following conditions has occurred: @n
393 * - An unexpected device failure has occurred as the media ejected suddenly. @n
394 * - %File corruption is detected. @n
395 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
396 * @remarks The following file opening mode strings are recognized by this method: "w+", "wb+", "w+b", "w", "wb", "a+",
397 * "ab+", "a+b", "a", "ab", "r+", "rb+", "r+b", "r", "rb". @n
398 * Other strings lead to E_INVALID_ARG. However, "b"(binary) open mode is ignored internally.
400 result Construct(const Tizen::Base::String& filePath, const char* pOpenMode, const Tizen::Base::ByteBuffer& secretKey);
403 * Reads the byte data from the current file pointer. @n
404 * The user-specified ByteBuffer is filled with the byte data from the current position in the file.
405 * The read operation continues until the specified ByteBuffer is filled or end-of-file is met. @n
406 * In the secure mode, the byte data read from the secure file is automatically decrypted by a platform security module.
410 * @return An error code
411 * @param[in, out] buffer A reference to the buffer that is used to receive the byte data read from the file
412 * @exception E_SUCCESS The method is successful.
413 * @exception E_INVALID_ARG The specified @c buffer has no space to store the read data.
414 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
415 * - The file is not opened for read operation. @n
416 * - Access is denied due to insufficient permission.
417 * @exception E_END_OF_FILE The file pointer has reached end-of-file.
418 * @exception E_IO Either of the following conditions has occurred: @n
419 * - An unexpected device failure has occurred as the media ejected suddenly. @n
420 * - %File corruption is detected.
421 * @remarks The ByteBuffer should be constructed before being passed to the method.
423 result Read(Tizen::Base::ByteBuffer& buffer);
426 * Reads the byte data from the current file pointer and copies it into the specified buffer. @n
427 * In the secure mode, the byte data read from the secure file is automatically decrypted by a platform security module.
431 * @return The length of the data read in bytes, @n
432 * else @c 0 in case of failure
433 * @param[out] buffer A pointer to the user-supplied buffer where the read data is copied
434 * @param[in] length The buffer length in bytes
435 * @exception E_SUCCESS The method is successful.
436 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
437 * - The specified @c buffer contains a @c null pointer. @n
438 * - The length of the specified @c buffer is equal to or smaller than @c 0. @n
439 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
440 * - The file is not opened for read operation. @n
441 * - Access is denied due to insufficient permission.
442 * @exception E_END_OF_FILE The file pointer has reached end-of-file.
443 * @exception E_IO Either of the following conditions has occurred: @n
444 * - An unexpected device failure has occurred as the media ejected suddenly. @n
445 * - %File corruption is detected.
446 * @remarks The specific error code can be accessed using the GetLastResult() method.
448 int Read(void* buffer, int length);
451 * Reads the string data from the current file pointer and copies the string to the specified buffer (it is assumed that the
452 * file is in the UTF-8 format). @n
453 * The read operation continues until new line character or end-of-file is met. @n
454 * In the secure mode, the string data read from the secure file is automatically decrypted by a platform security module.
458 * @return An error code
459 * @param[out] buffer A reference to the buffer where the data is copied
460 * @exception E_SUCCESS The method is successful.
461 * @exception E_INVALID_ARG The file handle is invalid (either the file is closed by another method, or the
462 * memory is corrupted).
463 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
464 * - The file is not opened for read operation. @n
465 * - Access is denied due to insufficient permission.
466 * @exception E_END_OF_FILE The file pointer reached end-of-file.
467 * @exception E_IO Either of the following conditions has occurred:
468 * - An unexpected device failure has occurred as the media ejected suddenly. @n
469 * - %File corruption is detected.
470 * @remarks To get the expected string value
471 * from a file, which is not in the UTF-8 format (Unicode or any other format),
472 * user should use other encoding or decoding methods of the Tizen::Text namespace after reading the content of
473 * a file in binary format. @n
474 * The maximum length of characters read by this method is defined as 4096. @n
475 * Therefore, if the length of a single line (considering new line character or end-of-file) from the current
476 * file position is longer than 4096, the rest of the characters remain as not read. @n
477 * 'ByteBuffer' or 'void*' version of the File::Read() API can be used to overcome this limitation.
479 result Read(Tizen::Base::String& buffer);
482 * Writes the byte data from the specified ByteBuffer into a file beginning at the current position to the limit of the
484 * In the secure mode, the byte data written by a user is automatically encrypted to the secure file by a platform security module. @n
485 * The size of a secure file can be greater than the size of a normal (original) file
486 * because of the encryption.
487 * However, the file pointer for the secure file is equal to the file pointer for the original file.
491 * @return An error code
492 * @param[in] buffer A reference to the buffer that contains byte data to write
493 * @exception E_SUCCESS The method is successful.
494 * @exception E_INVALID_ARG The file handle is invalid (either the file is closed by another method, or the
495 * memory is corrupted).
496 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
497 * - The file is not opened for write operation. @n
498 * - Access is denied due to insufficient permission.
499 * @exception E_STORAGE_FULL The disk space is full.
500 * @exception E_IO Either of the following conditions has occurred: @n
501 * - An unexpected device failure has occurred as the media ejected suddenly. @n
502 * - %File corruption is detected.
504 result Write(const Tizen::Base::ByteBuffer& buffer);
507 * Writes the byte data into a file. @n
508 * In the secure mode, the byte data written by a user is automatically encrypted to the secure file by a platform security module. @n
509 * The size of a secure file can be greater than the size of a normal (original) file
510 * because of the encryption.
511 * However, the file pointer for the secure file is equal to the file pointer for the original file.
515 * @return An error code
516 * @param[in] buffer A pointer to the user-supplied buffer that contains @c byte data to write
517 * @param[in] length The buffer length in bytes
518 * @exception E_SUCCESS The method is successful.
519 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
520 * - The file is not opened for write operation. @n
521 * - Access is denied due to insufficient permission.
522 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
523 * - The specified @c buffer contains a @c null pointer. @n
524 * - The specified @c buffer length is equal or smaller than @c 0. @n
525 * @exception E_STORAGE_FULL The disk space is full.
526 * @exception E_IO Either of the following conditions has occurred: @n
527 * - An unexpected device failure has occurred as the media ejected suddenly. @n
528 * - %File corruption is detected.
530 result Write(const void* buffer, int length);
533 * Writes the string data into a file. @n
534 * In the secure mode, the string data written by a user is automatically encrypted to the secure file by a platform security
536 * The size of a secure file can be greater than the size of a normal (original) file
537 * because of the encryption.
538 * However, the file pointer for the secure file is equal to the file pointer for the original file.
542 * @return An error code
543 * @param[in] buffer A reference to the buffer that contains string data to write
544 * @exception E_SUCCESS The method is successful.
545 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
546 * - The file is not opened for write operation. @n
547 * - Access is denied due to insufficient permission.
548 * @exception E_INVALID_ARG The specified @c buffer contains an empty string.
549 * @exception E_STORAGE_FULL The disk space is full.
550 * @exception E_IO Either of the following conditions has occurred: @n
551 * - An unexpected device failure has occurred as the media ejected suddenly. @n
552 * - %File corruption is detected.
554 result Write(const Tizen::Base::String& buffer);
557 * Flushes the internally buffered data.
561 * @return An error code
562 * @exception E_SUCCESS The method is successful.
563 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
564 * @exception E_INVALID_ARG The file handle is invalid (either the file is closed by another method, or the
565 * memory is corrupted).
566 * @exception E_IO Either of the following conditions has occurred: @n
567 * - An unexpected device failure has occurred as the media ejected suddenly. @n
568 * - %File corruption is detected.
573 * Gets the offset of the current file pointer relative to the beginning of the file. @n
574 * The size of a secure file can be greater than the size of a normal (original) file
575 * because of the encryption.
576 * However, the file pointer for the secure file is equal to the file pointer for the original file.
580 * @return The offset of the current file pointer, @n
581 * else @c -1L if an error occurs
582 * @exception E_SUCCESS The method is successful.
583 * @exception E_INVALID_ARG The file handle is invalid (either the file is closed by another method, or the
584 * memory is corrupted).
585 * @exception E_IO Either of the following conditions has occurred: @n
586 * - An unexpected device failure has occurred as the media ejected suddenly. @n
587 * - %File corruption is detected.
588 * @remarks The specific error code can be accessed using the GetLastResult() method.
591 int Tell(void) const;
594 * Repositions the file pointer associated with an opened file. @n
595 * Each opened file has its own file pointer, and it points to the next byte to be read or written in the file.
596 * The repositioning offset can be specified with respect to the beginning of file, current position, or end of the file.
597 * If the file pointer is over the end-of-file, it expands the file size to the specified position and the expanded area is
598 * filled with zero. @n
599 * The size of a secure file can be greater than the size of a normal (original) file
600 * because of the encryption.
601 * However, the file pointer for the secure file is equal to the file pointer for the original file.
605 * @return An error code
606 * @param[in] position The origin from where to start the repositioning a file pointer
607 * @param[in] offset The number of bytes to move a file pointer @n
608 * A negative offset moves the pointer backwards.
609 * @exception E_SUCCESS The method is successful.
610 * @exception E_INVALID_ARG The specified @c position or @c offset is invalid.
611 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
612 * @exception E_STORAGE_FULL The disk space is full.
613 * @exception E_IO Either of the following conditions has occurred: @n
614 * - An unexpected device failure has occurred as the media ejected suddenly. @n
615 * - %File corruption is detected.
616 * @see FileSeekPosition
618 result Seek(FileSeekPosition position, long offset);
621 * Truncates the file size to the specified length. @n
622 * If the specified length is less than the length of file, the bytes present between the @c length and size of a file are
624 * If the file size is small, its size is increased. @n
625 * The size of a secure file can be greater than the size of a normal (original) file
626 * because of the encryption.
627 * However, the file pointer for a secure file is equal to the file pointer for an original file.
631 * @return An error code
632 * @param[in] length The required file size in bytes after this method is executed
633 * @exception E_SUCCESS The method is successful.
634 * @exception E_ILLEGAL_ACCESS Either of the following conditions has occurred: @n
635 * - The file is not opened for write operation. @n
636 * - Access is denied due to insufficient permission.
637 * @exception E_INVALID_ARG The specified @c length has a negative value.
638 * @exception E_STORAGE_FULL The disk space is full.
639 * @exception E_IO Either of the following conditions has occurred: @n
640 * - An unexpected device failure has occurred as the media ejected suddenly. @n
641 * - %File corruption is detected.
643 result Truncate(int length);
646 * Gets the path associated with a constructed %File.
650 * @return The file path to the currently constructed %File if successful, @n
651 * else an empty string in case of failure
653 Tizen::Base::String GetName(void) const;
656 * Acquires the file lock on the current opened whole file if it is not acquired.
657 * If the file lock is already acquired by another process, the current process is blocked until the file lock is
662 * @return The pointer to %FileLock instance, @n
663 * else @c null pointer in case of failure
664 * @param[in] lockType The type of file lock to be created
665 * @exception E_SUCCESS The method is successful.
666 * @exception E_INVALID_ARG The specified @c lockType is invalid.
667 * @exception E_INVALID_OPERATION Either of the following conditions has occurred: @n
668 * - The specified @c lockType cannot be FILE_LOCK_SHARED if the current
669 * file is not open for reading. @n
670 * - The specified @c lockType cannot be FILE_LOCK_EXCLUSIVE if the current
671 * file is not open for writing. @n
672 * @exception E_WOULD_DEADLOCK The method would cause a deadlock. @n
673 * The lock is blocked by a lock from another process, and putting the
674 * calling process to sleep to wait for that lock to become free would
676 * @exception E_MAX_EXCEEDED The number of file lock exceeds system limitations.
677 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
678 * @remarks The %FileLock instance is invalid if the associated %File instance is deleted. @n
679 * The specific error code can be accessed using the GetLastResult() method.
680 * @see Tizen::Io::File::FileLockType
682 FileLock* LockN(FileLockType lockType);
685 * Acquires the file lock on the specified region of the current opened file if it is not acquired.
686 * If the file lock is already acquired by another process, the current process is blocked until the file lock is
691 * @return The pointer to %FileLock instance, @n
692 * else @c null pointer in case of failure
693 * @param[in] lockType The type of file lock to be created
694 * @param[in] offset The starting offset for the locked region
695 * @param[in] length The length of the locked region in bytes
696 * @exception E_SUCCESS The method is successful.
697 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
698 * - The specified @c lockType is invalid.
699 * - The specified @c offset or @c length is negative or is greater than
700 * the system limitation.
701 * @exception E_INVALID_OPERATION Either of the following conditions has occurred: @n
702 * - The specified @c lockType cannot be FILE_LOCK_SHARED if the current
703 * file is not open for reading. @n
704 * - The specified @c lockType cannot be FILE_LOCK_EXCLUSIVE if the current
705 * file is not open for writing. @n
706 * @exception E_WOULD_DEADLOCK The method would cause a deadlock. @n
707 * The lock is blocked by a lock from another process, and putting the
708 * calling process to sleep to wait for that lock to become free would
710 * @exception E_MAX_EXCEEDED The number of file lock exceeds system limitations.
711 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
712 * @remarks The %FileLock instance is invalid if the associated %File instance is deleted. @n
713 * The specific error code can be accessed using the GetLastResult() method.
714 * @see Tizen::Io::File::FileLockType
716 FileLock* LockN(FileLockType lockType, int offset, int length);
719 * Tries to acquire the file lock on the current opened whole file.
720 * If the file lock is already acquired by another process, E_OBJECT_LOCKED is returned.
724 * @return The pointer to %FileLock instance, @n
725 * else @c null pointer in case of failure
726 * @param[in] lockType The type of file lock to be created
727 * @exception E_SUCCESS The method is successful.
728 * @exception E_INVALID_ARG The specified @c lockType is invalid.
729 * @exception E_INVALID_OPERATION Either of the following conditions has occurred: @n
730 * - The specified @c lockType cannot be FILE_LOCK_SHARED if the current
731 * file is not open for reading. @n
732 * - The specified @c lockType cannot be FILE_LOCK_EXCLUSIVE if the current
733 * file is not open for writing. @n
734 * @exception E_OBJECT_LOCKED Either of the following conditions has occurred: @n
735 * - The file lock is already held by another process. @n
736 * - The file to be locked has been memory-mapped by another process.
737 * @exception E_MAX_EXCEEDED The number of file lock exceeds system limitations.
738 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
739 * @remarks The %FileLock instance is invalid if the associated %File instance is deleted. @n
740 * The specific error code can be accessed using the GetLastResult() method.
741 * @see Tizen::Io::File::FileLockType
743 FileLock* TryToLockN(FileLockType lockType);
746 * Tries to acquire the file lock on the specified region of the current opened file.
747 * If the file lock is already acquired by another process, E_OBJECT_LOCKED is returned.
751 * @return The pointer to %FileLock instance, @n
752 * else @c null pointer in case of failure
753 * @param[in] lockType The type of file lock to be created
754 * @param[in] offset The starting offset for the locked region
755 * @param[in] length The length of the locked region in bytes
756 * @exception E_SUCCESS The method is successful.
757 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
758 * - The specified @c lockType is invalid.
759 * - The specified @c offset or @c length is negative or is greater than
760 * the system limitation.
761 * @exception E_INVALID_OPERATION Either of the following conditions has occurred: @n
762 * - The specified @c lockType cannot be FILE_LOCK_SHARED if the current
763 * file is not open for reading. @n
764 * - The specified @c lockType cannot be FILE_LOCK_EXCLUSIVE if the current
765 * file is not open for writing. @n
766 * @exception E_OBJECT_LOCKED Either of the following conditions has occurred: @n
767 * - The file lock is already held by another process. @n
768 * - The file to be locked has been memory-mapped by another process.
769 * @exception E_MAX_EXCEEDED The number of file lock exceeds system limitations.
770 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
771 * @remarks The %FileLock instance is invalid if the associated %File instance is deleted. @n
772 * The specific error code can be accessed using the GetLastResult() method.
773 * @see Tizen::Io::File::FileLockType
775 FileLock* TryToLockN(FileLockType lockType, int offset, int length);
778 * Deletes the file specified. @n
779 * The opened file cannot be deleted. This method is static.
782 * @brief <i> [Compatibility] </i>
786 * @compatibility This method has compatibility issues with OSP compatible applications. @n
787 * For more information, see @ref CompIoPathPage "here".
790 * @return An error code
791 * @param[in] filePath The path of the file to delete
792 * @exception E_SUCCESS The method is successful.
793 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
794 * - The overall length of the specified path is equal to @c 0 or
795 * exceeds system limitations. @n
796 * - The specified path is invalid.
797 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
798 * For example, opening a read-only file in the write mode.
799 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
800 * @exception E_IO Either of the following conditions has occurred: @n
801 * - An unexpected device failure has occurred as the media ejected suddenly. @n
802 * - %File corruption is detected.
803 * @remarks The opened file cannot be deleted.
805 static result Remove(const Tizen::Base::String& filePath);
808 * Moves the specified file to another location. @n
809 * The opened files cannot be moved. This method is static.
812 * @brief <i> [Compatibility] </i>
816 * @compatibility This method has compatibility issues with OSP compatible applications. @n
817 * For more information, see @ref CompIoPathPage "here".
820 * @return An error code
821 * @param[in] oldFilePath The old file path
822 * @param[in] newFilePath The new file path
823 * @exception E_SUCCESS The method is successful.
824 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
825 * - The overall length of the specified path is equal to @c 0 or
826 * exceeds system limitations. @n
827 * - The specified path is invalid.
828 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
829 * For example, opening a read-only file in the write mode.
830 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
831 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
832 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
833 * @exception E_STORAGE_FULL The disk space is full.
834 * @exception E_IO Either of the following conditions has occurred: @n
835 * - An unexpected device failure has occurred as the media ejected suddenly. @n
836 * - %File corruption is detected.
840 static result Move(const Tizen::Base::String& oldFilePath, const Tizen::Base::String& newFilePath);
843 * Copies the existing source file to the destined location. @n
844 * This method is static.
848 * @return An error code
849 * @param[in] srcFilePath The source file path
850 * @param[in] destFilePath The destination file path
851 * @param[in] failIfExist Set to @c true to return an error if the destination file already exists, @n
853 * @exception E_SUCCESS The method is successful.
854 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
855 * - The overall length of the specified path is equal to @c 0 or
856 * exceeds system limitations. @n
857 * - The specified path is invalid.
858 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission. @n
859 * For example, opening a read-only file in the write mode.
860 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
861 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
862 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
863 * @exception E_STORAGE_FULL The disk space is full.
864 * @exception E_IO Either of the following conditions has occurred: @n
865 * - An unexpected device failure has occurred as the media ejected suddenly. @n
866 * - %File corruption is detected.
870 static result Copy(const Tizen::Base::String& srcFilePath, const Tizen::Base::String& destFilePath, bool failIfExist);
873 * Reads the file information such as size, attribute, creation date, and so on. @n
874 * This method is static.
877 * @brief <i> [Compatibility] </i>
881 * @compatibility This method has compatibility issues with OSP compatible applications. @n
882 * For more information, see @ref CompIoPathPage "here".
885 * @return An error code
886 * @param[in] filePath The path of the file @n
887 * @param[out] attribute A %File attribute instance
888 * @exception E_SUCCESS The method is successful.
889 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
890 * - The overall length of the specified path is equal to @c 0 or
891 * exceeds system limitations. @n
892 * - The specified path is invalid.
893 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
894 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
895 * @exception E_IO Either of the following conditions has occurred: @n
896 * - An unexpected device failure has occurred as the media ejected suddenly. @n
897 * - %File corruption is detected.
899 static result GetAttributes(const Tizen::Base::String& filePath, FileAttributes& attribute);
902 * Gets only the file name from the specified file path. @n
903 * For example, if the file path passed is 'xxx/file.txt', 'file.txt' is returned.
906 * @brief <i> [Compatibility] </i>
910 * @compatibility This method has compatibility issues with OSP compatible applications. @n
911 * For more information, see @ref CompIoPathPage "here".
914 * @return The file name of type String
915 * @param[in] filePath The path of the file
916 * @exception E_SUCCESS The method is successful.
917 * @exception E_INVALID_ARG The length of the specified path is @c 0 or exceeds system limitations.
918 * @remarks The specific error code can be accessed using the GetLastResult() method.
919 * @see GetFileExtension()
921 static Tizen::Base::String GetFileName(const Tizen::Base::String& filePath);
924 * Gets the file extension of the specified file path.
927 * @brief <i> [Compatibility] </i>
931 * @compatibility This method has compatibility issues with OSP compatible applications. @n
932 * For more information, see @ref CompIoPathPage "here".
935 * @return The file extension, @n
936 * else an empty string if the file has no extension
937 * @param[in] filePath The path of the file
938 * @exception E_SUCCESS The method is successful.
939 * @exception E_INVALID_ARG The length of the specified path is @c 0 or exceeds system limitations.
940 * @remarks The specific error code can be accessed using the GetLastResult() method.
943 static Tizen::Base::String GetFileExtension(const Tizen::Base::String& filePath);
946 * Checks whether the specified file or directory exists.
949 * @brief <i> [Compatibility] </i>
953 * @compatibility This method has compatibility issues with OSP compatible applications. @n
954 * For more information, see @ref CompIoPathPage "here".
957 * @return @c true if file or directory exists, @n
959 * @param[in] filePath The path of the file or directory
960 * @exception E_SUCCESS The method is successful.
961 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
962 * - The overall length of the specified path is equal to @c 0 or
963 * exceeds system limitations. @n
964 * - The specified path is invalid.
965 * @exception E_ILLEGAL_ACCESS The specified path is not permitted, or
966 * access is denied due to insufficient permission.
967 * @remarks The specific error code can be accessed using the GetLastResult() method.
969 static bool IsFileExist(const Tizen::Base::String& filePath);
972 * Converts a normal file to a secure file. @n
973 * A secure file that is converted by this method can be shared among applications with the same key value.
974 * This method is static.
977 * @brief <i> [Compatibility] </i>
981 * @compatibility This method has compatibility issues with OSP compatible applications. @n
982 * For more information, see @ref CompIoPathPage "here".
985 * @return An error code
986 * @param[in] plainFilePath The normal (non-encrypted) file path
987 * @param[in] secureFilePath The secure (encrypted) file path to create
988 * @param[in] key A key that encrypts a secure file @n
989 * If the secure file is converted with a specific key value,
990 * applications can access the same secure file with the identical key value.
991 * @exception E_SUCCESS The method is successful.
992 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
993 * - The overall length of the specified path is equal to @c 0 or
994 * exceeds system limitations. @n
995 * - The specified path is invalid. @n
996 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
997 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
998 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
999 * @exception E_STORAGE_FULL The disk space is full.
1000 * @exception E_IO Either of the following conditions has occurred: @n
1001 * - An unexpected device failure has occurred as the media ejected suddenly. @n
1002 * - %File corruption is detected. @n
1003 * - The number of opened files has exceeded the maximum limit.
1005 static result ConvertToSecureFile(const Tizen::Base::String& plainFilePath, const Tizen::Base::String& secureFilePath, const Tizen::Base::ByteBuffer& key);
1009 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
1013 File(const File& rhs);
1016 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
1020 File& operator =(const File& rhs);
1022 class _FileImpl* __pFileImpl;
1024 friend class _FileImpl;
1030 #endif // _FIO_FILE_H_