<commit_before>package net.trajano.ms.engine.internal;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.NewCookie;

import io.vertx.core.MultiMap;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.RequestOptions;
import io.vertx.ext.web.impl.CookieImpl;

public final class Conversions {

    /**
     * Loads up the whole input stream data to a buffer/
     *
     * @param is
     * @return
     */
    public static Buffer toBuffer(final InputStream is) throws IOException {

        final Buffer b = Buffer.buffer(1024);
        final byte[] buf = new byte[1024];
        int len;
        while ((len = is.read(buf)) >= 0) {
            b.appendBytes(buf, 0, len);
        }
        return b;

    }

    /**
     * Converts a VertX cookie to a JaxRS Cookie.
     *
     * @param vertxCookie
     * @return
     */
    public static Cookie toCookie(final io.vertx.ext.web.Cookie vertxCookie) {

        return new Cookie(vertxCookie.getName(), vertxCookie.getValue(), vertxCookie.getPath(), vertxCookie.getDomain());
    }

    public static Map<String, Cookie> toCookies(final Set<io.vertx.ext.web.Cookie> vertxCookies) {

        final Map<String, Cookie> cookies = new HashMap<>(vertxCookies.size());
        vertxCookies.forEach(vertxCookie -> {
            cookies.put(vertxCookie.getName(), toCookie(vertxCookie));
        });
        return cookies;
    }

    public static MultivaluedMap<String, Object> toMultivaluedMap(final MultiMap multimap) {

        final MultivaluedMap<String, Object> mvm = new MultivaluedHashMap<>(multimap.size());
        multimap.forEach(entry -> {
            mvm.add(entry.getKey(), entry.getValue());
        });
        return mvm;
    }

    public static MultivaluedMap<String, String> toMultivaluedStringMap(final MultiMap multimap) {

        final MultivaluedMap<String, String> mvm = new MultivaluedHashMap<>(multimap.size());
        multimap.forEach(entry -> {
            mvm.add(entry.getKey(), entry.getValue());
        });
        return mvm;
    }

    public static RequestOptions toRequestOptions(final URI uri) {

        final RequestOptions options = new RequestOptions()
            .setSsl("https".equals(uri.getScheme()))
            .setHost(uri.getHost());
        if (uri.getPort() > 0) {
            options.setPort(uri.getPort());
        } else if (options.isSsl()) {
            options.setPort(443);
        } else {
            options.setPort(80);
        }
        if (uri.getRawQuery() == null) {
            options.setURI(uri.getRawPath());
        } else {
            options.setURI(uri.getRawPath() + "?" + uri.getRawQuery());
        }
        return options;
    }

    public static io.vertx.ext.web.Cookie toVertxCookie(final NewCookie cookie) {

        final io.vertx.ext.web.Cookie vertxCookie = new CookieImpl(cookie.getName(), cookie.getValue());
        vertxCookie.setPath(cookie.getPath());
        vertxCookie.setDomain(cookie.getDomain());
        vertxCookie.setHttpOnly(cookie.isHttpOnly());
        vertxCookie.setChanged(true);<commit_msg>Sonarqube fixes<commit_after>package net.trajano.ms.engine.internal;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.NewCookie;

import io.vertx.core.MultiMap;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.RequestOptions;
import io.vertx.ext.web.impl.CookieImpl;

public final class Conversions {

    /**
     * Loads up the whole input stream data to a buffer/
     *
     * @param is
     * @return
     */
    public static Buffer toBuffer(final InputStream is) throws IOException {

        final Buffer b = Buffer.buffer(1024);
        final byte[] buf = new byte[1024];
        int len;
        while ((len = is.read(buf)) >= 0) {
            b.appendBytes(buf, 0, len);
        }
        return b;

    }

    /**
     * Converts a VertX cookie to a JaxRS Cookie.
     *
     * @param vertxCookie
     * @return
     */
    public static Cookie toCookie(final io.vertx.ext.web.Cookie vertxCookie) {

        return new Cookie(vertxCookie.getName(), vertxCookie.getValue(), vertxCookie.getPath(), vertxCookie.getDomain());
    }

    public static Map<String, Cookie> toCookies(final Set<io.vertx.ext.web.Cookie> vertxCookies) {

        final Map<String, Cookie> cookies = new HashMap<>(vertxCookies.size());
        vertxCookies.forEach(vertxCookie -> cookies.put(vertxCookie.getName(), toCookie(vertxCookie)));
        return cookies;
    }

    public static MultivaluedMap<String, Object> toMultivaluedMap(final MultiMap multimap) {

        final MultivaluedMap<String, Object> mvm = new MultivaluedHashMap<>(multimap.size());
        multimap.forEach(entry -> mvm.add(entry.getKey(), entry.getValue()));
        return mvm;
    }

    public static MultivaluedMap<String, String> toMultivaluedStringMap(final MultiMap multimap) {

        final MultivaluedMap<String, String> mvm = new MultivaluedHashMap<>(multimap.size());
        multimap.forEach(entry -> mvm.add(entry.getKey(), entry.getValue()));
        return mvm;
    }

    public static RequestOptions toRequestOptions(final URI uri) {

        final RequestOptions options = new RequestOptions()
            .setSsl("https".equals(uri.getScheme()))
            .setHost(uri.getHost());
        if (uri.getPort() > 0) {
            options.setPort(uri.getPort());
        } else if (options.isSsl()) {
            options.setPort(443);
        } else {
            options.setPort(80);
        }
        if (uri.getRawQuery() == null) {
            options.setURI(uri.getRawPath());
        } else {
            options.setURI(uri.getRawPath() + "?" + uri.getRawQuery());
        }
        return options;
    }

    public static io.vertx.ext.web.Cookie toVertxCookie(final NewCookie cookie) {

        final io.vertx.ext.web.Cookie vertxCookie = new CookieImpl(cookie.getName(), cookie.getValue());
        vertxCookie.setPath(cookie.getPath());
        vertxCookie.setDomain(cookie.getDomain());
        vertxCookie.setHttpOnly(cookie.isHttpOnly());
        vertxCookie.setChanged(true);
{'fraction_non_alphanumeric': 0.12505754181371798, 'fraction_numerical': 0.0049102347705999696, 'mean_word_length': 2.7331042382588775, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5326936', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1967, 'n_words': 400}