Class BufferedInputStream
- All Implemented Interfaces:
Proxy
,AutoCloseable
,AutoCloseable
,Seekable
- 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(org.gnome.gio.InputStream)
,
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
Modifier and TypeClassDescriptionstatic class
static class
Inner class implementing a builder pattern to construct a GObject with properties.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
ConstructorDescriptionBufferedInputStream
(MemorySegment address) Create a BufferedInputStream proxy instance for the provided memory address.BufferedInputStream
(InputStream baseStream) Creates a newInputStream
from the givenbaseStream
, with a buffer set to the default size (4 kilobytes). -
Method Summary
Modifier and TypeMethodDescriptionprotected BufferedInputStream
asParent()
Returns this instance as if it were its parent type.static BufferedInputStream.Builder
<? extends BufferedInputStream.Builder> builder()
ABufferedInputStream.Builder
object constructs aBufferedInputStream
with the specified properties.long
fill
(long count, @Nullable Cancellable cancellable) Tries to readcount
bytes from the stream into the buffer.void
fillAsync
(long count, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Reads data into this BufferedInputStream's buffer asynchronously, up tocount
size.long
fillFinish
(AsyncResult result) Finishes an asynchronous read.long
Gets the size of the available data within the stream.long
Gets the size of the input buffer.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the BufferedInputStream classlong
peek
(byte[] buffer, long offset) Peeks in the buffer, copying data of sizecount
intobuffer
, offsetoffset
bytes.byte[]
Returns the buffer with the currently available bytes.int
readInt
(@Nullable Cancellable cancellable) Tries to read a single byte from the stream or the buffer.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.static BufferedInputStream
sized
(InputStream baseStream, long size) 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
-
BufferedInputStream
Create a BufferedInputStream proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
BufferedInputStream
Creates a newInputStream
from the givenbaseStream
, with a buffer set to the default size (4 kilobytes).- Parameters:
baseStream
- aInputStream
-
-
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 classFilterInputStream
-
sized
- Parameters:
baseStream
- aInputStream
size
- agsize
- Returns:
- a
InputStream
.
-
fill
Tries to readcount
bytes from the stream into the buffer. Will block during this read.If
count
is zero, returns zero and does nothing. A value ofcount
larger thanG_MAXSSIZE
will cause aGio.IOErrorEnum.INVALID_ARGUMENT
error.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
count
is zero), but never otherwise.If
count
is -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer.If
cancellable
is notNULL
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.On error
-1
is returned anderror
is 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
- optionalCancellable
object,NULL
to ignore- Returns:
- the number of bytes read into this BufferedInputStream's buffer, up to
count
, or-1
on error. - Throws:
GErrorException
- seeGError
-
fillAsync
public void fillAsync(long count, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Reads data into this BufferedInputStream's buffer asynchronously, up tocount
size.ioPriority
can be used to prioritize reads. For the synchronous version of this function, seefill(long, org.gnome.gio.Cancellable)
.If
count
is-1
then 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
- optionalCancellable
objectcallback
- aGio.AsyncReadyCallback
-
fillFinish
Finishes an asynchronous read.- Parameters:
result
- aAsyncResult
- Returns:
- a
gssize
of the read stream, or-1
on 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(byte[] buffer, long offset) Peeks in the buffer, copying data of sizecount
intobuffer
, offsetoffset
bytes.- Parameters:
buffer
- a pointer to an allocated chunk of memoryoffset
- agsize
- Returns:
- a
gsize
of the number of bytes peeked, or-1
on 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
-1
is returned but it's not an exceptional error anderror
is not set.If
cancellable
is notNULL
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.On error
-1
is returned anderror
is set accordingly.- Parameters:
cancellable
- optionalCancellable
object,NULL
to ignore- Returns:
- the byte read from the this BufferedInputStream, or
-1
on 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.Builder
object constructs aBufferedInputStream
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withBufferedInputStream.Builder.build()
.
-