Class ByteArrayEndPoint

All Implemented Interfaces:
Closeable, AutoCloseable, EndPoint
Direct Known Subclasses:
LocalConnector.LocalEndPoint

public class ByteArrayEndPoint extends AbstractEndPoint
ByteArrayEndPoint.
  • Constructor Details

    • ByteArrayEndPoint

      public ByteArrayEndPoint()
    • ByteArrayEndPoint

      public ByteArrayEndPoint(byte[] input, int outputSize)
      Parameters:
      input - the input bytes
      outputSize - the output size
    • ByteArrayEndPoint

      public ByteArrayEndPoint(String input, int outputSize)
      Parameters:
      input - the input string (converted to bytes using default encoding charset)
      outputSize - the output size
    • ByteArrayEndPoint

      public ByteArrayEndPoint(Scheduler scheduler, long idleTimeoutMs)
    • ByteArrayEndPoint

      public ByteArrayEndPoint(Scheduler timer, long idleTimeoutMs, byte[] input, int outputSize)
    • ByteArrayEndPoint

      public ByteArrayEndPoint(Scheduler timer, long idleTimeoutMs, String input, int outputSize)
    • ByteArrayEndPoint

      public ByteArrayEndPoint(Scheduler timer, long idleTimeoutMs, ByteBuffer input, ByteBuffer output)
  • Method Details

    • getLocalSocketAddress

      public SocketAddress getLocalSocketAddress()
      Specified by:
      getLocalSocketAddress in interface EndPoint
      Overrides:
      getLocalSocketAddress in class AbstractEndPoint
      Returns:
      the local SocketAddress to which this EndPoint is bound or null if this EndPoint is not bound to a Socket address.
    • getRemoteSocketAddress

      public SocketAddress getRemoteSocketAddress()
      Specified by:
      getRemoteSocketAddress in interface EndPoint
      Overrides:
      getRemoteSocketAddress in class AbstractEndPoint
      Returns:
      The remote SocketAddress to which this EndPoint is connected, or null if this EndPoint is not connected to a Socket address.
    • doShutdownOutput

      public void doShutdownOutput()
      Overrides:
      doShutdownOutput in class AbstractEndPoint
    • doClose

      public void doClose()
      Overrides:
      doClose in class AbstractEndPoint
    • onIncompleteFlush

      protected void onIncompleteFlush()
      Specified by:
      onIncompleteFlush in class AbstractEndPoint
    • execute

      protected void execute(Runnable task)
    • needsFillInterest

      protected void needsFillInterest() throws IOException
      Specified by:
      needsFillInterest in class AbstractEndPoint
      Throws:
      IOException
    • addInputEOF

      public void addInputEOF()
    • addInput

      public void addInput(ByteBuffer in)
      Parameters:
      in - The in to set.
    • addInput

      public void addInput(String s)
    • addInput

      public void addInput(String s, Charset charset)
    • addInputAndExecute

      public void addInputAndExecute(ByteBuffer in)
    • getOutput

      public ByteBuffer getOutput()
      Returns:
      Returns the out.
    • getOutputString

      public String getOutputString()
      Returns:
      Returns the out.
    • getOutputString

      public String getOutputString(Charset charset)
      Parameters:
      charset - the charset to encode the output as
      Returns:
      Returns the out.
    • takeOutput

      public ByteBuffer takeOutput()
      Returns:
      Returns the out.
    • waitForOutput

      public ByteBuffer waitForOutput(long time, TimeUnit unit) throws InterruptedException
      Wait for some output
      Parameters:
      time - Time to wait
      unit - Units for time to wait
      Returns:
      The buffer of output
      Throws:
      InterruptedException - if interrupted
    • takeOutputString

      public String takeOutputString()
      Returns:
      Returns the out.
    • takeOutputString

      public String takeOutputString(Charset charset)
      Parameters:
      charset - the charset to encode the output as
      Returns:
      Returns the out.
    • setOutput

      public void setOutput(ByteBuffer out)
      Parameters:
      out - The out to set.
    • hasMore

      public boolean hasMore()
      Returns:
      true if there are bytes remaining to be read from the encoded input
    • fill

      public int fill(ByteBuffer buffer) throws IOException
      Description copied from interface: EndPoint
      Fill the passed buffer with data from this endpoint. The bytes are appended to any data already in the buffer by writing from the buffers limit up to it's capacity. The limit is updated to include the filled bytes.
      Parameters:
      buffer - The buffer to fill. The position and limit are modified during the fill. After the operation, the position is unchanged and the limit is increased to reflect the new data filled.
      Returns:
      an int value indicating the number of bytes filled or -1 if EOF is read or the input is shutdown.
      Throws:
      IOException - if the endpoint is closed.
    • flush

      public boolean flush(ByteBuffer... buffers) throws IOException
      Description copied from interface: EndPoint
      Flush data from the passed header/buffer to this endpoint. As many bytes as can be consumed are taken from the header/buffer position up until the buffer limit. The header/buffers position is updated to indicate how many bytes have been consumed.
      Parameters:
      buffers - the buffers to flush
      Returns:
      True IFF all the buffers have been consumed and the endpoint has flushed the data to its destination (ie is not buffering any data).
      Throws:
      IOException - If the endpoint is closed or output is shutdown.
    • reset

      public void reset()
      Overrides:
      reset in class AbstractEndPoint
    • getTransport

      public Object getTransport()
      Returns:
      The underlying transport object (socket, channel, etc.)
    • isGrowOutput

      public boolean isGrowOutput()
      Returns:
      the growOutput
    • setGrowOutput

      public void setGrowOutput(boolean growOutput)
      Parameters:
      growOutput - the growOutput to set
    • toString

      public String toString()
      Overrides:
      toString in class AbstractEndPoint