<commit_before>package com.jifalops.wsnlocalize.file;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class NumberReaderWriter extends TextReaderWriter {
    public interface NumberCallbacks {
        void onNumbersRead(NumberReaderWriter rw, double[][] numbers);
        void onNumbersWritten(NumberReaderWriter rw, int recordsWritten);
    }

    final IoCallbacks ioCallbacks = new IoCallbacks() {
        @Override
        public void onReadCompleted(TextReaderWriter rw, List<String> lines) {
            int rows = lines.size();
//            if (rows == 0) { return; }
            int cols = lines.get(0).split(",").length;
            final double[][] numbers = new double[rows][cols];
            for (int i = 0; i < rows; ++i) {
                String[] p = lines.get(i).split(",");
                for (int j = 0; j < cols; ++j) {
                    try {
                        numbers[i][j] = Double.valueOf(p[j]);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            creationThreadHandler.post(new Runnable() {
                @Override
                public void run() {
                    callbacks.onNumbersRead(NumberReaderWriter.this, numbers);
                }
            });
        }
        @Override
        public void onWriteCompleted(TextReaderWriter rw, final int linesWritten) {
            creationThreadHandler.post(new Runnable() {
                @Override
                public void run() {
                    callbacks.onNumbersWritten(NumberReaderWriter.this, linesWritten);
                }
            });
        }
    };

    final NumberCallbacks callbacks;
    public NumberReaderWriter(File file, NumberCallbacks callbacks) {
        super(file);
        this.callbacks = callbacks;
        setIoCallbacks(ioCallbacks);
    }

    public boolean readNumbers() {
        return readLines();
    }

    public void writeNumbers(double[][] numbers, boolean append) {
        List<String> lines = new ArrayList<>();
        StringBuilder sb;
        int cols = numbers[0].length;
        for (double[] row : numbers) {
            sb = new StringBuilder(cols*2-1);
            for (int i = 0; i < cols; ++i) {
                if (i != 0) sb.append(",");
                sb.append(row[i]);
            }
            lines.add(sb.toString());
        }
        writeLines(lines, append);
    }
}
<commit_msg>Bugfix for empty file<commit_after>package com.jifalops.wsnlocalize.file;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class NumberReaderWriter extends TextReaderWriter {
    public interface NumberCallbacks {
        void onNumbersRead(NumberReaderWriter rw, double[][] numbers);
        void onNumbersWritten(NumberReaderWriter rw, int recordsWritten);
    }

    final IoCallbacks ioCallbacks = new IoCallbacks() {
        @Override
        public void onReadCompleted(TextReaderWriter rw, List<String> lines) {
            double[][] numbers = null;
            int rows = lines.size();
            if (rows > 0) {
                int cols = lines.get(0).split(",").length;
                numbers = new double[rows][cols];
                for (int i = 0; i < rows; ++i) {
                    String[] p = lines.get(i).split(",");
                    for (int j = 0; j < cols; ++j) {
                        try {
                            numbers[i][j] = Double.valueOf(p[j]);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
            final double[][] finalNumbers = numbers;
            creationThreadHandler.post(new Runnable() {
                @Override
                public void run() {
                    callbacks.onNumbersRead(NumberReaderWriter.this, finalNumbers);
                }
            });
        }
        @Override
        public void onWriteCompleted(TextReaderWriter rw, final int linesWritten) {
            creationThreadHandler.post(new Runnable() {
                @Override
                public void run() {
                    callbacks.onNumbersWritten(NumberReaderWriter.this, linesWritten);
                }
            });
        }
    };

    final NumberCallbacks callbacks;
    public NumberReaderWriter(File file, NumberCallbacks callbacks) {
        super(file);
        this.callbacks = callbacks;
        setIoCallbacks(ioCallbacks);
    }

    public boolean readNumbers() {
        return readLines();
    }

    public void writeNumbers(double[][] numbers, boolean append) {
        List<String> lines = new ArrayList<>();
        StringBuilder sb;
        int cols = numbers[0].length;
        for (double[] row : numbers) {
            sb = new StringBuilder(cols*2-1);
            for (int i = 0; i < cols; ++i) {
                if (i != 0) sb.append(",");
                sb.append(row[i]);
            }
            lines.add(sb.toString());
        }
        writeLines(lines, append);
    }
}

{'fraction_non_alphanumeric': 0.11057037181234183, 'fraction_numerical': 0.0035039906560249173, 'mean_word_length': 1.6134282807731435, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 10, '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': '3752167', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1316, 'n_words': 317}