Class BufferedInputStream
- All Implemented Interfaces:
AutoCloseable,Seekable,Proxy,AutoCloseable
- Direct Known Subclasses:
DataInputStream
FilterInputStream and provides
for buffered reads.
By default, GBufferedInputStream's buffer size is set at 4 kilobytes.
To create a buffered input stream, use BufferedInputStream(),
or sized(org.gnome.gio.InputStream, long) to specify the buffer's size at
construction.
To get the size of a buffer within a buffered input stream, use
getBufferSize(). To change the size of a
buffered input stream's buffer, use setBufferSize(long).
Note that the buffer's size cannot be reduced below the size of the data within the buffer.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classInner class implementing a builder pattern to construct a GObject with properties.Nested 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 BufferedInputStream.BufferedInputStream(MemorySegment address) Create a BufferedInputStream proxy instance for the provided memory address.BufferedInputStream(InputStream baseStream) Creates a newInputStreamfrom the givenbaseStream,with a buffer set to the default size (4 kilobytes). -
Method Summary
Modifier and TypeMethodDescriptionprotected BufferedInputStreamasParent()Returns this instance as if it were its parent type.static BufferedInputStream.Builder<? extends BufferedInputStream.Builder> builder()ABufferedInputStream.Builderobject constructs aBufferedInputStreamwith the specified properties.longfill(long count, @Nullable Cancellable cancellable) Tries to readcountbytes from the stream into the buffer.voidfillAsync(long count, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Reads data intostream'sbuffer asynchronously, up tocountsize.longfillFinish(AsyncResult result) Finishes an asynchronous read.longGets the size of the available data within the stream.longGets the size of the input buffer.static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the BufferedInputStream classlongpeek(@org.jspecify.annotations.Nullable byte @Nullable [] buffer, long offset) Peeks in the buffer, copying data of sizecountintobuffer,offsetoffsetbytes.byte[]Returns the buffer with the currently available bytes.intreadInt(@Nullable Cancellable cancellable) Tries to read a single byte from the stream or the buffer.voidsetBufferSize(long size) Sets the size of the internal buffer of this BufferedInputStream tosize,or to the size of the contents of the buffer.static InputStreamsized(InputStream baseStream, long size) Methods 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
-
BufferedInputStream
Create a BufferedInputStream proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
BufferedInputStream
Creates a newInputStreamfrom the givenbaseStream,with a buffer set to the default size (4 kilobytes).- Parameters:
baseStream- aInputStream
-
BufferedInputStream
public BufferedInputStream()Creates a new BufferedInputStream.
-
-
Method Details
-
getType
Get the GType of the BufferedInputStream 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 classFilterInputStream
-
sized
- Parameters:
baseStream- aInputStreamsize- agsize- Returns:
- a
InputStream.
-
fill
Tries to readcountbytes from the stream into the buffer. Will block during this read.If
countis zero, returns zero and does nothing. A value ofcountlarger thanG_MAXSSIZEwill cause aGio.IOErrorEnum.INVALID_ARGUMENTerror.On success, the number of bytes read into the buffer is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file. Zero is returned on end of file (or if
countis zero), but never otherwise.If
countis -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer.If
cancellableis notNULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLEDwill be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.On error
-1is returned anderroris set accordingly.For the asynchronous, non-blocking, version of this function, see
fillAsync(long, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback).- Parameters:
count- the number of bytes that will be read from the streamcancellable- optionalCancellableobject,NULLto ignore- Returns:
- the number of bytes read into
stream'sbuffer, up tocount,or-1on error. - Throws:
GErrorException- seeGError
-
fillAsync
public void fillAsync(long count, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Reads data intostream'sbuffer asynchronously, up tocountsize.ioPrioritycan be used to prioritize reads. For the synchronous version of this function, seefill(long, org.gnome.gio.Cancellable).If
countis-1then the attempted read size is equal to the number of bytes that are required to fill the buffer.- Parameters:
count- the number of bytes that will be read from the streamioPriority- the I/O priority of the requestcancellable- optionalCancellableobjectcallback- aGio.AsyncReadyCallback
-
fillFinish
Finishes an asynchronous read.- Parameters:
result- aAsyncResult- Returns:
- a
gssizeof the read stream, or-1on an error. - Throws:
GErrorException- seeGError
-
getAvailable
public long getAvailable()Gets the size of the available data within the stream.- Returns:
- size of the available stream.
-
getBufferSize
public long getBufferSize()Gets the size of the input buffer.- Returns:
- the current buffer size.
-
peek
public long peek(@org.jspecify.annotations.Nullable byte @Nullable [] buffer, long offset) Peeks in the buffer, copying data of sizecountintobuffer,offsetoffsetbytes.- Parameters:
buffer- a pointer to an allocated chunk of memoryoffset- agsize- Returns:
- a
gsizeof the number of bytes peeked, or-1on error.
-
peekBuffer
public byte[] peekBuffer()Returns the buffer with the currently available bytes. The returned buffer must not be modified and will become invalid when reading from the stream or filling the buffer.- Returns:
- read-only buffer
-
readInt
Tries to read a single byte from the stream or the buffer. Will block during this read.On success, the byte read from the stream is returned. On end of stream
-1is returned but it's not an exceptional error anderroris not set.If
cancellableis notNULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLEDwill be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.On error
-1is returned anderroris set accordingly.- Parameters:
cancellable- optionalCancellableobject,NULLto ignore- Returns:
- the byte read from the
stream,or-1on end of stream or error. - Throws:
GErrorException- seeGError
-
setBufferSize
public void setBufferSize(long size) Sets the size of the internal buffer of this BufferedInputStream tosize,or to the size of the contents of the buffer. The buffer can never be resized smaller than its current contents.- Parameters:
size- agsize
-
builder
ABufferedInputStream.Builderobject constructs aBufferedInputStreamwith the specified properties. Use the variousset...()methods to set properties, and finish construction withBufferedInputStream.Builder.build().- Returns:
- the builder object
-