Class WebSocketUtils


  • public final class WebSocketUtils
    extends Object
    • Method Detail

      • readHeaders

        public static Map<String,​String> readHeaders​(InputStream in,
                                                           boolean req)
                                                    throws IOException
        Read header properties from the specified input stream. Only a restricted syntax is allowed as the syntax is in our control. Not allowed are: - multiline or line-wrapped headers are not not - charset other than utf-8. (although i would have preferred iso-8859-1 ;-)
        Parameters:
        in - the input stream
        req - true if the input stream includes the request line
        Returns:
        a map of name value pairs.
        Throws:
        IOException
      • readLine

        public static String readLine​(InputStream in)
                               throws IOException
        Read a line terminated by '\n' optionally preceded by '\r' from the specified input stream.
        Parameters:
        in - the input stream
        Returns:
        Throws:
        IOException
      • buildResponse

        public static byte[] buildResponse​(Map<String,​String> headers,
                                           byte[] data,
                                           int offset,
                                           int length)
        Build response bytes with the status and type information specified in the headers.
        Parameters:
        headers -
        data -
        offset -
        length -
        Returns:
      • buildResponse

        public static byte[] buildResponse​(byte[] headers,
                                           byte[] data,
                                           int offset,
                                           int length)
        Build response bytes with some generated headers.
        Parameters:
        headers -
        data -
        offset -
        length -
        Returns:
      • buildResponse

        public static byte[] buildResponse​(byte[] data,
                                           int offset,
                                           int length)
        Build response bytes without status and type information.
        Parameters:
        data -
        offset -
        length -
        Returns:
      • buildHeaderLine

        public static byte[] buildHeaderLine​(String name,
                                             String value)
      • buildRequest

        public static byte[] buildRequest​(String method,
                                          String url,
                                          Map<String,​String> headers,
                                          byte[] data,
                                          int offset,
                                          int length)
        Build request bytes with the specified method, url, headers, and content entity.
        Parameters:
        method -
        url -
        headers -
        data -
        offset -
        length -
        Returns:
      • isContainingCRLF

        public static boolean isContainingCRLF​(String value)