Jameo Core Library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
jm::File Class Reference

This field stores the directory separator character based on the operating system. More...

Inheritance diagram for jm::File:
jm::Stream jm::Comparable< File > jm::Object

Public Member Functions

 File ()
 Default constructor. The file has no name.
 
 File (const String &pathname)
 Constructor.
 
 File (String parent, String child)
 Constructor.
 
 File (const File &parent, String child)
 Constructor.
 
 File (const File &other)
 Copy constructor.
 
 ~File () override=default
 Destructor.
 
bool isNull () const
 checks if the file is null (has no path).
 
bool canExecute () const
 Checks if the file can be executed.
 
bool canRead () const override
 Checks if the file can be read.
 
bool canWrite () const
 Checks if the file can be written.
 
bool createNewFile ()
 Creates a new file, but only, if the file not exist. If the file exists, nothing happens.
 
bool makeDirectory ()
 Create a new directory.
 
bool exists () const
 Checks if the file exists.
 
bool remove ()
 This method deletes the file permanently. If it is a directory, it will only be deleted if it is empty.
 
bool moveToTrash ()
 Moves the file to the system trash.
 
bool renameTo (const String &newPath)
 Renames the file to a new name.
 
String name () const
 Returns the name of the file. This is the pure name without any path information.
 
String parent () const
 Returns the directory path of the file, excluding the file name itself. It corresponds to the directory in which this file is located.
 
const StringabsolutePath () const
 Returns the absolute path of the file from the root of the file system.
 
String path () const
 Returns the full path of this file. The path can be relative or absolute.
 
String extension () const
 This method returns the file extension of the file. If the file does not have an extension, the return value is an empty string. An extension is indicated by a dot. For ".tar.gz", only "gz" is returned.
 
bool isAbsolute () const
 Checks if this file is an absolute path.
 
bool isDirectory () const
 Checks if this file is a directory.
 
bool isFile () const
 Checks if this file is a regular file.
 
bool isLink () const
 Checks if this file is a symbolic link.
 
bool isPipe () const
 Checks if this file is a named pipe (FIFO).
 
bool isHidden () const
 Checks if this file is hidden.
 
Array< File > * listFiles () const
 Retrieves a list of all files in the directory.
 
size_t size () const override
 Returns the size of the file in bytes.
 
Date lastModified () const
 Returns the date of the last modification.
 
Status open (FileMode mode) override
 Opens the file for read or write operations.
 
bool isOpen () override
 Checks if the file is open.
 
void close () override
 Closes the file if it was previously opened.
 
size_t read (unsigned char *buffer, size_t size) override
 Reads a maximum of length bytes into the array. \discussion For large blocks, it is possible that not all bytes are read because it is still waiting for data. In this case, only a portion may be returned. If you want to ensure that all data is read, you should call "readFully".
 
size_t readFully (ByteArray &buffer, size_t length) override
 Reads a maximum of length bytes into the array.
 
void seek (size_t position) override
 Moves the file cursor to the desired position, counted from the beginning of the file.
 
void move (ssize_t offset) override
 Moves the file cursor to the desired position, relative to the current position.
 
size_t position () override
 Returns the current cursor position in the file.
 
size_t write (const uint8 *buffer, size_t length) override
 Writes a buffer to the output file.
 
int32 compareTo (const File &other) const override
 Compares the absolute file path with another file's absolute path.
 
StringList getTags () const
 Returns the tags of the file.
 
Status addTag (const String &tag)
 Adds a tag to the file. If the tag already exists, nothing happens.
 
Status removeTag (const String &tag)
 Remove a tag from the file. If the tag not exists, nothing happens.
 
Fileoperator= (const File &another)
 
- Public Member Functions inherited from jm::Stream
 Stream ()
 Constructor.
 
size_t readFully (ByteArray &buffer)
 Reads a maximum of length bytes into the array.
 
size_t write (const int8 *buffer, size_t length)
 Writes a buffer to the output file.
 
size_t write (const String &string)
 Writes a string to the output file. The encoding is the default encoding (UTF-8). NOT AS A C-STRING!
 
- Public Member Functions inherited from jm::Object
 Object () noexcept
 Constructor.
 
virtual ~Object () noexcept
 Destructor.
 
