<commit_before>/*
 * Copyright (c) 2016, 2017 <NAME>, All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

 
package com.github.dyna4jdbc.internal.scriptengine.jdbc.impl;

import com.github.dyna4jdbc.internal.CancelException;
import com.github.dyna4jdbc.internal.JDBCError;
import com.github.dyna4jdbc.internal.ScriptExecutionException;
import com.github.dyna4jdbc.internal.common.outputhandler.IOHandlerFactory;
import com.github.dyna4jdbc.internal.common.outputhandler.impl.DefaultIOHandlerFactory;
import com.github.dyna4jdbc.internal.common.util.io.AbortableOutputStream;
import com.github.dyna4jdbc.internal.config.Configuration;

import javax.script.*;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

final class BasicScriptEngineScriptExecutor implements ScriptEngineScriptExecutor {

    private final Object lockObject = new Object();

    private final String systemName;

    private final ScriptEngine scriptEngine;

    private final IOHandlerFactory ioHandlerFactory;

    private AtomicReference<AbortableOutputStream.AbortHandler> streamAbortHandlerRef = new AtomicReference<>();

    BasicScriptEngineScriptExecutor(String systemName, ScriptEngine scriptEngine, Configuration configuration) {
        if (systemName == null || "".equals(systemName.trim())) {
            throw new NullPointerException("argument systemName cannot be null");
        }
        if (scriptEngine == null) {
            throw new NullPointerException("argument scriptEngine cannot be null");
        }
        if (configuration == null) {
            throw new NullPointerException("argument configuration cannot be null");
        }

        this.systemName = systemName;
        this.scriptEngine = scriptEngine;
        this.ioHandlerFactory = DefaultIOHandlerFactory.getInstance(configuration);
    }

    @Override
    public void executeScriptUsingStreams(
            String script, Map<String, Object> variables,
            OutputStream stdOutOutputStream,
            OutputStream errorOutputStream) throws ScriptExecutionException {

        AbortableOutputStream.AbortHandler abortHandler = new AbortableOutputStream.AbortHandler();

        executeScriptUsingAbortableStreams(script,
                variables,
                new AbortableOutputStream(stdOutOutputStream, abortHandler),
                new AbortableOutputStream(errorOutputStream, abortHandler),
                abortHandler);
    }
<commit_msg>Code cleanup<commit_after>/*
 * Copyright (c) 2016, 2017 <NAME>, All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

 
package com.github.dyna4jdbc.internal.scriptengine.jdbc.impl;

import com.github.dyna4jdbc.internal.CancelException;
import com.github.dyna4jdbc.internal.JDBCError;
import com.github.dyna4jdbc.internal.ScriptExecutionException;
import com.github.dyna4jdbc.internal.common.outputhandler.IOHandlerFactory;
import com.github.dyna4jdbc.internal.common.outputhandler.impl.DefaultIOHandlerFactory;
import com.github.dyna4jdbc.internal.common.util.io.AbortableOutputStream;
import com.github.dyna4jdbc.internal.config.Configuration;

import javax.script.*;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

final class BasicScriptEngineScriptExecutor implements ScriptEngineScriptExecutor {

    private final Object lockObject = new Object();

    private final String systemName;

    private final ScriptEngine scriptEngine;

    private final IOHandlerFactory ioHandlerFactory;

    private AtomicReference<AbortableOutputStream.AbortHandler> streamAbortHandlerRef = new AtomicReference<>();

    BasicScriptEngineScriptExecutor(String systemName, ScriptEngine scriptEngine, Configuration configuration) {
        Objects.requireNonNull(scriptEngine, "argument systemName cannot be null");
        if ("".equals(systemName.trim())) {
            throw new IllegalArgumentException("argument systemName cannot be empty/whitespace-only");
        }
        Objects.requireNonNull(scriptEngine, "argument scriptEngine cannot be null");
        Objects.requireNonNull(configuration, "argument configuration cannot be null");

        this.systemName = systemName;
        this.scriptEngine = scriptEngine;
        this.ioHandlerFactory = DefaultIOHandlerFactory.getInstance(configuration);
    }

    @Override
    public void executeScriptUsingStreams(
            String script, Map<String, Object> variables,
            OutputStream stdOutOutputStream,
            OutputStream errorOutputStream) throws ScriptExecutionException {

        AbortableOutputStream.AbortHandler abortHandler = new AbortableOutputStream.AbortHandler();

        executeScriptUsingAbortableStreams(script,
                variables,
                new AbortableOutputStream(stdOutOutputStream, abortHandler),
                new AbortableOutputStream(errorOutputStream, abortHandler),
                abortHandler);
    }

{'fraction_non_alphanumeric': 0.07563566140971999, 'fraction_numerical': 0.006437077566784679, 'mean_word_length': 4.032388663967612, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '146062', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1485, 'n_words': 438}