Class StreamIO


public class StreamIO extends RawIOBase
Raw I/O implementation for simple streams. Supports Input/Outputstreams and Readable/WritableByteChannels.
Author:
Philip Jenvey
  • Constructor Details

    • StreamIO

      public StreamIO(ReadableByteChannel readChannel, boolean closefd)
      Construct a StreamIO for the given read channel.
      Parameters:
      readChannel - a ReadableByteChannel
      closefd - boolean whether the underlying file is closed on close() (defaults to True)
    • StreamIO

      public StreamIO(ReadableByteChannel readChannel)
      Construct a StreamIO for the given read channel.
      Parameters:
      readChannel - a ReadableByteChannel
    • StreamIO

      public StreamIO(WritableByteChannel writeChannel, boolean closefd)
      Construct a StreamIO for the given write channel.
      Parameters:
      writeChannel - a WritableByteChannel
      closefd - boolean whether the underlying file is closed on close() (defaults to True)
    • StreamIO

      public StreamIO(WritableByteChannel writeChannel)
      Construct a StreamIO for the given write channel.
      Parameters:
      writeChannel - a WritableByteChannel
    • StreamIO

      public StreamIO(InputStream inputStream, boolean closefd)
      Construct a StreamIO for the given read/write streams.
      Parameters:
      inputStream - an InputStream
      closefd - boolean whether the underlying file is closed on close() (defaults to True)
    • StreamIO

      public StreamIO(OutputStream outputStream, boolean closefd)
      Construct a StreamIO for the given read/write streams.
      Parameters:
      outputStream - an OutputStream
      closefd - boolean whether the underlying file is closed on close() (defaults to True)
  • Method Details

    • readinto

      public int readinto(ByteBuffer buf)
      Description copied from class: RawIOBase
      Read up to buf.remaining() bytes into buf. Returns number of bytes read (0 for EOF).
      Overrides:
      readinto in class RawIOBase
      Parameters:
      buf - a ByteBuffer to read bytes into
      Returns:
      the amount of data read as an int
    • write

      public int write(ByteBuffer buf)
      Description copied from class: RawIOBase
      Write the given ByteBuffer to the IO stream. Returns the number of bytes written, which may be less than buf.remaining().
      Overrides:
      write in class RawIOBase
      Parameters:
      buf - a ByteBuffer value
      Returns:
      the number of bytes written as an int
    • flush

      public void flush()
      Description copied from class: IOBase
      Flushes write buffers, if applicable. This is a no-op for read-only and non-blocking streams.
      Overrides:
      flush in class IOBase
    • close

      public void close()
      Description copied from class: IOBase
      Flushes and closes the IO object. This must be idempotent. It should also set a flag for the 'closed' property (see below) to test.
      Overrides:
      close in class IOBase
    • isatty

      public boolean isatty()
      Description copied from class: IOBase
      Returns whether this is an 'interactive' stream. Returns False if we don't know.
      Overrides:
      isatty in class IOBase
      Returns:
      a boolean, true if an 'interactive' stream
    • readable

      public boolean readable()
      Description copied from class: IOBase
      Return whether this file was opened for reading.
      Overrides:
      readable in class IOBase
      Returns:
      true if the file was opened for reading
    • writable

      public boolean writable()
      Description copied from class: IOBase
      Return whether this file was opened for writing.
      Overrides:
      writable in class IOBase
      Returns:
      true if the file was opened for writing
    • asOutputStream

      public OutputStream asOutputStream()
      Description copied from class: IOBase
      Coerce this into an OutputStream if possible, or return null.
      Overrides:
      asOutputStream in class IOBase
    • asInputStream

      public InputStream asInputStream()
      Description copied from class: IOBase
      Coerce this into an InputStream if possible, or return null.
      Overrides:
      asInputStream in class IOBase
    • getChannel

      public Channel getChannel()
      Description copied from class: RawIOBase
      Return the underlying Java nio Channel.
      Specified by:
      getChannel in class RawIOBase
      Returns:
      the underlying Java nio Channel