Class BufferedInputStream
- All Implemented Interfaces:
AutoCloseable, Seekable, Proxy, AutoCloseable
- Direct Known Subclasses:
DataInputStream
Buffered input stream implements 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(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 FilterInputStream
FilterInputStream.FilterInputStream$Impl, FilterInputStream.FilterInputStreamClassNested classes/interfaces inherited from class InputStream
InputStream.InputStream$Impl, InputStream.InputStreamClassNested classes/interfaces inherited from class GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface Seekable
Seekable.Seekable$Impl, Seekable.SeekableIface -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new BufferedInputStream.BufferedInputStream(MemorySegment address) Create a BufferedInputStream 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()Return 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 class.longpeek(@Nullable byte @Nullable [] buffer, long offset) Peeks in the buffered input, copyingcountbytes of data fromoffsetbytes in the buffered input intobuffer.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 FilterInputStream
getBaseStream, getCloseBaseStream, setCloseBaseStreamMethods inherited from class 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 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 TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class ProxyInstance
equals, handle, hashCodeMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AutoCloseable
close
-
Constructor Details
-
BufferedInputStream
Create a BufferedInputStream 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()Create 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
Return this instance as if it were its parent type. Comparable to the Javasuperkeyword, but ensures the parent typeclass is also used in native code.- Overrides:
asParentin classFilterInputStream- Returns:
- the instance as if it were its parent type
-
sized
- Parameters:
baseStream- aInputStreamsize- agsize- Returns:
- a
InputStream.
-
fill
Tries to read
countbytes 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, Cancellable, 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 into
stream'sbuffer asynchronously, up tocountsize.ioPrioritycan be used to prioritize reads. For the synchronous version of this function, seefill(long, 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(@Nullable byte @Nullable [] buffer, long offset) Peeks in the buffered input, copyingcountbytes of data fromoffsetbytes in the buffered input intobuffer.- Parameters:
buffer- a pointer to an allocated chunk of memory, which must be at leastcountbytes longoffset- offset into the buffered input to peek from, or zero to peek from the next byte in the buffered input onwards- Returns:
- the number of bytes copied, which may be zero
-
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
-