Class BufferedInputStream

All Implemented Interfaces:
AutoCloseable, Seekable, Proxy, AutoCloseable
Direct Known Subclasses:
DataInputStream

@Generated("org.javagi.JavaGI") public class BufferedInputStream extends FilterInputStream implements Seekable

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.

  • Constructor Details

    • BufferedInputStream

      public BufferedInputStream(MemorySegment address)
      Create a BufferedInputStream instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • BufferedInputStream

      public BufferedInputStream(InputStream baseStream)
      Creates a new InputStream from the given baseStream, with a buffer set to the default size (4 kilobytes).
      Parameters:
      baseStream - a InputStream
    • BufferedInputStream

      public BufferedInputStream()
      Create a new BufferedInputStream.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the BufferedInputStream class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected BufferedInputStream asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class FilterInputStream
      Returns:
      the instance as if it were its parent type
    • sized

      public static InputStream sized(InputStream baseStream, long size)
      Creates a new BufferedInputStream from the given baseStream, with a buffer set to size.
      Parameters:
      baseStream - a InputStream
      size - a gsize
      Returns:
      a InputStream.
    • fill

      public long fill(long count, @Nullable Cancellable cancellable) throws GErrorException

      Tries to read count bytes from the stream into the buffer. Will block during this read.

      If count is zero, returns zero and does nothing. A value of count larger than G_MAXSSIZE will cause a Gio.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 not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.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 and error is 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 stream
      cancellable - optional Cancellable object, NULL to ignore
      Returns:
      the number of bytes read into stream's buffer, up to count, or -1 on error.
      Throws:
      GErrorException - see GError
    • fillAsync

      public void fillAsync(long count, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Reads data into stream's buffer asynchronously, up to count size. ioPriority can be used to prioritize reads. For the synchronous version of this function, see fill(long, 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 stream
      ioPriority - the I/O priority of the request
      cancellable - optional Cancellable object
      callback - a Gio.AsyncReadyCallback
    • fillFinish

      public long fillFinish(AsyncResult result) throws GErrorException
      Finishes an asynchronous read.
      Parameters:
      result - a AsyncResult
      Returns:
      a gssize of the read stream, or -1 on an error.
      Throws:
      GErrorException - see GError
    • 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, copying count bytes of data from offset bytes in the buffered input into buffer.
      Parameters:
      buffer - a pointer to an allocated chunk of memory, which must be at least count bytes long
      offset - 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

      public int readInt(@Nullable Cancellable cancellable) throws GErrorException

      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 and error is not set.

      If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.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 and error is set accordingly.

      Parameters:
      cancellable - optional Cancellable object, NULL to ignore
      Returns:
      the byte read from the stream, or -1 on end of stream or error.
      Throws:
      GErrorException - see GError
    • setBufferSize

      public void setBufferSize(long size)
      Sets the size of the internal buffer of this BufferedInputStream to size, or to the size of the contents of the buffer. The buffer can never be resized smaller than its current contents.
      Parameters:
      size - a gsize
    • builder

      public static BufferedInputStream.Builder<? extends BufferedInputStream.Builder> builder()
      A BufferedInputStream.Builder object constructs a BufferedInputStream with the specified properties. Use the various set...() methods to set properties, and finish construction with BufferedInputStream.Builder.build().
      Returns:
      the builder object