RawIOBase (Jython API documentation)
Date: 2024-08-18

org.python.core.io

## Class RawIOBase

- java.lang.Object
- - org.python.core.io.IOBase
  - - org.python.core.io.RawIOBase

- Direct Known Subclasses:
    FileIO, SocketIOBase, StreamIO

      public abstract class RawIOBase
      extends IOBase

  Base class for raw binary I/O. RawIOBases wrap raw Java I/O objects (typically nio Channels). They provide a convenient means of handling raw Java I/O objects in the context of Python files. RawIOBases maintain state about their underlying I/O objects (such as their mode) and translate Java exceptions into PyExceptions. The read() method is implemented by calling readinto(); derived classes that want to support read() only need to implement readinto() as a primitive operation. In general, readinto() can be more efficient than read().
  Author:
    Philip Jenvey

- - ### Field Summary

    - ### Fields inherited from class org.python.core.io.IOBase

      `DEFAULT_BUFFER_SIZE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RawIOBase()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `RawIOBase` | `fileno()` Returns underlying file descriptor if one exists.
    `abstract java.nio.channels.Channel` | `getChannel()` Return the underlying Java nio Channel.
    `java.nio.ByteBuffer` | `read(int size)` Read and return up to size bytes, contained in a ByteBuffer.
    `java.nio.ByteBuffer` | `readall()` Read until EOF, using multiple read() calls.
    `int` | `readinto(java.nio.ByteBuffer buf)` Read up to buf.remaining() bytes into buf.
    `long` | `readinto(java.nio.ByteBuffer[] bufs)` Read bytes into each of the specified ByteBuffers.
    `int` | `write(java.nio.ByteBuffer buf)` Write the given ByteBuffer to the IO stream.
    `long` | `write(java.nio.ByteBuffer[] bufs)` Write the given ByteBuffers to the IO stream.

    - ### Methods inherited from class org.python.core.io.IOBase

      `asInputStream, asOutputStream, checkClosed, checkReadable, checkWritable, close, closed, flush, isatty, readable, seek, seek, tell, truncate, writable`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RawIOBase

          public RawIOBase()

  - ### Method Detail

    - #### read

          public java.nio.ByteBuffer read(int size)

      Read and return up to size bytes, contained in a ByteBuffer. ByteBuffers returned from read are already flip()'d. Returns an empty ByteBuffer on EOF
      Parameters:
        `size` - the number of bytes to read
      Returns:
        a ByteBuffer containing the bytes read

    - #### readall

          public java.nio.ByteBuffer readall()

      Read until EOF, using multiple read() calls.
      Returns:
        a ByteBuffer containing the bytes read

    - #### readinto

          public int readinto(java.nio.ByteBuffer buf)

      Read up to buf.remaining() bytes into buf. Returns number of bytes read (0 for EOF).
      Parameters:
        `buf` - a ByteBuffer to read bytes into
      Returns:
        the amount of data read as an int

    - #### readinto

          public long readinto(java.nio.ByteBuffer[] bufs)

      Read bytes into each of the specified ByteBuffers. Returns number of bytes read (0 for EOF).
      Parameters:
        `bufs` - an array of ByteBuffers to read bytes into
      Returns:
        the amount of data read as a long

    - #### write

          public int write(java.nio.ByteBuffer buf)

      Write the given ByteBuffer to the IO stream. Returns the number of bytes written, which may be less than buf.remaining().
      Parameters:
        `buf` - a ByteBuffer value
      Returns:
        the number of bytes written as an int

    - #### write

          public long write(java.nio.ByteBuffer[] bufs)

      Write the given ByteBuffers to the IO stream. Returns the number of bytes written, which may be less than the combined value of all the buf.remaining()'s.
      Parameters:
        `bufs` - an array of ByteBuffers
      Returns:
        the number of bytes written as a long

    - #### fileno

          public RawIOBase fileno()

      Description copied from class: `IOBase`
      Returns underlying file descriptor if one exists. Raises IOError if the IO object does not use a file descriptor.
      Overrides:
        `fileno` in class `IOBase`
      Returns:
        a file descriptor

    - #### getChannel

          public abstract java.nio.channels.Channel getChannel()

      Return the underlying Java nio Channel.
      Returns:
        the underlying Java nio Channel

Jython homepage