Class DataInputStream
- All Implemented Interfaces:
Proxy
,AutoCloseable
,AutoCloseable
,Seekable
InputStream
and includes functions
for reading structured data directly from a binary input stream.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
DataInputStream.Builder<B extends DataInputStream.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.gio.BufferedInputStream
BufferedInputStream.BufferedInputStreamClass
Nested classes/interfaces inherited from class org.gnome.gio.FilterInputStream
FilterInputStream.FilterInputStreamClass, FilterInputStream.FilterInputStreamImpl
Nested classes/interfaces inherited from class org.gnome.gio.InputStream
InputStream.InputStreamClass, InputStream.InputStreamImpl
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gio.Seekable
Seekable.SeekableIface, Seekable.SeekableImpl
-
Constructor Summary
ConstructorDescriptionDataInputStream
(MemorySegment address) Create a DataInputStream proxy instance for the provided memory address.DataInputStream
(InputStream baseStream) Creates a new data input stream for thebaseStream
. -
Method Summary
Modifier and TypeMethodDescriptionprotected DataInputStream
asParent()
Returns this instance as if it were its parent type.static DataInputStream.Builder
<? extends DataInputStream.Builder> builder()
ADataInputStream.Builder
object constructs aDataInputStream
with the specified properties.Gets the byte order for the data input stream.static MemoryLayout
The memory layout of the native struct.Gets the current newline type for the this DataInputStream.static Type
getType()
Get the GType of the DataInputStream classbyte
readByte
(@Nullable Cancellable cancellable) Reads an unsigned 8-bit/1-byte value from this DataInputStream.short
readInt16
(@Nullable Cancellable cancellable) Reads a 16-bit/2-byte value from this DataInputStream.int
readInt32
(@Nullable Cancellable cancellable) Reads a signed 32-bit/4-byte value from this DataInputStream.long
readInt64
(@Nullable Cancellable cancellable) Reads a 64-bit/8-byte value from this DataInputStream.byte[]
readLine
(@Nullable Out<Long> length, @Nullable Cancellable cancellable) Reads a line from the data input stream.void
readLineAsync
(int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) The asynchronous version of g_data_input_stream_read_line().byte[]
readLineFinish
(AsyncResult result, @Nullable Out<Long> length) Finish an asynchronous call started by g_data_input_stream_read_line_async().readLineFinishUtf8
(AsyncResult result, @Nullable Out<Long> length) Finish an asynchronous call started by g_data_input_stream_read_line_async().readLineUtf8
(@Nullable Out<Long> length, @Nullable Cancellable cancellable) Reads a UTF-8 encoded line from the data input stream.short
readUint16
(@Nullable Cancellable cancellable) Reads an unsigned 16-bit/2-byte value from this DataInputStream.int
readUint32
(@Nullable Cancellable cancellable) Reads an unsigned 32-bit/4-byte value from this DataInputStream.long
readUint64
(@Nullable Cancellable cancellable) Reads an unsigned 64-bit/8-byte value from this DataInputStream.readUntil
(String stopChars, @Nullable Out<Long> length, @Nullable Cancellable cancellable) Deprecated.Use g_data_input_stream_read_upto() instead, which has more consistent behaviour regarding the stop character.void
readUntilAsync
(String stopChars, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Deprecated.Use g_data_input_stream_read_upto_async() instead, which has more consistent behaviour regarding the stop character.readUntilFinish
(AsyncResult result, @Nullable Out<Long> length) Deprecated.Use g_data_input_stream_read_upto_finish() instead, which has more consistent behaviour regarding the stop character.readUpto
(String stopChars, long stopCharsLen, @Nullable Out<Long> length, @Nullable Cancellable cancellable) Reads a string from the data input stream, up to the first occurrence of any of the stop characters.void
readUptoAsync
(String stopChars, long stopCharsLen, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) The asynchronous version of g_data_input_stream_read_upto().readUptoFinish
(AsyncResult result, @Nullable Out<Long> length) Finish an asynchronous call started by g_data_input_stream_read_upto_async().void
setByteOrder
(DataStreamByteOrder order) This function sets the byte order for the given this DataInputStream.void
Sets the newline type for the this DataInputStream.Methods inherited from class org.gnome.gio.BufferedInputStream
fill, fillAsync, fillFinish, getAvailable, getBufferSize, peek, peekBuffer, readInt, setBufferSize, sized
Methods inherited from class org.gnome.gio.FilterInputStream
getBaseStream, getCloseBaseStream, setCloseBaseStream
Methods inherited from class org.gnome.gio.InputStream
clearPending, close, closeAsync, closeFinish, closeFn, hasPending, isClosed, read, readAll, readAllAsync, readAllFinish, readAsync, readBytes, readBytesAsync, readBytesFinish, readFinish, readFn, setPending, skip, skipAsync, skipFinish
Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.github.jwharm.javagi.gio.AutoCloseable
close
-
Constructor Details
-
DataInputStream
Create a DataInputStream proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
DataInputStream
Creates a new data input stream for thebaseStream
.- Parameters:
baseStream
- aGInputStream
.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type.- Overrides:
asParent
in classBufferedInputStream
-
getByteOrder
Gets the byte order for the data input stream.- Returns:
- the this DataInputStream's current
GDataStreamByteOrder
.
-
getNewlineType
Gets the current newline type for the this DataInputStream.- Returns:
GDataStreamNewlineType
for the given this DataInputStream.
-
readByte
Reads an unsigned 8-bit/1-byte value from this DataInputStream.- Parameters:
cancellable
- optionalGCancellable
object,null
to ignore.- Returns:
- an unsigned 8-bit/1-byte value read from the this DataInputStream or
0
if an error occurred. - Throws:
GErrorException
- seeGError
-
readInt16
Reads a 16-bit/2-byte value from this DataInputStream.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
- optionalGCancellable
object,null
to ignore.- Returns:
- a signed 16-bit/2-byte value read from this DataInputStream or
0
if an error occurred. - Throws:
GErrorException
- seeGError
-
readInt32
Reads a signed 32-bit/4-byte value from this DataInputStream.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 notnull
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLED
will be returned.- Parameters:
cancellable
- optionalGCancellable
object,null
to ignore.- Returns:
- a signed 32-bit/4-byte value read from the this DataInputStream or
0
if an error occurred. - Throws:
GErrorException
- seeGError
-
readInt64
Reads a 64-bit/8-byte value from this DataInputStream.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 notnull
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLED
will be returned.- Parameters:
cancellable
- optionalGCancellable
object,null
to ignore.- Returns:
- a signed 64-bit/8-byte value read from this DataInputStream or
0
if an error occurred. - Throws:
GErrorException
- seeGError
-
readLine
public byte[] readLine(@Nullable @Nullable Out<Long> length, @Nullable @Nullable Cancellable cancellable) throws GErrorException 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 notnull
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLED
will be returned.- Parameters:
length
- agsize
to get the length of the data read in.cancellable
- optionalGCancellable
object,null
to ignore.- Returns:
- a NUL terminated byte array with the line that was read in
(without the newlines). Set
length
to agsize
to get the length of the read line. On an error, it will returnnull
anderror
will be set. If there's no content to read, it will still returnnull
, buterror
won't be set. - Throws:
GErrorException
- seeGError
-
readLineAsync
public void readLineAsync(int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) 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:
ioPriority
- the I/O priority of the requestcancellable
- optionalGCancellable
object,null
to ignore.callback
- callback to call when the request is satisfied.
-
readLineFinish
public byte[] readLineFinish(AsyncResult result, @Nullable @Nullable Out<Long> length) throws GErrorException 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
- theGAsyncResult
that was provided to the callback.length
- agsize
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 agsize
to get the length of the read line. On an error, it will returnnull
anderror
will be set. If there's no content to read, it will still returnnull
, buterror
won't be set. - Throws:
GErrorException
- seeGError
-
readLineFinishUtf8
public String readLineFinishUtf8(AsyncResult result, @Nullable @Nullable Out<Long> length) throws GErrorException Finish an asynchronous call started by g_data_input_stream_read_line_async().- Parameters:
result
- theGAsyncResult
that was provided to the callback.length
- agsize
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 agsize
to get the length of the read line. On an error, it will returnnull
anderror
will be set. For UTF-8 conversion errors, the set error domain isG_CONVERT_ERROR
. If there's no content to read, it will still returnnull
, buterror
won't be set. - Throws:
GErrorException
- seeGError
-
readLineUtf8
public String readLineUtf8(@Nullable @Nullable Out<Long> length, @Nullable @Nullable Cancellable cancellable) throws GErrorException Reads a UTF-8 encoded line from the data input stream.If
cancellable
is notnull
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLED
will be returned.- Parameters:
length
- agsize
to get the length of the data read in.cancellable
- optionalGCancellable
object,null
to ignore.- Returns:
- a NUL terminated UTF-8 string
with the line that was read in (without the newlines). Set
length
to agsize
to get the length of the read line. On an error, it will returnnull
anderror
will be set. For UTF-8 conversion errors, the set error domain isG_CONVERT_ERROR
. If there's no content to read, it will still returnnull
, buterror
won't be set. - Throws:
GErrorException
- seeGError
-
readUint16
Reads an unsigned 16-bit/2-byte value from this DataInputStream.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
- optionalGCancellable
object,null
to ignore.- Returns:
- an unsigned 16-bit/2-byte value read from the this DataInputStream or
0
if an error occurred. - Throws:
GErrorException
- seeGError
-
readUint32
Reads an unsigned 32-bit/4-byte value from this DataInputStream.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 notnull
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLED
will be returned.- Parameters:
cancellable
- optionalGCancellable
object,null
to ignore.- Returns:
- an unsigned 32-bit/4-byte value read from the this DataInputStream or
0
if an error occurred. - Throws:
GErrorException
- seeGError
-
readUint64
Reads an unsigned 64-bit/8-byte value from this DataInputStream.In order to get the correct byte order for this read operation, see g_data_input_stream_get_byte_order().
If
cancellable
is notnull
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLED
will be returned.- Parameters:
cancellable
- optionalGCancellable
object,null
to ignore.- Returns:
- an unsigned 64-bit/8-byte read from this DataInputStream or
0
if an error occurred. - Throws:
GErrorException
- seeGError
-
readUntil
@Deprecated public String readUntil(String stopChars, @Nullable @Nullable Out<Long> length, @Nullable @Nullable Cancellable cancellable) throws GErrorException Deprecated.Use g_data_input_stream_read_upto() instead, which has more consistent behaviour regarding the stop character.Reads a string from the data input stream, up to the first occurrence of any of the stop characters.Note that, in contrast to g_data_input_stream_read_until_async(), this function consumes the stop character that it finds.
Don't use this function in new code. Its functionality is inconsistent with g_data_input_stream_read_until_async(). Both functions will be marked as deprecated in a future release. Use g_data_input_stream_read_upto() instead, but note that that function does not consume the stop character.
- Parameters:
stopChars
- characters to terminate the read.length
- agsize
to get the length of the data read in.cancellable
- optionalGCancellable
object,null
to ignore.- Returns:
- a string with the data that was read
before encountering any of the stop characters. Set
length
to agsize
to get the length of the string. This function will returnnull
on an error. - Throws:
GErrorException
- seeGError
-
readUntilAsync
@Deprecated public void readUntilAsync(String stopChars, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Deprecated.Use g_data_input_stream_read_upto_async() instead, which has more consistent behaviour regarding the stop character.The asynchronous version of g_data_input_stream_read_until(). It is an error to have two outstanding calls to this function.Note that, in contrast to g_data_input_stream_read_until(), this function does not consume the stop character that it finds. You must read it for yourself.
When the operation is finished,
callback
will be called. You can then call g_data_input_stream_read_until_finish() to get the result of the operation.Don't use this function in new code. Its functionality is inconsistent with g_data_input_stream_read_until(). Both functions will be marked as deprecated in a future release. Use g_data_input_stream_read_upto_async() instead.
- Parameters:
stopChars
- characters to terminate the read.ioPriority
- the I/O priority of the requestcancellable
- optionalGCancellable
object,null
to ignore.callback
- callback to call when the request is satisfied.
-
readUntilFinish
@Deprecated public String readUntilFinish(AsyncResult result, @Nullable @Nullable Out<Long> length) throws GErrorException Deprecated.Use g_data_input_stream_read_upto_finish() instead, which has more consistent behaviour regarding the stop character.Finish an asynchronous call started by g_data_input_stream_read_until_async().- Parameters:
result
- theGAsyncResult
that was provided to the callback.length
- agsize
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 agsize
to get the length of the string. This function will returnnull
on an error. - Throws:
GErrorException
- seeGError
-
readUpto
public String readUpto(String stopChars, long stopCharsLen, @Nullable @Nullable Out<Long> length, @Nullable @Nullable Cancellable cancellable) throws GErrorException 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
stopChars
may contain '\\0' ifstopCharsLen
is specified.The returned string will always be nul-terminated on success.
- Parameters:
stopChars
- characters to terminate the readstopCharsLen
- length ofstopChars
. May be -1 ifstopChars
is nul-terminatedlength
- agsize
to get the length of the data read incancellable
- optionalGCancellable
object,null
to ignore- Returns:
- a string with the data that was read
before encountering any of the stop characters. Set
length
to agsize
to get the length of the string. This function will returnnull
on an error - Throws:
GErrorException
- seeGError
-
readUptoAsync
public void readUptoAsync(String stopChars, long stopCharsLen, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) 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
stopChars
may contain '\\0' ifstopCharsLen
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:
stopChars
- characters to terminate the readstopCharsLen
- length ofstopChars
. May be -1 ifstopChars
is nul-terminatedioPriority
- the I/O priority of the requestcancellable
- optionalGCancellable
object,null
to ignorecallback
- callback to call when the request is satisfied
-
readUptoFinish
public String readUptoFinish(AsyncResult result, @Nullable @Nullable Out<Long> length) throws GErrorException 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
- theGAsyncResult
that was provided to the callbacklength
- agsize
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 agsize
to get the length of the string. This function will returnnull
on an error. - Throws:
GErrorException
- seeGError
-
setByteOrder
This function sets the byte order for the given this DataInputStream. All subsequent reads from the this DataInputStream will be read in the givenorder
.- Parameters:
order
- aGDataStreamByteOrder
to set.
-
setNewlineType
Sets the newline type for the this DataInputStream.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 asGDataStreamNewlineType
.
-
builder
ADataInputStream.Builder
object constructs aDataInputStream
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withDataInputStream.Builder.build()
.
-