Package ch.bailu.gtk.gio
Class DataInputStream
- All Implemented Interfaces:
PointerInterface
Data input stream implements #GInputStream and includes functions for
reading structured data directly from a binary input stream.
reading structured data directly from a binary input stream.
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
ConstructorDescriptionDataInputStream
(InputStream base_stream) Creates a new data input stream for the @base_stream.DataInputStream
(PointerContainer pointer) -
Method Summary
Modifier and TypeMethodDescriptionImplements interfaceSeekable
.int
Gets the byte order for the data input stream.static ClassHandler
static int
int
Gets the current newline type for the @stream.static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
int
readInt16
(Cancellable cancellable) Reads a 16-bit/2-byte value from @stream.int
readInt32
(Cancellable cancellable) Reads a signed 32-bit/4-byte value from @stream.long
readInt64
(Cancellable cancellable) Reads a 64-bit/8-byte value from @stream.readLine
(Int64 length, Cancellable cancellable) Reads a line from the data input stream.void
readLineAsync
(int io_priority, Cancellable cancellable, DataInputStream.OnAsyncReadyCallback callback, Pointer user_data) The asynchronous version of g_data_input_stream_read_line().readLineFinish
(AsyncResult result, Int64 length) Finish an asynchronous call started by
g_data_input_stream_read_line_async().readLineFinishUtf8
(AsyncResult result, Int64 length) Finish an asynchronous call started by
g_data_input_stream_read_line_async().readLineUtf8
(Int64 length, Cancellable cancellable) Reads a UTF-8 encoded line from the data input stream.int
readUint16
(Cancellable cancellable) Reads an unsigned 16-bit/2-byte value from @stream.int
readUint32
(Cancellable cancellable) Reads an unsigned 32-bit/4-byte value from @stream.long
readUint64
(Cancellable cancellable) Reads an unsigned 64-bit/8-byte value from @stream.readUpto
(Str stop_chars, long stop_chars_len, Int64 length, Cancellable cancellable) Reads a string from the data input stream, up to the first
occurrence of any of the stop characters.readUpto
(String stop_chars, long stop_chars_len, Int64 length, Cancellable cancellable) Reads a string from the data input stream, up to the first
occurrence of any of the stop characters.void
readUptoAsync
(Str stop_chars, long stop_chars_len, int io_priority, Cancellable cancellable, DataInputStream.OnAsyncReadyCallback callback, Pointer user_data) The asynchronous version of g_data_input_stream_read_upto().void
readUptoAsync
(String stop_chars, long stop_chars_len, int io_priority, Cancellable cancellable, DataInputStream.OnAsyncReadyCallback callback, Pointer user_data) The asynchronous version of g_data_input_stream_read_upto().readUptoFinish
(AsyncResult result, Int64 length) Finish an asynchronous call started by
g_data_input_stream_read_upto_async().void
setByteOrder
(int order) This function sets the byte order for the given @stream.void
setNewlineType
(int type) Sets the newline type for the @stream.Methods inherited from class ch.bailu.gtk.gio.BufferedInputStream
fill, fillAsync, fillFinish, getAvailable, getBufferSize, newSizedBufferedInputStream, peek, peekBuffer, readByte, setBufferSize
Methods inherited from class ch.bailu.gtk.gio.FilterInputStream
getBaseStream, getCloseBaseStream, setCloseBaseStream
Methods inherited from class ch.bailu.gtk.gio.InputStream
clearPending, close, closeAsync, closeFinish, hasPending, isClosed, read, readAll, readAllAsync, readAllFinish, readAsync, readBytes, readBytesAsync, readBytesFinish, readFinish, setPending, skip, skipAsync, skipFinish
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Constructor Details
-
DataInputStream
-
DataInputStream
Creates a new data input stream for the @base_stream.- Parameters:
base_stream
- a #GInputStream.
-
-
Method Details
-
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
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
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
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 requestcancellable
- 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
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
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
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 readstop_chars_len
- length of @stop_chars. May be -1 if @stop_chars is nul-terminatedlength
- a #gsize to get the length of the data read incancellable
- 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 readstop_chars_len
- length of @stop_chars. May be -1 if @stop_chars is nul-terminatedlength
- a #gsize to get the length of the data read incancellable
- 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 readstop_chars_len
- length of @stop_chars. May be -1 if @stop_chars is nul-terminatedio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- callback to call when the request is satisfieduser_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 readstop_chars_len
- length of @stop_chars. May be -1 if @stop_chars is nul-terminatedio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- callback to call when the request is satisfieduser_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 callbacklength
- 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
Implements interfaceSeekable
. Call this to get access to interface functions.- Overrides:
asSeekable
in classBufferedInputStream
- Returns:
Seekable
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-