Class DataInputStream
- All Implemented Interfaces:
AutoCloseable,Seekable,Proxy,AutoCloseable
InputStream and includes functions
for reading structured data directly from a binary input stream.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDataInputStream.Builder<B extends DataInputStream.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class org.gnome.gio.BufferedInputStream
BufferedInputStream.BufferedInputStreamClassNested classes/interfaces inherited from class org.gnome.gio.FilterInputStream
FilterInputStream.FilterInputStream$Impl, FilterInputStream.FilterInputStreamClassNested classes/interfaces inherited from class org.gnome.gio.InputStream
InputStream.InputStream$Impl, InputStream.InputStreamClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.gio.Seekable
Seekable.Seekable$Impl, Seekable.SeekableIface -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new DataInputStream.DataInputStream(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 DataInputStreamasParent()Returns this instance as if it were its parent type.static DataInputStream.Builder<? extends DataInputStream.Builder> builder()ADataInputStream.Builderobject constructs aDataInputStreamwith the specified properties.Gets the byte order for the data input stream.static MemoryLayoutThe memory layout of the native struct.Gets the current newline type for thestream.static @Nullable TypegetType()Get the GType of the DataInputStream classbytereadByte(@Nullable Cancellable cancellable) Reads an unsigned 8-bit/1-byte value fromstream.shortreadInt16(@Nullable Cancellable cancellable) Reads a 16-bit/2-byte value fromstream.intreadInt32(@Nullable Cancellable cancellable) Reads a signed 32-bit/4-byte value fromstream.longreadInt64(@Nullable Cancellable cancellable) Reads a 64-bit/8-byte value fromstream.@org.jspecify.annotations.Nullable byte @Nullable []readLine(@Nullable Out<Long> length, @Nullable Cancellable cancellable) Reads a line from the data input stream.voidreadLineAsync(int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) The asynchronous version of g_data_input_stream_read_line().@org.jspecify.annotations.Nullable byte @Nullable []readLineFinish(AsyncResult result, @Nullable Out<Long> length) Finish an asynchronous call started by g_data_input_stream_read_line_async().@Nullable StringreadLineFinishUtf8(AsyncResult result, @Nullable Out<Long> length) Finish an asynchronous call started by g_data_input_stream_read_line_async().@Nullable StringreadLineUtf8(@Nullable Out<Long> length, @Nullable Cancellable cancellable) Reads a UTF-8 encoded line from the data input stream.shortreadUint16(@Nullable Cancellable cancellable) Reads an unsigned 16-bit/2-byte value fromstream.intreadUint32(@Nullable Cancellable cancellable) Reads an unsigned 32-bit/4-byte value fromstream.longreadUint64(@Nullable Cancellable cancellable) Reads an unsigned 64-bit/8-byte value fromstream.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.voidreadUntilAsync(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.voidreadUptoAsync(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().voidsetByteOrder(DataStreamByteOrder order) This function sets the byte order for the givenstream.All subsequent reads from the this DataInputStream will be read in the givenorder.voidSets the newline type for thestream.Methods inherited from class org.gnome.gio.BufferedInputStream
fill, fillAsync, fillFinish, getAvailable, getBufferSize, peek, peekBuffer, readInt, setBufferSize, sizedMethods inherited from class org.gnome.gio.FilterInputStream
getBaseStream, getCloseBaseStream, setCloseBaseStreamMethods 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, skipFinishMethods 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, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.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.
-
DataInputStream
public DataInputStream()Creates a new DataInputStream.
-
-
Method Details
-
getType
Get the GType of the DataInputStream class- Returns:
- the GType
-
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 Javasuperkeyword, 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:
asParentin classBufferedInputStream
-
getByteOrder
Gets the byte order for the data input stream.- Returns:
- the
stream'scurrentGDataStreamByteOrder.
-
getNewlineType
Gets the current newline type for thestream.- Returns:
GDataStreamNewlineTypefor the givenstream.
-
readByte
Reads an unsigned 8-bit/1-byte value fromstream.- Parameters:
cancellable- optionalGCancellableobject,nullto ignore.- Returns:
- an unsigned 8-bit/1-byte value read from the this DataInputStream or
0if an error occurred. - Throws:
GErrorException- seeGError
-
readInt16
Reads a 16-bit/2-byte value fromstream.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- optionalGCancellableobject,nullto ignore.- Returns:
- a signed 16-bit/2-byte value read from this DataInputStream or
0if an error occurred. - Throws:
GErrorException- seeGError
-
readInt32
Reads a signed 32-bit/4-byte value fromstream.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
cancellableis notnull, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLEDwill be returned.- Parameters:
cancellable- optionalGCancellableobject,nullto ignore.- Returns:
- a signed 32-bit/4-byte value read from the this DataInputStream or
0if an error occurred. - Throws:
GErrorException- seeGError
-
readInt64
Reads a 64-bit/8-byte value fromstream.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
cancellableis notnull, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLEDwill be returned.- Parameters:
cancellable- optionalGCancellableobject,nullto ignore.- Returns:
- a signed 64-bit/8-byte value read from this DataInputStream or
0if an error occurred. - Throws:
GErrorException- seeGError
-
readLine
public @org.jspecify.annotations.Nullable byte @Nullable [] readLine(@Nullable Out<Long> length, @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
cancellableis notnull, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLEDwill be returned.- Parameters:
length- agsizeto get the length of the data read in.cancellable- optionalGCancellableobject,nullto ignore.- Returns:
- a NUL terminated byte array with the line that was read in
(without the newlines). Set
lengthto agsizeto get the length of the read line. On an error, it will returnnullanderrorwill be set. If there's no content to read, it will still returnnull, buterrorwon't be set. - Throws:
GErrorException- seeGError
-
readLineAsync
public void readLineAsync(int ioPriority, @Nullable Cancellable cancellable, @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,
callbackwill 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- optionalGCancellableobject,nullto ignore.callback- callback to call when the request is satisfied.- Since:
- 2.20
-
readLineFinish
public @org.jspecify.annotations.Nullable byte @Nullable [] readLineFinish(AsyncResult result, @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- theGAsyncResultthat was provided to the callback.length- agsizeto 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
lengthto agsizeto get the length of the read line. On an error, it will returnnullanderrorwill be set. If there's no content to read, it will still returnnull, buterrorwon't be set. - Throws:
GErrorException- seeGError- Since:
- 2.20
-
readLineFinishUtf8
public @Nullable String readLineFinishUtf8(AsyncResult result, @Nullable Out<Long> length) throws GErrorException Finish an asynchronous call started by g_data_input_stream_read_line_async().- Parameters:
result- theGAsyncResultthat was provided to the callback.length- agsizeto get the length of the data read in.- Returns:
- a string with the line that
was read in (without the newlines). Set
lengthto agsizeto get the length of the read line. On an error, it will returnnullanderrorwill 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, buterrorwon't be set. - Throws:
GErrorException- seeGError- Since:
- 2.30
-
readLineUtf8
public @Nullable String readLineUtf8(@Nullable Out<Long> length, @Nullable Cancellable cancellable) throws GErrorException Reads a UTF-8 encoded line from the data input stream.If
cancellableis notnull, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLEDwill be returned.- Parameters:
length- agsizeto get the length of the data read in.cancellable- optionalGCancellableobject,nullto ignore.- Returns:
- a NUL terminated UTF-8 string
with the line that was read in (without the newlines). Set
lengthto agsizeto get the length of the read line. On an error, it will returnnullanderrorwill 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, buterrorwon't be set. - Throws:
GErrorException- seeGError- Since:
- 2.30
-
readUint16
Reads an unsigned 16-bit/2-byte value fromstream.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- optionalGCancellableobject,nullto ignore.- Returns:
- an unsigned 16-bit/2-byte value read from the this DataInputStream or
0if an error occurred. - Throws:
GErrorException- seeGError
-
readUint32
Reads an unsigned 32-bit/4-byte value fromstream.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
cancellableis notnull, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLEDwill be returned.- Parameters:
cancellable- optionalGCancellableobject,nullto ignore.- Returns:
- an unsigned 32-bit/4-byte value read from the this DataInputStream or
0if an error occurred. - Throws:
GErrorException- seeGError
-
readUint64
Reads an unsigned 64-bit/8-byte value fromstream.In order to get the correct byte order for this read operation, see g_data_input_stream_get_byte_order().
If
cancellableis notnull, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLEDwill be returned.- Parameters:
cancellable- optionalGCancellableobject,nullto ignore.- Returns:
- an unsigned 64-bit/8-byte read from this DataInputStream or
0if an error occurred. - Throws:
GErrorException- seeGError
-
readUntil
@Deprecated public String readUntil(String stopChars, @Nullable Out<Long> length, @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- agsizeto get the length of the data read in.cancellable- optionalGCancellableobject,nullto ignore.- Returns:
- a string with the data that was read
before encountering any of the stop characters. Set
lengthto agsizeto get the length of the string. This function will returnnullon an error. - Throws:
GErrorException- seeGError
-
readUntilAsync
@Deprecated public 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.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,
callbackwill 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- optionalGCancellableobject,nullto ignore.callback- callback to call when the request is satisfied.- Since:
- 2.20
-
readUntilFinish
@Deprecated public String readUntilFinish(AsyncResult result, @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- theGAsyncResultthat was provided to the callback.length- agsizeto 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
lengthto agsizeto get the length of the string. This function will returnnullon an error. - Throws:
GErrorException- seeGError- Since:
- 2.20
-
readUpto
public String readUpto(String stopChars, long stopCharsLen, @Nullable Out<Long> length, @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
stopCharsmay contain '\\0' ifstopCharsLenis specified.The returned string will always be nul-terminated on success.
- Parameters:
stopChars- characters to terminate the readstopCharsLen- length ofstopChars.May be -1 ifstopCharsis nul-terminatedlength- agsizeto get the length of the data read incancellable- optionalGCancellableobject,nullto ignore- Returns:
- a string with the data that was read
before encountering any of the stop characters. Set
lengthto agsizeto get the length of the string. This function will returnnullon an error - Throws:
GErrorException- seeGError- Since:
- 2.26
-
readUptoAsync
public void readUptoAsync(String stopChars, long stopCharsLen, int ioPriority, @Nullable Cancellable cancellable, @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
stopCharsmay contain '\\0' ifstopCharsLenis specified.When the operation is finished,
callbackwill 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 ifstopCharsis nul-terminatedioPriority- the I/O priority of the requestcancellable- optionalGCancellableobject,nullto ignorecallback- callback to call when the request is satisfied- Since:
- 2.26
-
readUptoFinish
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- theGAsyncResultthat was provided to the callbacklength- agsizeto 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
lengthto agsizeto get the length of the string. This function will returnnullon an error. - Throws:
GErrorException- seeGError- Since:
- 2.24
-
setByteOrder
This function sets the byte order for the givenstream.All subsequent reads from the this DataInputStream will be read in the givenorder.- Parameters:
order- aGDataStreamByteOrderto set.
-
setNewlineType
Sets the newline type for thestream.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.Builderobject constructs aDataInputStreamwith the specified properties. Use the variousset...()methods to set properties, and finish construction withDataInputStream.Builder.build().- Returns:
- the builder object
-