Class SocketUtils

    • Constructor Detail

      • SocketUtils

        public SocketUtils()
    • Method Detail

      • validResponse

        public static boolean validResponse​(String request,
                                            String responsePattern,
                                            BufferedReader r,
                                            Writer wr)
                                     throws IOException

        Writes request to wr then reads the response from r and validates that it matches the pattern provided in responsePattern.

        To obtain r from a java.util.Socket socket:
        new BufferedReader(new InputStreamReader(socket.getInputStream()));

        To obtain wr from a java.util.Socket socket:
        new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

        Parameters:
        request - the String to write to wr
        responsePattern - a String representing a regular expression pattern you expect to match the response received from r after writing request to wr
        r - the BufferedReader from which to get the response
        wr - the Writer on which the request is written
        Throws:
        IOException