Class ByteString

  • Direct Known Subclasses:
    URI.Path

    public class ByteString
    extends java.lang.Object
    String of bytes. Used by the Network classes to avoid converting the byte array received from a Socket into Strings.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected byte[] base  
      protected int len  
      protected int pos  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static int convertToInt​(byte[] b, int start, int end)
      Convert the literal representation of an int to its int value
      int convertToInt​(int start)
      Convert the literal representation of an int to its int value
      static ByteString copy​(ByteString source)
      Copy - if the source is null, this returns null.
      boolean equalsAtIgnoreCase​(byte[] b, int at)
      Check if this ByteString equals the byte array b, for the length of the byte array, starting at at within this ByteString.
      boolean equalsIgnoreCase​(byte[] b, int pos, int len)
      Check if this ByteString equals the value of the passed arguments
      boolean equalsIgnoreCase​(ByteString c)
      Check if this ByteString is equal to the one passed in the argument.
      int indexOf​(byte[] b, int start)
      Find the first byte array b in this ByteString.
      int indexOf​(byte b, int start)
      Find the first byte b in this ByteString.
      int lastIndexOf​(byte b)
      Find the last byte b in this ByteString.
      ByteString substring​(int start, int end)
      Creates a ByteString substring.
      java.lang.String toString()
      Return a String representation of this ByteString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • base

        protected byte[] base
      • pos

        protected int pos
      • len

        protected int len
    • Method Detail

      • copy

        public static ByteString copy​(ByteString source)
        Copy - if the source is null, this returns null. Otherwise, the ByteString is copied.
        Parameters:
        source - ByteString to be copied
      • substring

        public ByteString substring​(int start,
                                    int end)
        Creates a ByteString substring.
        Parameters:
        start - the first character of the substring
        end - the character after the last character of the substring
        Returns:
        the ByteString substring
      • equalsIgnoreCase

        public final boolean equalsIgnoreCase​(byte[] b,
                                              int pos,
                                              int len)
        Check if this ByteString equals the value of the passed arguments
        Parameters:
        b - byte array that holds the value to check against
        pos - first byte in the byte array
        len - length of the value to check against
        Returns:
        true if this ByteString matches, false otherwise
      • equalsIgnoreCase

        public final boolean equalsIgnoreCase​(ByteString c)
        Check if this ByteString is equal to the one passed in the argument.
        Parameters:
        c - ByteString to check against
        Returns:
        true if this ByteString is equal to the c ByteString, false otherwise.
      • equalsAtIgnoreCase

        public final boolean equalsAtIgnoreCase​(byte[] b,
                                                int at)
        Check if this ByteString equals the byte array b, for the length of the byte array, starting at at within this ByteString.

        This extends, some how, startsWidth and endsWidth, avoiding substring.

        Parameters:
        b - byte array that holds the value to check against
        at - first byte in this ByteString
        Returns:
        true if this ByteString matches, false otherwise
      • toString

        public final java.lang.String toString()
        Return a String representation of this ByteString
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String representation of this ByteString
      • indexOf

        public final int indexOf​(byte b,
                                 int start)
        Find the first byte b in this ByteString.
        Parameters:
        b - byte to find
        start - where to start from
        Returns:
        the offset of the byte, if found; -1 if not found
      • lastIndexOf

        public final int lastIndexOf​(byte b)
        Find the last byte b in this ByteString.
        Parameters:
        b - byte to find
        Returns:
        the offset of the byte, if found; -1 if not found
      • indexOf

        public final int indexOf​(byte[] b,
                                 int start)
        Find the first byte array b in this ByteString.
        Parameters:
        b - byte array to find
        start - where to start from
        Returns:
        the offset of the byte array, if found; -1 if not found
      • convertToInt

        public static int convertToInt​(byte[] b,
                                       int start,
                                       int end)
        Convert the literal representation of an int to its int value
        Parameters:
        b - byte array that holds the literal representation
        start - where it starts in the byte array
        end - where it ends
        Returns:
        the integer value, or -1 if wrong representation.
      • convertToInt

        public int convertToInt​(int start)
        Convert the literal representation of an int to its int value
        Parameters:
        start - where the int represenation starts in this ByteString
        Returns:
        the integer value, or -1 if wrong representation.