Class ConfinedInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.mysql.cj.protocol.x.ConfinedInputStream
All Implemented Interfaces:
java.io.Closeable, java.lang.AutoCloseable

public class ConfinedInputStream
extends java.io.FilterInputStream
An InputStream wrapper that limits the number of bytes that can be read form the underlying InputStream.
  • Field Summary

    Fields inherited from class java.io.FilterInputStream

    in
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected ConfinedInputStream​(java.io.InputStream in)  
    protected ConfinedInputStream​(java.io.InputStream in, int lim)  
  • Method Summary

    Modifier and Type Method Description
    int available()
    Returns the number of bytes not yet consumed.
    void close()
    Closes this stream and throws away any bytes not consumed from the underlying InputStream.
    protected long dumpLeftovers()
    Skips the number bytes not yet consumed from the underlying InputStream.
    int read()  
    int read​(byte[] b)
    Forwards the read to read(byte[], int, int).
    int read​(byte[] b, int off, int len)
    Reads bytes from the underlying InputStream up to the number of bytes defined in this ConfinedInputStream limit.
    int resetLimit​(int len)
    Resets this ConfinedInputStream limit so that it can be reused over the same underlying InputStream.

    Methods inherited from class java.io.FilterInputStream

    mark, markSupported, reset, skip

    Methods inherited from class java.io.InputStream

    nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo

    Methods inherited from class java.lang.Object

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

  • Method Details

    • available

      public int available() throws java.io.IOException
      Returns the number of bytes not yet consumed. Note that this method doen't care about the exact number of bytes that may or may not be available in the underlying InputStream
      Overrides:
      available in class java.io.FilterInputStream
      Returns:
      the number of bytes available.
      Throws:
      java.io.IOException
      See Also:
      FilterInputStream.available()
    • close

      public void close() throws java.io.IOException
      Closes this stream and throws away any bytes not consumed from the underlying InputStream.
      Specified by:
      close in interface java.lang.AutoCloseable
      Specified by:
      close in interface java.io.Closeable
      Overrides:
      close in class java.io.FilterInputStream
      Throws:
      java.io.IOException
      See Also:
      FilterInputStream.close()
    • read

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

      public int read​(byte[] b) throws java.io.IOException
      Forwards the read to read(byte[], int, int).
      Overrides:
      read in class java.io.FilterInputStream
      Throws:
      java.io.IOException
      See Also:
      FilterInputStream.read(byte[])
    • read

      public int read​(byte[] b, int off, int len) throws java.io.IOException
      Reads bytes from the underlying InputStream up to the number of bytes defined in this ConfinedInputStream limit.
      Overrides:
      read in class java.io.FilterInputStream
      Throws:
      java.io.IOException
      See Also:
      FilterInputStream.read(byte[], int, int)
    • resetLimit

      public int resetLimit​(int len)
      Resets this ConfinedInputStream limit so that it can be reused over the same underlying InputStream.
      Parameters:
      len - the new length to set.
      Returns:
      the number of bytes not consumed before reseting the limit.
    • dumpLeftovers

      protected long dumpLeftovers() throws java.io.IOException
      Skips the number bytes not yet consumed from the underlying InputStream.
      Returns:
      the number of bytes skipped.
      Throws:
      java.io.IOException - if any of the underlying I/O operations fail.