Class ByteArrayEscapeUtils


  • public final class ByteArrayEscapeUtils
    extends Object
    Removes the 0 byte from a byte array. Preserves ordering.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] escape​(byte[] bytes, byte... appendAfterEscaping)
      Escapes the provided byte[] so that it no longer contains the Constants.DELIMITER character.
      static byte[] unEscape​(byte[] bytes)
      Unescapes the provided byte array - this should only be called on byte arrays that have been through the escape method.
      static byte[] unEscape​(byte[] allBytes, int start, int end)
      Unescapes the provided byte array - this should only be called on byte arrays that have been through the escape method.
      static byte[] unEscapeByLength​(byte[] allBytes, int offset, int length)
      Unescapes the provided byte array - this should only be called on byte arrays that have been through the escape method.
      static byte[] unEscapeByPosition​(byte[] allBytes, int start, int end)
      Unescapes the provided byte array - this should only be called on byte arrays that have been through the escape method.
    • Method Detail

      • escape

        public static byte[] escape​(byte[] bytes,
                                    byte... appendAfterEscaping)
        Escapes the provided byte[] so that it no longer contains the Constants.DELIMITER character. After escaping the byte[] the appendAfterEscaping[] is appended unescaped.
        Parameters:
        bytes - the byte array to escape
        appendAfterEscaping - the bytes to append to the array after being escaped.
        Returns:
        the escaped byte array
      • unEscape

        public static byte[] unEscape​(byte[] bytes)
        Unescapes the provided byte array - this should only be called on byte arrays that have been through the escape method.
        Parameters:
        bytes - the byte array to unescape
        Returns:
        the unescaped byte array
      • unEscape

        public static byte[] unEscape​(byte[] allBytes,
                                      int start,
                                      int end)
        Unescapes the provided byte array - this should only be called on byte arrays that have been through the escape method.
        Parameters:
        allBytes - The backing byte array which contains the subset to unEscape
        start - The position to start the unEscape, inclusive.
        end - The position to end the unEscape, exclusive
        Returns:
        the unescaped byte array
      • unEscapeByPosition

        public static byte[] unEscapeByPosition​(byte[] allBytes,
                                                int start,
                                                int end)
        Unescapes the provided byte array - this should only be called on byte arrays that have been through the escape method.
        Parameters:
        allBytes - The backing byte array which contains the subset to unEscape
        start - The position to start the unEscape, inclusive.
        end - The position to end the unEscape, exclusive
        Returns:
        the unescaped byte array
      • unEscapeByLength

        public static byte[] unEscapeByLength​(byte[] allBytes,
                                              int offset,
                                              int length)
        Unescapes the provided byte array - this should only be called on byte arrays that have been through the escape method.
        Parameters:
        allBytes - The backing byte array which contains the subset to unEscape.
        offset - The position to start the unEscape, inclusive
        length - The length of bytes to unEscape
        Returns:
        the unescaped byte array