Class DynamicBuffer

java.lang.Object
com.sshtools.common.util.DynamicBuffer

public class DynamicBuffer extends Object

This class provides an alternative method of storing data, used within the API where Piped Streams could have been used. We found that Piped streams would lock if a thread attempted to read to data when the OutputStream attached was not being read; since we have no control over when the user will actually read the data, this behaviour led us to develop this dynamic buffer which will automatically grow if the buffer is full.

*
Author:
Lee David Painter
  • Field Details

    • DEFAULT_BUFFER_SIZE

      protected static final int DEFAULT_BUFFER_SIZE
      Buffer size when the dynamic buffer is opened
      See Also:
    • buf

      protected byte[] buf
      The buffer
    • writepos

      protected int writepos
      The current write position
    • readpos

      protected int readpos
      The current read position
    • in

      protected InputStream in
      This buffers InputStream
    • out

      protected OutputStream out
      This buffers OutputStream
  • Constructor Details

    • DynamicBuffer

      public DynamicBuffer()
      Creates a new DynamicBuffer object.
    • DynamicBuffer

      public DynamicBuffer(int bufferSize)
  • Method Details

    • getInputStream

      public InputStream getInputStream()
      Get the InputStream of this buffer. Use the stream to read data from this buffer.
      Returns:
    • getOutputStream

      public OutputStream getOutputStream()
      Get the OutputStream of the buffer. Use this stream to write data to the buffer.
      Returns:
    • getTimeout

      public long getTimeout()
    • setTimeout

      public void setTimeout(int timeout)
    • available

      protected int available()
      Return the number of bytes of data available to be read from the buffer
      Returns:
    • close

      public void close()
    • close

      public void close(boolean closedWithError)
      Closes the buffer
    • write

      protected void write(int b) throws IOException
      Write a byte array to the buffer
      Parameters:
      b -
      Throws:
      IOException
    • write

      protected void write(byte[] data, int offset, int len) throws IOException
      Parameters:
      data -
      offset -
      len -
      Throws:
      IOException
    • setBlockInterrupt

      public void setBlockInterrupt(int interrupt)
    • read

      protected int read() throws IOException
      Read a byte from the buffer
      Returns:
      Throws:
      IOException
      InterruptedIOException
    • read

      protected int read(byte[] data, int offset, int len) throws IOException
      Read a byte array from the buffer
      Parameters:
      data -
      offset -
      len -
      Returns:
      Throws:
      IOException
      InterruptedIOException
    • flush

      protected void flush() throws IOException
      Flush data
      Throws:
      IOException