Class NIODataInputStream

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

    public class NIODataInputStream
    extends RebufferingInputStream
    Rough equivalent of BufferedInputStream and DataInputStream wrapping the input stream of a File or Socket Created to work around the fact that when BIS + DIS delegate to NIO for socket IO they will allocate large thread local direct byte buffers when a large array is used to read. There may also be some performance improvement due to using a DBB as the underlying buffer for IO and the removal of some indirection and delegation when it comes to reading out individual values, but that is not the goal. Closing NIODataInputStream will invoke close on the ReadableByteChannel provided at construction. NIODataInputStream is not thread safe.
    • Field Detail

      • channel

        protected final java.nio.channels.ReadableByteChannel channel
    • Constructor Detail

      • NIODataInputStream

        public NIODataInputStream​(java.nio.channels.ReadableByteChannel channel,
                                  int bufferSize)
    • Method Detail

      • reBuffer

        protected void reBuffer()
                         throws java.io.IOException
        Description copied from class: RebufferingInputStream
        Implementations must implement this method to refill the buffer. They can expect the buffer to be empty when this method is invoked.
        Specified by:
        reBuffer in class RebufferingInputStream
        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
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

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