Class DataInputStream

All Implemented Interfaces:
PointerInterface

public class DataInputStream extends BufferedInputStream
Data input stream implements #GInputStream and includes functions for
reading structured data directly from a binary input stream.

https://docs.gtk.org/gio/class.DataInputStream.html

  • Constructor Details

    • DataInputStream

      public DataInputStream(PointerContainer pointer)
    • DataInputStream

      public DataInputStream(@Nonnull InputStream base_stream)
      Creates a new data input stream for the @base_stream.
      Parameters:
      base_stream - a #GInputStream.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • getByteOrder

      public int getByteOrder()
      Gets the byte order for the data input stream.
      Returns:
      the @stream's current #GDataStreamByteOrder.
    • getNewlineType

      public int getNewlineType()
      Gets the current newline type for the @stream.
      Returns:
      #GDataStreamNewlineType for the given @stream.
    • readInt16

      public int readInt16(@Nullable Cancellable cancellable) throws AllocationError
      Reads a 16-bit/2-byte value from @stream.

      In order to get the correct byte order for this read operation,
      see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
      Parameters:
      cancellable - optional #GCancellable object, %NULL to ignore.
      Returns:
      a signed 16-bit/2-byte value read from @stream or `0` if an error occurred.
      Throws:
      AllocationError
    • readInt32

      public int readInt32(@Nullable Cancellable cancellable) throws AllocationError
      Reads a signed 32-bit/4-byte value from @stream.

      In order to get the correct byte order for this read operation,
      see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().

      If @cancellable is not %NULL, then the operation can be cancelled by
      triggering the cancellable object from another thread. If the operation
      was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
      Parameters:
      cancellable - optional #GCancellable object, %NULL to ignore.
      Returns:
      a signed 32-bit/4-byte value read from the @stream or `0` if an error occurred.
      Throws:
      AllocationError
    • readInt64

      public long readInt64(@Nullable Cancellable cancellable) throws AllocationError
      Reads a 64-bit/8-byte value from @stream.

      In order to get the correct byte order for this read operation,
      see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().

      If @cancellable is not %NULL, then the operation can be cancelled by
      triggering the cancellable object from another thread. If the operation
      was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
      Parameters:
      cancellable - optional #GCancellable object, %NULL to ignore.
      Returns:
      a signed 64-bit/8-byte value read from @stream or `0` if an error occurred.
      Throws:
      AllocationError
    • readLine

      public Str readLine(@Nullable Int64 length, @Nullable Cancellable cancellable) throws AllocationError
      Reads a line from the data input stream. Note that no encoding
      checks or conversion is performed; the input is not guaranteed to
      be UTF-8, and may in fact have embedded NUL characters.

      If @cancellable is not %NULL, then the operation can be cancelled by
      triggering the cancellable object from another thread. If the operation
      was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
      Parameters:
      length - a #gsize to get the length of the data read in.
      cancellable - optional #GCancellable object, %NULL to ignore.
      Returns:
      a NUL terminated byte array with the line that was read in (without the newlines). Set @length to a #gsize to get the length of the read line. On an error, it will return %NULL and @error will be set. If there's no content to read, it will still return %NULL, but @error won't be set.
      Throws:
      AllocationError
    • readLineAsync

      public void readLineAsync(int io_priority, @Nullable Cancellable cancellable, DataInputStream.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      The asynchronous version of g_data_input_stream_read_line(). It is
      an error to have two outstanding calls to this function.

      When the operation is finished, @callback will be called. You
      can then call g_data_input_stream_read_line_finish() to get
      the result of the operation.
      Parameters:
      io_priority - the [I/O priority][io-priority] of the request
      cancellable - optional #GCancellable object, %NULL to ignore.
      callback - callback to call when the request is satisfied.
      user_data - the data to pass to callback function.
    • readLineFinish

      public Str readLineFinish(@Nonnull AsyncResult result, @Nullable Int64 length) throws AllocationError
      Finish an asynchronous call started by
      g_data_input_stream_read_line_async(). Note the warning about
      string encoding in g_data_input_stream_read_line() applies here as
      well.
      Parameters:
      result - the #GAsyncResult that was provided to the callback.
      length - a #gsize to get the length of the data read in.
      Returns:
      a NUL-terminated byte array with the line that was read in (without the newlines). Set @length to a #gsize to get the length of the read line. On an error, it will return %NULL and @error will be set. If there's no content to read, it will still return %NULL, but @error won't be set.
      Throws:
      AllocationError
    • readLineFinishUtf8

      public Str readLineFinishUtf8(@Nonnull AsyncResult result, @Nullable Int64 length) throws AllocationError
      Finish an asynchronous call started by
      g_data_input_stream_read_line_async().
      Parameters:
      result - the #GAsyncResult that was provided to the callback.
      length - a #gsize to get the length of the data read in.
      Returns:
      a string with the line that was read in (without the newlines). Set @length to a #gsize to get the length of the read line. On an error, it will return %NULL and @error will be set. For UTF-8 conversion errors, the set error domain is %G_CONVERT_ERROR. If there's no content to read, it will still return %NULL, but @error won't be set.
      Throws:
      AllocationError
    • readLineUtf8

      public Str readLineUtf8(@Nullable Int64 length, @Nullable Cancellable cancellable) throws AllocationError
      Reads a UTF-8 encoded line from the data input stream.

      If @cancellable is not %NULL, then the operation can be cancelled by
      triggering the cancellable object from another thread. If the operation
      was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
      Parameters:
      length - a #gsize to get the length of the data read in.
      cancellable - optional #GCancellable object, %NULL to ignore.
      Returns:
      a NUL terminated UTF-8 string with the line that was read in (without the newlines). Set @length to a #gsize to get the length of the read line. On an error, it will return %NULL and @error will be set. For UTF-8 conversion errors, the set error domain is %G_CONVERT_ERROR. If there's no content to read, it will still return %NULL, but @error won't be set.
      Throws:
      AllocationError
    • readUint16

      public int readUint16(@Nullable Cancellable cancellable) throws AllocationError
      Reads an unsigned 16-bit/2-byte value from @stream.

      In order to get the correct byte order for this read operation,
      see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
      Parameters:
      cancellable - optional #GCancellable object, %NULL to ignore.
      Returns:
      an unsigned 16-bit/2-byte value read from the @stream or `0` if an error occurred.
      Throws:
      AllocationError
    • readUint32

      public int readUint32(@Nullable Cancellable cancellable) throws AllocationError
      Reads an unsigned 32-bit/4-byte value from @stream.

      In order to get the correct byte order for this read operation,
      see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().

      If @cancellable is not %NULL, then the operation can be cancelled by
      triggering the cancellable object from another thread. If the operation
      was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
      Parameters:
      cancellable - optional #GCancellable object, %NULL to ignore.
      Returns:
      an unsigned 32-bit/4-byte value read from the @stream or `0` if an error occurred.
      Throws:
      AllocationError
    • readUint64

      public long readUint64(@Nullable Cancellable cancellable) throws AllocationError
      Reads an unsigned 64-bit/8-byte value from @stream.

      In order to get the correct byte order for this read operation,
      see g_data_input_stream_get_byte_order().

      If @cancellable is not %NULL, then the operation can be cancelled by
      triggering the cancellable object from another thread. If the operation
      was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
      Parameters:
      cancellable - optional #GCancellable object, %NULL to ignore.
      Returns:
      an unsigned 64-bit/8-byte read from @stream or `0` if an error occurred.
      Throws:
      AllocationError
    • readUpto

      public Str readUpto(@Nonnull Str stop_chars, long stop_chars_len, @Nullable Int64 length, @Nullable Cancellable cancellable) throws AllocationError
      Reads a string from the data input stream, up to the first
      occurrence of any of the stop characters.

      In contrast to g_data_input_stream_read_until(), this function
      does not consume the stop character. You have to use
      g_data_input_stream_read_byte() to get it before calling
      g_data_input_stream_read_upto() again.

      Note that @stop_chars may contain '\0' if @stop_chars_len is
      specified.

      The returned string will always be nul-terminated on success.
      Parameters:
      stop_chars - characters to terminate the read
      stop_chars_len - length of @stop_chars. May be -1 if @stop_chars is nul-terminated
      length - a #gsize to get the length of the data read in
      cancellable - optional #GCancellable object, %NULL to ignore
      Returns:
      a string with the data that was read before encountering any of the stop characters. Set @length to a #gsize to get the length of the string. This function will return %NULL on an error
      Throws:
      AllocationError
    • readUpto

      public Str readUpto(String stop_chars, long stop_chars_len, @Nullable Int64 length, @Nullable Cancellable cancellable) throws AllocationError
      Reads a string from the data input stream, up to the first
      occurrence of any of the stop characters.

      In contrast to g_data_input_stream_read_until(), this function
      does not consume the stop character. You have to use
      g_data_input_stream_read_byte() to get it before calling
      g_data_input_stream_read_upto() again.

      Note that @stop_chars may contain '\0' if @stop_chars_len is
      specified.

      The returned string will always be nul-terminated on success.
      Parameters:
      stop_chars - characters to terminate the read
      stop_chars_len - length of @stop_chars. May be -1 if @stop_chars is nul-terminated
      length - a #gsize to get the length of the data read in
      cancellable - optional #GCancellable object, %NULL to ignore
      Returns:
      a string with the data that was read before encountering any of the stop characters. Set @length to a #gsize to get the length of the string. This function will return %NULL on an error
      Throws:
      AllocationError
    • readUptoAsync

      public void readUptoAsync(@Nonnull Str stop_chars, long stop_chars_len, int io_priority, @Nullable Cancellable cancellable, DataInputStream.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      The asynchronous version of g_data_input_stream_read_upto().
      It is an error to have two outstanding calls to this function.

      In contrast to g_data_input_stream_read_until(), this function
      does not consume the stop character. You have to use
      g_data_input_stream_read_byte() to get it before calling
      g_data_input_stream_read_upto() again.

      Note that @stop_chars may contain '\0' if @stop_chars_len is
      specified.

      When the operation is finished, @callback will be called. You
      can then call g_data_input_stream_read_upto_finish() to get
      the result of the operation.
      Parameters:
      stop_chars - characters to terminate the read
      stop_chars_len - length of @stop_chars. May be -1 if @stop_chars is nul-terminated
      io_priority - the [I/O priority][io-priority] of the request
      cancellable - optional #GCancellable object, %NULL to ignore
      callback - callback to call when the request is satisfied
      user_data - the data to pass to callback function
    • readUptoAsync

      public void readUptoAsync(String stop_chars, long stop_chars_len, int io_priority, @Nullable Cancellable cancellable, DataInputStream.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      The asynchronous version of g_data_input_stream_read_upto().
      It is an error to have two outstanding calls to this function.

      In contrast to g_data_input_stream_read_until(), this function
      does not consume the stop character. You have to use
      g_data_input_stream_read_byte() to get it before calling
      g_data_input_stream_read_upto() again.

      Note that @stop_chars may contain '\0' if @stop_chars_len is
      specified.

      When the operation is finished, @callback will be called. You
      can then call g_data_input_stream_read_upto_finish() to get
      the result of the operation.
      Parameters:
      stop_chars - characters to terminate the read
      stop_chars_len - length of @stop_chars. May be -1 if @stop_chars is nul-terminated
      io_priority - the [I/O priority][io-priority] of the request
      cancellable - optional #GCancellable object, %NULL to ignore
      callback - callback to call when the request is satisfied
      user_data - the data to pass to callback function
    • readUptoFinish

      public Str readUptoFinish(@Nonnull AsyncResult result, @Nullable Int64 length) throws AllocationError
      Finish an asynchronous call started by
      g_data_input_stream_read_upto_async().

      Note that this function does not consume the stop character. You
      have to use g_data_input_stream_read_byte() to get it before calling
      g_data_input_stream_read_upto_async() again.

      The returned string will always be nul-terminated on success.
      Parameters:
      result - the #GAsyncResult that was provided to the callback
      length - a #gsize to get the length of the data read in
      Returns:
      a string with the data that was read before encountering any of the stop characters. Set @length to a #gsize to get the length of the string. This function will return %NULL on an error.
      Throws:
      AllocationError
    • setByteOrder

      public void setByteOrder(int order)
      This function sets the byte order for the given @stream. All subsequent
      reads from the @stream will be read in the given @order.
      Parameters:
      order - a #GDataStreamByteOrder to set.
    • setNewlineType

      public void setNewlineType(int type)
      Sets the newline type for the @stream.

      Note that using G_DATA_STREAM_NEWLINE_TYPE_ANY is slightly unsafe. If a read
      chunk ends in "CR" we must read an additional byte to know if this is "CR" or
      "CR LF", and this might block if there is no more data available.
      Parameters:
      type - the type of new line return as #GDataStreamNewlineType.
    • asSeekable

      public Seekable asSeekable()
      Implements interface Seekable. Call this to get access to interface functions.
      Overrides:
      asSeekable in class BufferedInputStream
      Returns:
      Seekable
    • 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()