public static String getLeadingComment(String sql) {
        if (sql == null || sql.isEmpty()) {
            return "";
        }

        StringBuilder builder = new StringBuilder();
        for (int i = 0, len = sql.length(); i + 1 < len; i++) {
            char ch = sql.charAt(i);
            char nextCh = sql.charAt(i + 1);

            if (ch == '-' && nextCh == '-') {
                int index = skipSingleLineComment(sql, i, len);
                if (index > i + 2) {
                    builder.append(sql.substring(i + 2, index).trim());
                }
                i = index - 1;
            } else if (ch == '/' && nextCh == '*') {
                int index = skipMultiLineComment(sql, i + 2, len);
                if (index > i + 4) {
                    builder.append(sql.substring(i + 2, index - 2).trim());
                }
                i = index - 1;
            } else if (!Character.isWhitespace(ch)) {
                break;
            }

            if (builder.length() > 0) {
                break;
            }
        }

        return builder.toString();
    }
Get output stream for writing a file. Directories and file will be created if
they do not exist.

@param file path to the file
@return output stream
@throws IOException when failed to create directories and/or file
clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseUtils.java