<commit_before>/*
 * Copyright 2017 ImpactDevelopment
 *
 * 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 clientapi.util.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringJoiner;

/**
 * Reads from an InputStream
 *
 * @author Brady
 * @since 2/15/2017 12:00 PM
 */
public final class StreamReader {

    /**
     * Stream being read
     */
    private final InputStream stream;

    public StreamReader(InputStream stream) {
        this.stream = stream;
    }

    /**
     * Reads the stream and returns the output
     *
     * @return The stream's output
     */
    public final String read() {
        StringJoiner joiner = new StringJoiner("\n");
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(stream));
            br.lines().forEach(joiner::add);
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return joiner.toString();
    }
}<commit_msg>Updated StreamReader methods<commit_after>/*
 * Copyright 2017 ImpactDevelopment
 *
 * 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 clientapi.util.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringJoiner;
import java.util.stream.Stream;

/**
 * Reads the lines returned from an {@code InputStream}.
 *
 * @author Brady
 * @since 2/15/2017 12:00 PM
 */
public final class StreamReader {

    /**
     * Stream being read
     */
    private final InputStream stream;

    public StreamReader(InputStream stream) {
        this.stream = stream;
    }

    /**
     * Returns the lines found from the {@code InputStream}. An empty
     * stream will be returned in the case of an {@code IOException} being thrown.
     *
     * @return Stream containing all lines from the {@code InputStream}.
     */
    public final Stream<String> lines() {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(stream));
            Stream<String> lines = br.lines();
            br.close();
            return lines;
        } catch (IOException e) {
            return Stream.empty();
        }
    }

    /**
     * Returns all of the lines from the {@code InputStream}
     * as a single string. New lines are broken up by "\n"
     *
     * @return The stream's output
     */
    public final String all() {
        StringJoiner joiner = new StringJoiner("\n");
        lines().forEach(joiner::add);
        return joiner.toString();
    }
}
{'fraction_non_alphanumeric': 0.09389542841500137, 'fraction_numerical': 0.010402408978921434, 'mean_word_length': 2.7209775967413443, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2488579', 'n_tokens_mistral': 994, 'n_tokens_neox': 949, 'n_words': 369}