Class ContentUtil


  • public class ContentUtil
    extends Object
    Utility methods for converting textual content of a message.
    • Method Detail

      • getBufferRecycler

        public static BufferRecycler getBufferRecycler()
      • copy

        public static void copy​(Reader in,
                                Writer out)
                         throws IOException
        Copies the contents of one stream to the other.
        Parameters:
        in - not null
        out - not null
        Throws:
        IOException
      • encode

        public static ByteSequence encode​(CharSequence string)
        Encodes the specified string into an immutable sequence of bytes using the US-ASCII charset or UTF-8 in case none ASCII characters are in the sequence.
        Parameters:
        string - string to encode.
        Returns:
        encoded string as an immutable sequence of bytes.
      • encode

        public static ByteSequence encode​(Charset charset,
                                          CharSequence string)
        Encodes the specified string into an immutable sequence of bytes using the specified charset.
        Parameters:
        charset - Java charset to be used for the conversion.
        string - string to encode.
        Returns:
        encoded string as an immutable sequence of bytes.
      • decode

        public static String decode​(ByteSequence byteSequence)
        Decodes the specified sequence of bytes into a string using the US-ASCII charset.
        Parameters:
        byteSequence - sequence of bytes to decode.
        Returns:
        decoded string.
      • decode

        public static String decode​(Charset charset,
                                    ByteSequence byteSequence)
        Decodes the specified sequence of bytes into a string using the specified charset.
        Parameters:
        charset - Java charset to be used for the conversion.
        byteSequence - sequence of bytes to decode.
        Returns:
        decoded string.
      • decode

        public static String decode​(ByteSequence byteSequence,
                                    int offset,
                                    int length)
        Decodes a sub-sequence of the specified sequence of bytes into a string using the US-ASCII charset.
        Parameters:
        byteSequence - sequence of bytes to decode.
        offset - offset into the byte sequence.
        length - number of bytes.
        Returns:
        decoded string.
      • decode

        public static String decode​(ByteSequence byteSequence,
                                    int offset,
                                    int length,
                                    Charset charset)
        Decodes a sub-sequence of the specified sequence of bytes into a string using the US-ASCII charset with falling back to decode(Charset, ByteSequence, int, int) on a first non US-ASCII character.
        Parameters:
        byteSequence - sequence of bytes to decode.
        offset - offset into the byte sequence.
        length - number of bytes.
        charset - fallback charset.
        Returns:
        decoded string.
      • decode

        public static String decode​(Charset charset,
                                    ByteSequence byteSequence,
                                    int offset,
                                    int length)
        Decodes a sub-sequence of the specified sequence of bytes into a string using the specified charset.
        Parameters:
        charset - Java charset to be used for the conversion.
        byteSequence - sequence of bytes to decode.
        offset - offset into the byte sequence.
        length - number of bytes.
        Returns:
        decoded string.
      • toByteArray

        public static byte[] toByteArray​(String s,
                                         Charset charset)
      • toAsciiByteArray

        public static byte[] toAsciiByteArray​(String s)
      • toString

        public static String toString​(byte[] b,
                                      Charset charset)
      • toAsciiString

        public static String toAsciiString​(byte[] b)
      • toString

        public static String toString​(byte[] b,
                                      int off,
                                      int len,
                                      Charset charset)
      • toAsciiString

        public static String toAsciiString​(byte[] b,
                                           int off,
                                           int len)