void release () noexcept
 Decreases the reference counter and releases the object immediately when the reference counter becomes 0.
 
Objectretain () noexcept
 Increases the reference counter of this object by 1.
 
Objectautorelease () noexcept
 Same function as release(), but releases the object with a delay if the reference counter is 0. AutoreleasePool::drain() must be called in the to release the object.
 
int32 referenceCount () const noexcept
 Returns the value of the reference counter.
 
virtual bool equals (const Object *other) const
 Comparison of objects.
 
virtual String displayName () const
 Returns the display name of the object intended to present to a user.
 
virtual void printDiffInfo (DiffOperation operation, Object *other) const
 Output method for outputting the diff results for the diff algorithm.
 
void setHighBit (bool status) noexcept
 
bool highBit () const noexcept
 
- Public Member Functions inherited from jm::Comparable< File >
 Comparable ()
 
virtual ~Comparable ()
 

Detailed Description

This field stores the directory separator character based on the operating system.

This class is a representation of file or directory paths. In addition, data can be read from and written to the hard disk.

Constructor & Destructor Documentation

◆ File() [1/5]

jm::File::File ( )

Default constructor. The file has no name.

◆ File() [2/5]

jm::File::File ( const String pathname)
explicit

Constructor.

Parameters
pathnamePath to the file.

◆ File() [3/5]

jm::File::File ( String  parent,
String  child 
)

Constructor.

Parameters
parentPath of parent file.
childPath of child file.

◆ File() [4/5]

jm::File::File ( const File parent,
String  child 
)

Constructor.

Parameters
parentFile object of parent file
childPath of child file

◆ File() [5/5]

jm::File::File ( const File other)

Copy constructor.

◆ ~File()

jm::File::~File ( )
overridedefault

Destructor.

Member Function Documentation

◆ absolutePath()

const String & jm::File::absolutePath ( ) const

Returns the absolute path of the file from the root of the file system.

Returns
The absolute path of the file.

◆ addTag()

Status jm::File::addTag ( const String tag)

Adds a tag to the file. If the tag already exists, nothing happens.

◆ canExecute()

bool jm::File::canExecute ( ) const

Checks if the file can be executed.

◆ canRead()

bool jm::File::canRead ( ) const
overridevirtual

Checks if the file can be read.

Implements jm::Stream.

◆ canWrite()

bool jm::File::canWrite ( ) const

Checks if the file can be written.

◆ close()

void jm::File::close ( )
overridevirtual

Closes the file if it was previously opened.

Implements jm::Stream.

◆ compareTo()

int32 jm::File::compareTo ( const File other) const
overridevirtual

Compares the absolute file path with another file's absolute path.

Parameters
otherThe file to compare with.
Returns
An integer value indicating the result of the comparison:
  • 0 if the file paths are equal.
  • a negative value if this file path is lexicographically less than the other file path.
  • a positive value if this file path is lexicographically greater than the other file path.

Implements jm::Comparable< File >.

◆ createNewFile()

bool jm::File::createNewFile ( )

Creates a new file, but only, if the file not exist. If the file exists, nothing happens.

Returns
true, if a new file was created. false otherwise.

◆ exists()

bool jm::File::exists ( ) const

Checks if the file exists.

◆ extension()

String jm::File::extension ( ) const

This method returns the file extension of the file. If the file does not have an extension, the return value is an empty string. An extension is indicated by a dot. For ".tar.gz", only "gz" is returned.

Returns
The file extension.

◆ getTags()

StringList jm::File::getTags ( ) const

Returns the tags of the file.

In mac os these tags are presented by the Finder.

◆ isAbsolute()

bool jm::File::isAbsolute ( ) const

Checks if this file is an absolute path.

Returns
true if the file is an absolute path, false otherwise.

◆ isDirectory()

bool jm::File::isDirectory ( ) const

Checks if this file is a directory.

Returns
true if the file is a directory, false otherwise.

◆ isFile()

bool jm::File::isFile ( ) const

Checks if this file is a regular file.

Returns
true if the file is a regular file, false otherwise.

◆ isHidden()

bool jm::File::isHidden ( ) const

Checks if this file is hidden.

Returns
true if the file is hidden, false otherwise.

◆ isLink()

bool jm::File::isLink ( ) const

Checks if this file is a symbolic link.

