<commit_before>package com.cqs.nio;

import com.google.common.base.Stopwatch;
import org.apache.commons.io.IOUtils;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.concurrent.TimeUnit;

/**
 * Created by cqs on 10/30/16.
 */
public class FileChannelDemo {

    public static void sendFile(OutputStream os, RandomAccessFile raFile) throws IOException {
        FileChannel channel = raFile.getChannel();
        final int SIZE = 1024 * 1024;//1M
        ByteBuffer buffer = ByteBuffer.allocate(SIZE);
        byte[] bytes = new byte[SIZE];
        int length;
        while ((length = channel.read(buffer)) != -1) {
            buffer.flip();
            while (buffer.hasRemaining()) {
                buffer.get(bytes, 0, length);
                os.write(bytes);
            }
            buffer.clear();
        }
        os.flush();
        IOUtils.closeQuietly(channel);
    }

    public static void main(String[] args) throws IOException {
        Stopwatch stopwatch = Stopwatch.createStarted();
//        stopwatch.start();<commit_msg>del comments<commit_after>package com.cqs.nio;

import com.google.common.base.Stopwatch;
import org.apache.commons.io.IOUtils;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.concurrent.TimeUnit;

/**
 * Created by cqs on 10/30/16.
 */
public class FileChannelDemo {

    public static void sendFile(OutputStream os, RandomAccessFile raFile) throws IOException {
        FileChannel channel = raFile.getChannel();
        final int SIZE = 1024 * 1024;//1M
        ByteBuffer buffer = ByteBuffer.allocate(SIZE);
        byte[] bytes = new byte[SIZE];
        int length;
        while ((length = channel.read(buffer)) != -1) {
            buffer.flip();
            while (buffer.hasRemaining()) {
                buffer.get(bytes, 0, length);
                os.write(bytes);
            }
            buffer.clear();
        }
        os.flush();
        IOUtils.closeQuietly(channel);
    }

    public static void main(String[] args) throws IOException {
        Stopwatch stopwatch = Stopwatch.createStarted();
{'fraction_non_alphanumeric': 0.1172668513388735, 'fraction_numerical': 0.01569713758079409, 'mean_word_length': 2.43968253968254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2132385', 'n_tokens_mistral': 642, 'n_tokens_neox': 607, 'n_words': 145}