Class Filename

java.lang.Object
org.javagi.base.Filename

public final class Filename extends Object
A character string in the filesystem encoding.

GLib I/O-related functions use this for compatibility with non-utf8 encoded filesystems. To display a Filename on-screen, convert it to a Java String with toString() or toString(Charset).

For more information, consult the GLib documentation on character set conversions.

Most Java methods generated by Java-GI that take Filename arguments are overloaded for convenience with a method that accepts a String argument instead of a Filename.

  • Constructor Details

    • Filename

      public Filename(MemorySegment data, TransferOwnership transfer)
      Create a Filename object from a null-terminated filename in native memory.
      Parameters:
      data - the null-terminated filename in native memory
      transfer - to free the native memory when ownership is transferred
    • Filename

      public Filename(MemorySegment data, long size, TransferOwnership transfer)
      Create a Filename object from a filename in native memory.
      Parameters:
      data - the filename in native memory
      size - the size of the filename
      transfer - to free the native memory when ownership is transferred
    • Filename

      public Filename(String string)
      Create a Filename object from a Java String. The string is converted to the native filesystem encoding with g_filename_from_utf8().
      Parameters:
      string - the filename
      Throws:
      IllegalArgumentException - when the string cannot be converted to the encoding of the filesystem. This can happen if string contains Japanese characters when the filesystem encoding is set to ISO-8859-1, for example.
  • Method Details

    • toMemorySegment

      public MemorySegment toMemorySegment(SegmentAllocator alloc)
      Write the filename to native memory.
      Parameters:
      alloc - used to allocate the filename
      Returns:
      the newly allocated memory segment with the filename
    • toString

      public String toString()
      Convert the filename to a Java String. The string is converted with g_filename_to_utf8().
      Overrides:
      toString in class Object
      Returns:
      the filename
      Throws:
      IllegalArgumentException - when the filename cannot be converted to utf8.
    • toString

      public String toString(Charset charset)
      Convert the filename to a Java String, using the provided Charset. The string is converted with String(byte[], Charset).
      Parameters:
      charset - the charset to decode the filename to a String
      Returns:
      the filename
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • convertArray

      public static @Nullable String @Nullable [] convertArray(@Nullable Filename @Nullable [] filenames)
      Convert an array of Filenames to an array of Strings.
      Parameters:
      filenames - array of filenames
      Returns:
      array of strings
    • convertArray

      public static @Nullable Filename @Nullable [] convertArray(@Nullable String @Nullable [] strings)
      Convert an array of Strings to an array of Filenames.
      Parameters:
      strings - array of strings
      Returns:
      array of filenames