Returns
true if the file is a symbolic link, false otherwise.

◆ isNull()

bool jm::File::isNull ( ) const

checks if the file is null (has no path).

◆ isOpen()

bool jm::File::isOpen ( )
overridevirtual

Checks if the file is open.

Returns
true if the file is open, false otherwise.

Implements jm::Stream.

◆ isPipe()

bool jm::File::isPipe ( ) const

Checks if this file is a named pipe (FIFO).

Returns
true if the file is a named pipe, false otherwise.

◆ lastModified()

Date jm::File::lastModified ( ) const

Returns the date of the last modification.

Returns
The date of the last modification.

◆ listFiles()

Array< File > * jm::File::listFiles ( ) const

Retrieves a list of all files in the directory.

Returns
A dynamically allocated array of File objects representing the files in the directory. The caller is responsible for deleting the array.

◆ makeDirectory()

bool jm::File::makeDirectory ( )

Create a new directory.

Returns
true, if a new directory was created. false otherwise.

◆ move()

void jm::File::move ( ssize_t  offset)
overridevirtual

Moves the file cursor to the desired position, relative to the current position.

Parameters
offsetThe offset to move the file cursor by. This variable is signed and can be negative.

Implements jm::Stream.

◆ moveToTrash()

bool jm::File::moveToTrash ( )

Moves the file to the system trash.

◆ name()

String jm::File::name ( ) const

Returns the name of the file. This is the pure name without any path information.

Returns
The name of the file.

◆ open()

Status jm::File::open ( FileMode  mode)
overridevirtual

Opens the file for read or write operations.

Parameters
modeThe mode for opening the file.

Implements jm::Stream.

◆ operator=()

File & jm::File::operator= ( const File another)

◆ parent()

String jm::File::parent ( ) const

Returns the directory path of the file, excluding the file name itself. It corresponds to the directory in which this file is located.

Returns
The directory path of the file.

◆ path()

String jm::File::path ( ) const

Returns the full path of this file. The path can be relative or absolute.

Returns
The full path of the file.

◆ position()

size_t jm::File::position ( )
overridevirtual

Returns the current cursor position in the file.

Returns
The current cursor position.

Implements jm::Stream.

◆ read()

size_t jm::File::read ( unsigned char *  buffer,
size_t  size 
)
overridevirtual

Reads a maximum of length bytes into the array. \discussion For large blocks, it is possible that not all bytes are read because it is still waiting for data. In this case, only a portion may be returned. If you want to ensure that all data is read, you should call "readFully".

Parameters
bufferThe buffer to read the data into.
sizeThe maximum number of bytes to read.
Returns
The actual number of bytes read, or 0 if no bytes were read (EOF).

Implements jm::Stream.

◆ readFully()

size_t jm::File::readFully ( ByteArray buffer,
size_t  length 
)
overridevirtual

Reads a maximum of length bytes into the array.

Parameters
bufferThe buffer to read the data into.
lengthThe maximum number of bytes to read.
Returns
The actual number of bytes read, or 0 if no bytes were read (EOF).

Implements jm::Stream.

◆ remove()

bool jm::File::remove ( )

This method deletes the file permanently. If it is a directory, it will only be deleted if it is empty.

Returns
true if the file was successfully deleted, false otherwise.

◆ removeTag()

Status jm::File::removeTag ( const String tag)

Remove a tag from the file. If the tag not exists, nothing happens.

◆ renameTo()

bool jm::File::renameTo ( const String newPath)

Renames the file to a new name.

Parameters
newPathThe new path and name for the file.

◆ seek()

void jm::File::seek ( size_t  position)
overridevirtual

Moves the file cursor to the desired position, counted from the beginning of the file.

Parameters
positionThe desired position to move the file cursor to (0-based index).

Implements jm::Stream.

◆ size()

size_t jm::File::size ( ) const
overridevirtual

Returns the size of the file in bytes.

Returns
The size of the file in bytes.

Implements jm::Stream.

◆ write()

size_t jm::File::write ( const uint8 *  buffer,
size_t  length 
)
overridevirtual

Writes a buffer to the output file.

Parameters
bufferThe buffer containing the data to be written.
lengthThe number of bytes to write from the buffer.
Returns
The number of bytes actually written, or 0 if an error occurred.

Implements jm::Stream.