Class TcpMessage

java.lang.Object
org.microproxy.tcp.TcpMessage

public final class TcpMessage extends Object
Bytes the proxy read from one side of a raw TCP tunnel, as a TcpInterceptor sees them.

TCP is a byte stream, not a sequence of messages: a message is whatever one read returned, so the peer's writes may arrive split into several messages or joined into one, differently from one run to the next. A hook that looks for a line or a command must allow for it starting in one message and ending in the next.

  • Constructor Details

    • TcpMessage

      public TcpMessage(byte[] data, boolean fromClient, Instant timestamp)
      A message.
      Parameters:
      data - the bytes, which the message holds as they are (not copied)
      fromClient - whether the client sent them, rather than the server
      timestamp - when the proxy read them
  • Method Details

    • data

      public byte[] data()
      The bytes as read. The array is the message's own, not a copy: an interceptor may change it in place and return it.
      Returns:
      the bytes
    • length

      public int length()
      Returns the number of bytes.
      Returns:
      the number of bytes
    • fromClient

      public boolean fromClient()
      Returns whether the client sent the bytes (going to the server), rather than the server.
      Returns:
      whether the client sent the bytes (going to the server), rather than the server
    • timestamp

      public Instant timestamp()
      Returns when the proxy read the bytes.
      Returns:
      when the proxy read the bytes
    • text

      public String text()
      The bytes decoded as UTF-8, malformed sequences replaced with U+FFFD. A character split between two messages shows as replacement characters in both.
      Returns:
      the text
    • withData

      public TcpMessage withData(byte[] data)
      A copy of this message with other bytes, the same direction and timestamp.
      Parameters:
      data - the bytes of the copy (not copied)
      Returns:
      the copy
    • withText

      public TcpMessage withText(String text)
      A copy of this message with the UTF-8 encoding of text.
      Parameters:
      text - the text of the copy
      Returns:
      the copy
    • toString

      public String toString()
      Overrides:
      toString in class Object