Class PumpReader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable

    public class PumpReader
    extends java.io.Reader
    A reader implementation with an associated writer for buffered character transfer.

    The PumpReader class provides a Reader implementation with an associated Writer that allows characters to be written to the writer and then read from the reader. This creates a character pipe or pump that can be used to transfer character data between different components.

    This class is particularly useful for:

    • Creating character streams for testing without actual I/O
    • Buffering characters between producer and consumer threads
    • Implementing character-based pipes with flow control
    • Simulating input for terminal emulation

    The PumpReader maintains internal buffers for reading and writing, with both buffers backed by the same array. It provides methods for reading characters with optional timeouts and for checking the availability of characters without blocking.

    This class is used in JLine for various purposes, including implementing non-blocking readers and for testing terminal input handling without actual terminal devices.

    • Field Summary

      • Fields inherited from class java.io.Reader

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      PumpReader()  
      PumpReader​(int bufferSize)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()  
      java.io.InputStream createInputStream​(java.nio.charset.Charset charset)  
      java.io.Writer getWriter()  
      int read()  
      int read​(char[] cbuf, int off, int len)  
      int read​(java.nio.CharBuffer target)  
      boolean ready()  
      • Methods inherited from class java.io.Reader

        mark, markSupported, nullReader, read, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PumpReader

        public PumpReader()
      • PumpReader

        public PumpReader​(int bufferSize)
    • Method Detail

      • getWriter

        public java.io.Writer getWriter()
      • createInputStream

        public java.io.InputStream createInputStream​(java.nio.charset.Charset charset)
      • ready

        public boolean ready()
        Overrides:
        ready in class java.io.Reader
      • available

        public int available()
      • read

        public int read()
                 throws java.io.IOException
        Overrides:
        read in class java.io.Reader
        Throws:
        java.io.IOException
      • read

        public int read​(char[] cbuf,
                        int off,
                        int len)
                 throws java.io.IOException
        Specified by:
        read in class java.io.Reader
        Throws:
        java.io.IOException
      • read

        public int read​(java.nio.CharBuffer target)
                 throws java.io.IOException
        Specified by:
        read in interface java.lang.Readable
        Overrides:
        read in class java.io.Reader
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Reader
        Throws:
        java.io.IOException