<commit_before>package at.hollanderkalauner.gpgpu;

import org.apache.commons.io.IOUtils;
import org.lwjgl.BufferUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class Util {

    public static String readFully(String file) throws IOException {
        return readFully(new File(file));
    }

    public static String readFully(File file) throws IOException {
        return IOUtils.toString(new FileInputStream(file), java.nio.charset.StandardCharsets.UTF_8);
    }

    /**
     * Utility method to convert float array to float buffer
     *
     * @param floats - the float array to convert
     * @return a float buffer containing the input float array
     */
    public static FloatBuffer toFloatBuffer(float[] floats) {
        FloatBuffer buf = BufferUtils.createFloatBuffer(floats.length).put(floats);
        buf.rewind();
        return buf;
    }


    /**
     * Utility method to toString a float buffer
     *
     * @param buffer - the float buffer to toString to System.out
     */
    public static String toString(FloatBuffer buffer) {
        StringBuilder str = new StringBuilder(buffer.capacity() * 2);
        str.append('[');
        for (int i = 0; i < buffer.capacity(); i++) {
            str.append(buffer.get(i));
            if (i != buffer.capacity() - 1) {
                str.append(", ");
            }
        }
        str.append(']');
        return str.toString();
    }

    public static String toString(ByteBuffer buffer) {
        byte[] bytes = new byte[buffer.capacity()];
        for (int i = 0; i < buffer.capacity(); i++) {
          bytes[i] = buffer.get(i);
        }
        return new String(bytes, StandardCharsets.UTF_8);
    }

    public static IntBuffer toIntBuffer(int[] ints) {
        return (IntBuffer) BufferUtils.createIntBuffer(ints.length).put(ints).rewind();
    }

    public static IntBuffer asIntBuffer(int i) {<commit_msg>Util.toString now terminates a string with 0x00<commit_after>package at.hollanderkalauner.gpgpu;

import org.apache.commons.io.IOUtils;
import org.lwjgl.BufferUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.charset.StandardCharsets;

public class Util {

    public static String readFully(String file) throws IOException {
        return readFully(new File(file));
    }

    public static String readFully(File file) throws IOException {
        return IOUtils.toString(new FileInputStream(file), java.nio.charset.StandardCharsets.UTF_8);
    }

    /**
     * Utility method to convert float array to float buffer
     *
     * @param floats - the float array to convert
     * @return a float buffer containing the input float array
     */
    public static FloatBuffer toFloatBuffer(float[] floats) {
        FloatBuffer buf = BufferUtils.createFloatBuffer(floats.length).put(floats);
        buf.rewind();
        return buf;
    }


    /**
     * Utility method to toString a float buffer
     *
     * @param buffer - the float buffer to toString to System.out
     */
    public static String toString(FloatBuffer buffer) {
        StringBuilder str = new StringBuilder(buffer.capacity() * 2);
        str.append('[');
        for (int i = 0; i < buffer.capacity(); i++) {
            str.append(buffer.get(i));
            if (i != buffer.capacity() - 1) {
                str.append(", ");
            }
        }
        str.append(']');
        return str.toString();
    }

    public static String toString(ByteBuffer buffer) {
        byte[] inBytes = new byte[buffer.capacity()];
        buffer.get(inBytes);
        byte[] outBytes = inBytes;
        for (int i = 0; i < inBytes.length; i++) {
            byte b = inBytes[i];
            if (b == 0x00) {
                outBytes = new byte[i];
                System.arraycopy(inBytes, 0, outBytes, 0, i);
                break;
            }
        }
        return new String(outBytes, StandardCharsets.UTF_8);
    }

    public static IntBuffer toIntBuffer(int[] ints) {
        return (IntBuffer) BufferUtils.createIntBuffer(ints.length).put(ints).rewind();
    }

    public static IntBuffer asIntBuffer(int i) {
{'fraction_non_alphanumeric': 0.11035730438715513, 'fraction_numerical': 0.004522840343735866, 'mean_word_length': 2.5243027888446217, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5557502', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1258, 'n_words': 341}