Class PumpReader

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

    public class PumpReader
    extends java.io.Reader
    • Constructor Summary

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()  
      private int copyFromBuffer​(char[] cbuf, int off, int len)  
      java.io.InputStream createInputStream​(java.nio.charset.Charset charset)  
      private void encodeBytes​(java.nio.charset.CharsetEncoder encoder, java.nio.ByteBuffer output)  
      (package private) void flush()  
      java.io.Writer getWriter()  
      int read()  
      int read​(char[] cbuf, int off, int len)  
      int read​(java.nio.CharBuffer target)  
      (package private) int readBytes​(java.nio.charset.CharsetEncoder encoder, byte[] b, int off, int len)  
      (package private) void readBytes​(java.nio.charset.CharsetEncoder encoder, java.nio.ByteBuffer output)  
      boolean ready()  
      private static boolean rewind​(java.nio.CharBuffer buffer, java.nio.CharBuffer other)  
      private boolean rewindReadBuffer()
      Attempts to find additional input by rewinding the readBuffer.
      private void rewindWriteBuffer()
      Attempts to find additional buffer space by rewinding the writeBuffer.
      private boolean wait​(java.nio.CharBuffer buffer)
      Waits until buffer.hasRemaining() == true, or it is false and the reader is closed.
      private void waitForBufferSpace()
      Blocks until there is new space available for buffering or the reader is closed.
      private boolean waitForInput()
      Blocks until input is available or the reader is closed.
      private boolean waitForMoreInput()
      Blocks until more input is available, even if readBuffer already contains some chars; or until the reader is closed.
      (package private) void write​(char c)  
      (package private) void write​(char[] cbuf, int off, int len)  
      (package private) void write​(java.lang.String str, int off, int len)  
      • 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
    • Field Detail

      • readBuffer

        private final java.nio.CharBuffer readBuffer
      • writeBuffer

        private final java.nio.CharBuffer writeBuffer
      • closed

        private boolean closed
    • 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)
      • waitForMoreInput

        private boolean waitForMoreInput()
                                  throws java.io.InterruptedIOException
        Blocks until more input is available, even if readBuffer already contains some chars; or until the reader is closed.
        Returns:
        true if more input is available, false if no additional input is available and the reader is closed
        Throws:
        java.io.InterruptedIOException - If Object.wait() is interrupted
      • wait

        private boolean wait​(java.nio.CharBuffer buffer)
                      throws java.io.InterruptedIOException
        Waits until buffer.hasRemaining() == true, or it is false and the reader is closed.
        Returns:
        true if buffer.hasRemaining() == true; false otherwise when reader is closed
        Throws:
        java.io.InterruptedIOException
      • waitForInput

        private boolean waitForInput()
                              throws java.io.InterruptedIOException
        Blocks until input is available or the reader is closed.
        Returns:
        true if input is available, false if no input is available and the reader is closed
        Throws:
        java.io.InterruptedIOException - If Object.wait() is interrupted
      • waitForBufferSpace

        private void waitForBufferSpace()
                                 throws java.io.InterruptedIOException,
                                        ClosedException
        Blocks until there is new space available for buffering or the reader is closed.
        Throws:
        java.io.InterruptedIOException - If Object.wait() is interrupted
        ClosedException - If the reader was closed
      • rewind

        private static boolean rewind​(java.nio.CharBuffer buffer,
                                      java.nio.CharBuffer other)
      • rewindReadBuffer

        private boolean rewindReadBuffer()
        Attempts to find additional input by rewinding the readBuffer. Updates the writeBuffer to make read bytes available for buffering.
        Returns:
        If more input is available
      • rewindWriteBuffer

        private void rewindWriteBuffer()
        Attempts to find additional buffer space by rewinding the writeBuffer. Updates the readBuffer to make written bytes available to the reader.
      • 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
      • copyFromBuffer

        private int copyFromBuffer​(char[] cbuf,
                                   int off,
                                   int len)
      • 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
      • encodeBytes

        private void encodeBytes​(java.nio.charset.CharsetEncoder encoder,
                                 java.nio.ByteBuffer output)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • readBytes

        int readBytes​(java.nio.charset.CharsetEncoder encoder,
                      byte[] b,
                      int off,
                      int len)
               throws java.io.IOException
        Throws:
        java.io.IOException
      • readBytes

        void readBytes​(java.nio.charset.CharsetEncoder encoder,
                       java.nio.ByteBuffer output)
                throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        void write​(char c)
            throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        void write​(char[] cbuf,
                   int off,
                   int len)
            throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        void write​(java.lang.String str,
                   int off,
                   int len)
            throws java.io.IOException
        Throws:
        java.io.IOException
      • flush

        void flush()
      • 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