<commit_before>/*
 *  Copyright(c) 2003-2004 by the authors indicated in the @author tags.
 *
 *  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 org.tigris.subversion.svnclientadapter.commandline;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Copies all data from an input stream to a String
 * This class is inspired by ant StreamPumper from <NAME>
 *
 */
public class CmdLineStreamPumper implements Runnable {
    private static final String NEWLINE = "\n\r";
    private static final int SLEEP = 5;
    private static final int SIZE = 128;
    private BufferedReader br;
    private boolean finished;
    private StringBuffer sb = new StringBuffer();
    private boolean coaleasceLines = false;

    /**
     * Create a new stream pumper.
     *
     * @param is input stream to read data from
     * @param coaleasceLines if true, it will coaleasce lines
     */
    public CmdLineStreamPumper(InputStream is, boolean coaleasceLines) {
        br = new BufferedReader(new InputStreamReader(is));
        this.coaleasceLines = coaleasceLines;
    }

    /**
     * Create a new stream pumper.
     *
     * @param is input stream to read data from
     */
    public CmdLineStreamPumper(InputStream is) {
        br = new BufferedReader(new InputStreamReader(is));
    }

    /**
     * Copies data from the input stream to the string buffer
     *
     * Terminates as soon as the input stream is closed or an error occurs.
     */
    public void run() {
        synchronized (this) {
            // Just in case this object is reused in the future
            finished = false;
        }

        final byte[] buf = new byte[SIZE];

        int length;
        try {
            String st;
            while((st=br.readLine())!=null) {
                if (coaleasceLines) {
                    sb.append(st);
                } else {
                    sb.append(st+NEWLINE);                    
                }
                try {
                    Thread.sleep(SLEEP);
                } catch (InterruptedException e) {}                
            }
        } catch (Exception e) {
            // ignore
        } finally {
            synchronized (this) {
                finished = true;
                notify();
            }
        }
    }

    public synchronized String toString() {
        return sb.toString();
    }

    /**
     * Tells whether the end of the stream has been reached.
     * @return true is the stream has been exhausted.
     **/<commit_msg>* patch from <NAME> applied I don't know while we did a sleep here. I can't see any reason why<commit_after>/*
 *  Copyright(c) 2003-2004 by the authors indicated in the @author tags.
 *
 *  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 org.tigris.subversion.svnclientadapter.commandline;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Copies all data from an input stream to a String
 * This class is inspired by ant StreamPumper from <NAME>
 *
 */
public class CmdLineStreamPumper implements Runnable {
    private static final String NEWLINE = "\n\r";
    private static final int SIZE = 128;
    private BufferedReader br;
    private boolean finished;
    private StringBuffer sb = new StringBuffer();
    private boolean coaleasceLines = false;

    /**
     * Create a new stream pumper.
     *
     * @param is input stream to read data from
     * @param coaleasceLines if true, it will coaleasce lines
     */
    public CmdLineStreamPumper(InputStream is, boolean coaleasceLines) {
        br = new BufferedReader(new InputStreamReader(is));
        this.coaleasceLines = coaleasceLines;
    }

    /**
     * Create a new stream pumper.
     *
     * @param is input stream to read data from
     */
    public CmdLineStreamPumper(InputStream is) {
        br = new BufferedReader(new InputStreamReader(is));
    }

    /**
     * Copies data from the input stream to the string buffer
     *
     * Terminates as soon as the input stream is closed or an error occurs.
     */
    public void run() {
        synchronized (this) {
            // Just in case this object is reused in the future
            finished = false;
        }

        final byte[] buf = new byte[SIZE];

        int length;
        try {
            String st;
            while((st=br.readLine())!=null) {
                if (coaleasceLines) {
                    sb.append(st);
                } else {
                    sb.append(st+NEWLINE);                    
                }
            }
        } catch (Exception e) {
            // ignore
        } finally {
            synchronized (this) {
                finished = true;
                notify();
            }
        }
    }

    public synchronized String toString() {
        return sb.toString();
    }

    /**
     * Tells whether the end of the stream has been reached.
     * @return true is the stream has been exhausted.
     **/
{'fraction_non_alphanumeric': 0.07936507936507936, 'fraction_numerical': 0.005125661375661375, 'mean_word_length': 2.0351229302558957, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '5221170', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1586, 'n_words': 610}