<commit_before>package com.milaboratory.util;

import com.fasterxml.jackson.core.JsonProcessingException;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.charset.StandardCharsets;
import java.nio.file.StandardOpenOption;

public final class ReportUtil {
    private ReportUtil() {
    }

    public static void writeReportToStdout(Report report) {
        report.writeReport(ReportHelper.STDOUT);
    }

    static void appendAtomically(String fileName, byte[] content) {
        appendAtomically(new File(fileName), content);
    }

    static void appendAtomically(File file, byte[] content) {
        try (FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE);
             FileLock lock = lockIfPossible(channel)) {
            channel.position(channel.size());
            channel.write(ByteBuffer.wrap(content));
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }

    static void writeAtomically(String fileName, byte[] content) {
        writeAtomically(new File(fileName), content);
    }

    static void writeAtomically(File file, byte[] content) {
        try (FileChannel channel = FileChannel.open(file.toPath(),
                StandardOpenOption.WRITE, StandardOpenOption.CREATE);
             FileLock lock = lockIfPossible(channel)) {
            channel.truncate(0);
            channel.write(ByteBuffer.wrap(content));
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }

    static FileLock lockIfPossible(FileChannel channel) {
        try {
            return channel.lock();
        } catch (Exception e) {
            return null;
        }<commit_msg>feat: appendAtomically and writeAtomically methods of ReportUtil made public<commit_after>package com.milaboratory.util;

import com.fasterxml.jackson.core.JsonProcessingException;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.charset.StandardCharsets;
import java.nio.file.StandardOpenOption;

public final class ReportUtil {
    private ReportUtil() {
    }

    public static void writeReportToStdout(Report report) {
        report.writeReport(ReportHelper.STDOUT);
    }

    public static void appendAtomically(String fileName, byte[] content) {
        appendAtomically(new File(fileName), content);
    }

    public static void appendAtomically(File file, byte[] content) {
        try (FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE);
             FileLock lock = lockIfPossible(channel)) {
            channel.position(channel.size());
            channel.write(ByteBuffer.wrap(content));
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }

    public static void writeAtomically(String fileName, byte[] content) {
        writeAtomically(new File(fileName), content);
    }

    public static void writeAtomically(File file, byte[] content) {
        try (FileChannel channel = FileChannel.open(file.toPath(),
                StandardOpenOption.WRITE, StandardOpenOption.CREATE);
             FileLock lock = lockIfPossible(channel)) {
            channel.truncate(0);
            channel.write(ByteBuffer.wrap(content));
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }

    static FileLock lockIfPossible(FileChannel channel) {
        try {
            return channel.lock();
        } catch (Exception e) {
            return null;
        }
{'fraction_non_alphanumeric': 0.09591889784247466, 'fraction_numerical': 0.0005198856251624642, 'mean_word_length': 2.987564766839378, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '5445727', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1017, 'n_words': 228}