Class ReaderInputStream

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

    public class ReaderInputStream
    extends java.io.InputStream
    Input stream based on a reader. The implementation relies on the NIO CharsetEncoder class.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.ByteBuffer byteBuffer
      The NIO byte buffer.
      private java.nio.CharBuffer charBuffer
      The NIO character buffer.
      private java.nio.charset.CharsetEncoder charsetEncoder
      The character set encoder.
      private boolean endReached
      Indicates if the end of the wrapped reader has been reached.
      private java.io.BufferedReader reader
      The wrapped reader.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()
      Closes the wrapped reader.
      int read()  
      int read​(byte[] b, int off, int len)  
      • Methods inherited from class java.io.InputStream

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

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

      • byteBuffer

        private final java.nio.ByteBuffer byteBuffer
        The NIO byte buffer.
      • charBuffer

        private final java.nio.CharBuffer charBuffer
        The NIO character buffer.
      • charsetEncoder

        private final java.nio.charset.CharsetEncoder charsetEncoder
        The character set encoder.
      • endReached

        private volatile boolean endReached
        Indicates if the end of the wrapped reader has been reached.
      • reader

        private final java.io.BufferedReader reader
        The wrapped reader.
    • Constructor Detail

      • ReaderInputStream

        public ReaderInputStream​(java.io.Reader reader)
                          throws java.io.IOException
        Constructor. Uses the CharacterSet.ISO_8859_1 character set by default.
        Parameters:
        reader - The reader to wrap as an input stream.
        Throws:
        java.io.IOException
      • ReaderInputStream

        public ReaderInputStream​(java.io.Reader reader,
                                 CharacterSet characterSet)
                          throws java.io.IOException
        Constructor.
        Parameters:
        reader - The reader to wrap as an input stream.
        characterSet - The character set to use for encoding.
        Throws:
        java.io.IOException
    • Method Detail

      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Closes the wrapped reader.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException