Class IOChannel

All Implemented Interfaces:
PointerInterface

public class IOChannel extends Record
A data structure representing an IO Channel. The fields should be
considered private and should only be accessed with the following
functions.

https://docs.gtk.org/glib/struct.IOChannel.html

  • Field Details

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • getFieldRefCount

      public int getFieldRefCount()
    • getFieldFuncs

      public IOFuncs getFieldFuncs()
    • getFieldEncoding

      public Str getFieldEncoding()
    • newFileIOChannel

      public static IOChannel newFileIOChannel(@Nonnull Str filename, @Nonnull Str mode) throws AllocationError
      Open a file @filename as a #GIOChannel using mode @mode. This
      channel will be closed when the last reference to it is dropped,
      so there is no need to call g_io_channel_close() (though doing
      so will not cause problems, as long as no attempt is made to
      access the channel after it is closed).
      Parameters:
      filename - A string containing the name of a file
      mode - One of "r", "w", "a", "r+", "w+", "a+". These have the same meaning as in fopen()
      Returns:
      A #GIOChannel on success, %NULL on failure.
      Throws:
      AllocationError
    • newFileIOChannel

      public static IOChannel newFileIOChannel(String filename, String mode) throws AllocationError
      Open a file @filename as a #GIOChannel using mode @mode. This
      channel will be closed when the last reference to it is dropped,
      so there is no need to call g_io_channel_close() (though doing
      so will not cause problems, as long as no attempt is made to
      access the channel after it is closed).
      Parameters:
      filename - A string containing the name of a file
      mode - One of "r", "w", "a", "r+", "w+", "a+". These have the same meaning as in fopen()
      Returns:
      A #GIOChannel on success, %NULL on failure.
      Throws:
      AllocationError
    • unixNewIOChannel

      public static IOChannel unixNewIOChannel(int fd)
      Creates a new #GIOChannel given a file descriptor. On UNIX systems
      this works for plain files, pipes, and sockets.

      The returned #GIOChannel has a reference count of 1.

      The default encoding for #GIOChannel is UTF-8. If your application
      is reading output from a command using via pipe, you may need to set
      the encoding to the encoding of the current locale (see
      g_get_charset()) with the g_io_channel_set_encoding() function.
      By default, the fd passed will not be closed when the final reference
      to the #GIOChannel data structure is dropped.

      If you want to read raw binary data without interpretation, then
      call the g_io_channel_set_encoding() function with %NULL for the
      encoding argument.

      This function is available in GLib on Windows, too, but you should
      avoid using it on Windows. The domain of file descriptors and
      sockets overlap. There is no way for GLib to know which one you mean
      in case the argument you pass to this function happens to be both a
      valid file descriptor and socket. If that happens a warning is
      issued, and GLib assumes that it is the file descriptor you mean.
      Parameters:
      fd - a file descriptor.
      Returns:
      a new #GIOChannel.
    • flush

      public int flush() throws AllocationError
      Flushes the write buffer for the GIOChannel.
      Returns:
      the status of the operation: One of %G_IO_STATUS_NORMAL, %G_IO_STATUS_AGAIN, or %G_IO_STATUS_ERROR.
      Throws:
      AllocationError
    • getBufferCondition

      public int getBufferCondition()
      This function returns a #GIOCondition depending on whether there
      is data to be read/space to write data in the internal buffers in
      the #GIOChannel. Only the flags %G_IO_IN and %G_IO_OUT may be set.
      Returns:
      A #GIOCondition
    • getBufferSize

      public long getBufferSize()
      Gets the buffer size.
      Returns:
      the size of the buffer.
    • getBuffered

      public boolean getBuffered()
      Returns whether @channel is buffered.
      Returns:
      %TRUE if the @channel is buffered.
    • getCloseOnUnref

      public boolean getCloseOnUnref()
      Returns whether the file/socket/whatever associated with @channel
      will be closed when @channel receives its final unref and is
      destroyed. The default value of this is %TRUE for channels created
      by g_io_channel_new_file (), and %FALSE for all other channels.
      Returns:
      %TRUE if the channel will be closed, %FALSE otherwise.
    • getEncoding

      public Str getEncoding()
      Gets the encoding for the input/output of the channel.
      The internal encoding is always UTF-8. The encoding %NULL
      makes the channel safe for binary data.
      Returns:
      A string containing the encoding, this string is owned by GLib and must not be freed.
    • getFlags

      public int getFlags()
      Gets the current flags for a #GIOChannel, including read-only
      flags such as %G_IO_FLAG_IS_READABLE.

      The values of the flags %G_IO_FLAG_IS_READABLE and %G_IO_FLAG_IS_WRITABLE
      are cached for internal use by the channel when it is created.
      If they should change at some later point (e.g. partial shutdown
      of a socket with the UNIX shutdown() function), the user
      should immediately call g_io_channel_get_flags() to update
      the internal values of these flags.
      Returns:
      the flags which are set on the channel
    • getLineTerm

      public Str getLineTerm(@Nonnull Int length)
      This returns the string that #GIOChannel uses to determine
      where in the file a line break occurs. A value of %NULL
      indicates autodetection.
      Parameters:
      length - a location to return the length of the line terminator
      Returns:
      The line termination string. This value is owned by GLib and must not be freed.
    • init

      public void init()
      Initializes a #GIOChannel struct.

      This is called by each of the above functions when creating a
      #GIOChannel, and so is not often needed by the application
      programmer (unless you are creating a new type of #GIOChannel).
    • readChars

      public int readChars(@Nonnull Str buf, long count, @Nullable Int64 bytes_read) throws AllocationError
      Replacement for g_io_channel_read() with the new API.
      Parameters:
      buf - a buffer to read data into
      count - the size of the buffer. Note that the buffer may not be completely filled even if there is data in the buffer if the remaining data is not a complete character.
      bytes_read - The number of bytes read. This may be zero even on success if count < 6 and the channel's encoding is non-%NULL. This indicates that the next UTF-8 character is too wide for the buffer.
      Returns:
      the status of the operation.
      Throws:
      AllocationError
    • readLineString

      public int readLineString(@Nonnull GString buffer, @Nullable Int64 terminator_pos) throws AllocationError
      Reads a line from a #GIOChannel, using a #GString as a buffer.
      Parameters:
      buffer - a #GString into which the line will be written. If @buffer already contains data, the old data will be overwritten.
      terminator_pos - location to store position of line terminator, or %NULL
      Returns:
      the status of the operation.
      Throws:
      AllocationError
    • ref

      public IOChannel ref()
      Increments the reference count of a #GIOChannel.
      Returns:
      the @channel that was passed in (since 2.6)
    • seekPosition

      public int seekPosition(long offset, int type) throws AllocationError
      Replacement for g_io_channel_seek() with the new API.
      Parameters:
      offset - The offset in bytes from the position specified by @type
      type - a #GSeekType. The type %G_SEEK_CUR is only allowed in those cases where a call to g_io_channel_set_encoding () is allowed. See the documentation for g_io_channel_set_encoding () for details.
      Returns:
      the status of the operation.
      Throws:
      AllocationError
    • setBufferSize

      public void setBufferSize(long size)
      Sets the buffer size.
      Parameters:
      size - the size of the buffer, or 0 to let GLib pick a good size
    • setBuffered

      public void setBuffered(boolean buffered)
      The buffering state can only be set if the channel's encoding
      is %NULL. For any other encoding, the channel must be buffered.

      A buffered channel can only be set unbuffered if the channel's
      internal buffers have been flushed. Newly created channels or
      channels which have returned %G_IO_STATUS_EOF
      not require such a flush. For write-only channels, a call to
      g_io_channel_flush () is sufficient. For all other channels,
      the buffers may be flushed by a call to g_io_channel_seek_position ().
      This includes the possibility of seeking with seek type %G_SEEK_CUR
      and an offset of zero. Note that this means that socket-based
      channels cannot be set unbuffered once they have had data
      read from them.

      On unbuffered channels, it is safe to mix read and write
      calls from the new and old APIs, if this is necessary for
      maintaining old code.

      The default state of the channel is buffered.
      Parameters:
      buffered - whether to set the channel buffered or unbuffered
    • setCloseOnUnref

      public void setCloseOnUnref(boolean do_close)
      Whether to close the channel on the final unref of the #GIOChannel
      data structure. The default value of this is %TRUE for channels
      created by g_io_channel_new_file (), and %FALSE for all other channels.

      Setting this flag to %TRUE for a channel you have already closed
      can cause problems when the final reference to the #GIOChannel is dropped.
      Parameters:
      do_close - Whether to close the channel on the final unref of the GIOChannel data structure.
    • setEncoding

      public int setEncoding(@Nullable Str encoding) throws AllocationError
      Sets the encoding for the input/output of the channel.
      The internal encoding is always UTF-8. The default encoding
      for the external file is UTF-8.

      The encoding %NULL is safe to use with binary data.

      The encoding can only be set if one of the following conditions
      is true:

      - The channel was just created, and has not been written to or read from yet.

      - The channel is write-only.

      - The channel is a file, and the file pointer was just repositioned
      by a call to g_io_channel_seek_position(). (This flushes all the
      internal buffers.)

      - The current encoding is %NULL or UTF-8.

      - One of the (new API) read functions has just returned %G_IO_STATUS_EOF
      (or, in the case of g_io_channel_read_to_end(), %G_IO_STATUS_NORMAL).

      - One of the functions g_io_channel_read_chars() or
      g_io_channel_read_unichar() has returned %G_IO_STATUS_AGAIN or
      %G_IO_STATUS_ERROR. This may be useful in the case of
      %G_CONVERT_ERROR_ILLEGAL_SEQUENCE.
      Returning one of these statuses from g_io_channel_read_line(),
      g_io_channel_read_line_string(), or g_io_channel_read_to_end()
      does not guarantee that the encoding can be changed.

      Channels which do not meet one of the above conditions cannot call
      g_io_channel_seek_position() with an offset of %G_SEEK_CUR, and, if
      they are "seekable", cannot call g_io_channel_write_chars() after
      calling one of the API "read" functions.
      Parameters:
      encoding - the encoding type
      Returns:
      %G_IO_STATUS_NORMAL if the encoding was successfully set
      Throws:
      AllocationError
    • setEncoding

      public int setEncoding(String encoding) throws AllocationError
      Sets the encoding for the input/output of the channel.
      The internal encoding is always UTF-8. The default encoding
      for the external file is UTF-8.

      The encoding %NULL is safe to use with binary data.

      The encoding can only be set if one of the following conditions
      is true:

      - The channel was just created, and has not been written to or read from yet.

      - The channel is write-only.

      - The channel is a file, and the file pointer was just repositioned
      by a call to g_io_channel_seek_position(). (This flushes all the
      internal buffers.)

      - The current encoding is %NULL or UTF-8.

      - One of the (new API) read functions has just returned %G_IO_STATUS_EOF
      (or, in the case of g_io_channel_read_to_end(), %G_IO_STATUS_NORMAL).

      - One of the functions g_io_channel_read_chars() or
      g_io_channel_read_unichar() has returned %G_IO_STATUS_AGAIN or
      %G_IO_STATUS_ERROR. This may be useful in the case of
      %G_CONVERT_ERROR_ILLEGAL_SEQUENCE.
      Returning one of these statuses from g_io_channel_read_line(),
      g_io_channel_read_line_string(), or g_io_channel_read_to_end()
      does not guarantee that the encoding can be changed.

      Channels which do not meet one of the above conditions cannot call
      g_io_channel_seek_position() with an offset of %G_SEEK_CUR, and, if
      they are "seekable", cannot call g_io_channel_write_chars() after
      calling one of the API "read" functions.
      Parameters:
      encoding - the encoding type
      Returns:
      %G_IO_STATUS_NORMAL if the encoding was successfully set
      Throws:
      AllocationError
    • setFlags

      public int setFlags(int flags) throws AllocationError
      Sets the (writeable) flags in @channel to (@flags & %G_IO_FLAG_SET_MASK).
      Parameters:
      flags - the flags to set on the IO channel
      Returns:
      the status of the operation.
      Throws:
      AllocationError
    • setLineTerm

      public void setLineTerm(@Nullable Str line_term, int length)
      This sets the string that #GIOChannel uses to determine
      where in the file a line break occurs.
      Parameters:
      line_term - The line termination string. Use %NULL for autodetect. Autodetection breaks on "\n", "\r\n", "\r", "\0", and the Unicode paragraph separator. Autodetection should not be used for anything other than file-based channels.
      length - The length of the termination string. If -1 is passed, the string is assumed to be nul-terminated. This option allows termination strings with embedded nuls.
    • setLineTerm

      public void setLineTerm(String line_term, int length)
      This sets the string that #GIOChannel uses to determine
      where in the file a line break occurs.
      Parameters:
      line_term - The line termination string. Use %NULL for autodetect. Autodetection breaks on "\n", "\r\n", "\r", "\0", and the Unicode paragraph separator. Autodetection should not be used for anything other than file-based channels.
      length - The length of the termination string. If -1 is passed, the string is assumed to be nul-terminated. This option allows termination strings with embedded nuls.
    • shutdown

      public int shutdown(boolean flush) throws AllocationError
      Close an IO channel. Any pending data to be written will be
      flushed if @flush is %TRUE. The channel will not be freed until the
      last reference is dropped using g_io_channel_unref().
      Parameters:
      flush - if %TRUE, flush pending
      Returns:
      the status of the operation.
      Throws:
      AllocationError
    • unixGetFd

      public int unixGetFd()
      Returns the file descriptor of the #GIOChannel.

      On Windows this function returns the file descriptor or socket of
      the #GIOChannel.
      Returns:
      the file descriptor of the #GIOChannel.
    • unref

      public void unref()
      Decrements the reference count of a #GIOChannel.
    • writeChars

      public int writeChars(@Nonnull Str buf, long count, @Nonnull Int64 bytes_written) throws AllocationError
      Replacement for g_io_channel_write() with the new API.

      On seekable channels with encodings other than %NULL or UTF-8, generic
      mixing of reading and writing is not allowed. A call to g_io_channel_write_chars ()
      may only be made on a channel from which data has been read in the
      cases described in the documentation for g_io_channel_set_encoding ().
      Parameters:
      buf - a buffer to write data from
      count - the size of the buffer. If -1, the buffer is taken to be a nul-terminated string.
      bytes_written - The number of bytes written. This can be nonzero even if the return value is not %G_IO_STATUS_NORMAL. If the return value is %G_IO_STATUS_NORMAL and the channel is blocking, this will always be equal to @count if @count >= 0.
      Returns:
      the status of the operation.
      Throws:
      AllocationError
    • writeChars

      public int writeChars(String buf, long count, @Nonnull Int64 bytes_written) throws AllocationError
      Replacement for g_io_channel_write() with the new API.

      On seekable channels with encodings other than %NULL or UTF-8, generic
      mixing of reading and writing is not allowed. A call to g_io_channel_write_chars ()
      may only be made on a channel from which data has been read in the
      cases described in the documentation for g_io_channel_set_encoding ().
      Parameters:
      buf - a buffer to write data from
      count - the size of the buffer. If -1, the buffer is taken to be a nul-terminated string.
      bytes_written - The number of bytes written. This can be nonzero even if the return value is not %G_IO_STATUS_NORMAL. If the return value is %G_IO_STATUS_NORMAL and the channel is blocking, this will always be equal to @count if @count >= 0.
      Returns:
      the status of the operation.
      Throws:
      AllocationError
    • writeUnichar

      public int writeUnichar(byte thechar) throws AllocationError
      Writes a Unicode character to @channel.
      This function cannot be called on a channel with %NULL encoding.
      Parameters:
      thechar - a character
      Returns:
      a #GIOStatus
      Throws:
      AllocationError
    • errorFromErrno

      public static int errorFromErrno(int en)
      Converts an `errno` error number to a #GIOChannelError.
      Parameters:
      en - an `errno` error number, e.g. `EINVAL`
      Returns:
      a #GIOChannelError error number, e.g. %G_IO_CHANNEL_ERROR_INVAL.
    • errorQuark

      public static int errorQuark()
      Returns:
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()