<commit_before>/*
 ** 2015 March 02
 **
 ** The author disclaims copyright to this source code. In place of
 ** a legal notice, here is a blessing:
 **    May you do good and not evil.
 **    May you find forgiveness for yourself and forgive others.
 **    May you share freely, never taking more than you give.
 */
package info.ata4.io.stream;

import info.ata4.io.buffer.source.BufferedSource;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;

/**
 *
 * @author <NAME> <barracuda415 at yahoo.de>
 */
public class BufferedSourceOutputStream extends OutputStream {
    
    private final BufferedSource buf;
    
    public BufferedSourceOutputStream(BufferedSource buf) {
        if (!buf.canWrite()) {
            throw new IllegalArgumentException("Source is not writable");
        }
        this.buf = buf;
    }

    @Override
    public void write(int b) throws IOException {
        buf.requestWrite(1).put((byte) b);
    }

    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        ByteBuffer bb = ByteBuffer.wrap(b, off, len);
        while (bb.hasRemaining()) {
            buf.write(bb);
        }
    }
}
<commit_msg>Optimized write method for small byte arrays<commit_after>/*
 ** 2015 March 02
 **
 ** The author disclaims copyright to this source code. In place of
 ** a legal notice, here is a blessing:
 **    May you do good and not evil.
 **    May you find forgiveness for yourself and forgive others.
 **    May you share freely, never taking more than you give.
 */
package info.ata4.io.stream;

import info.ata4.io.buffer.source.BufferedSource;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;

/**
 *
 * @author <NAME> <barracuda415 at yahoo.de>
 */
public class BufferedSourceOutputStream extends OutputStream {
    
    private final BufferedSource buf;
    
    public BufferedSourceOutputStream(BufferedSource buf) {
        if (!buf.canWrite()) {
            throw new IllegalArgumentException("Source is not writable");
        }
        this.buf = buf;
    }

    @Override
    public void write(int b) throws IOException {
        buf.requestWrite(1).put((byte) b);
    }

    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        if (len > buf.bufferSize()) {
            ByteBuffer bb = ByteBuffer.wrap(b, off, len);
            while (bb.hasRemaining()) {
                buf.write(bb);
            }
        } else {
            buf.requestWrite(len).put(b, off, len);
        }
    }
}

{'fraction_non_alphanumeric': 0.10405300077942323, 'fraction_numerical': 0.009353078721745909, 'mean_word_length': 2.605337078651685, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '5451555', 'n_tokens_mistral': 751, 'n_tokens_neox': 723, 'n_words': 239}