<commit_before>package com.tailoredshapes.underbar;

import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
import org.junit.Test;

import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.charset.Charset;
import java.util.Date;

import static com.tailoredshapes.stash.Stash.stash;
import static com.tailoredshapes.underbar.Dates.date;
import static com.tailoredshapes.underbar.IO.*;
import static org.junit.Assert.assertEquals;

public class IOTest {


    @Test
    public void easesBuildingAWriter() throws Exception {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        BufferedWriter writer = responseWriter(outputStream, stash());
        writer.write("Hello, World!");
        writer.flush();
        close(outputStream);
        assertEquals("Hello, World!", outputStream.toString("UTF-8"));
    }

    @Test
    public void canTakeACharSetFromAStash() throws Exception {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        BufferedWriter writer = responseWriter(outputStream, stash("encoding", "UTF-8"));
        writer.write("Hello, World!");
        writer.flush();
        close(outputStream);
        assertEquals("Hello, World!", outputStream.toString("UTF-8"));
    }

    @Test
    public void canGetLastModified() throws Exception {
        File file = file(resource("/test.txt"));
        assertEquals(new Date(file.lastModified()), lastModifiedDate(file));
    }

    @Test
    public void slurpCanReadAFile() throws Exception {
        assertEquals("Hello, World!", slurp(file(resource("/test.txt"))));
    }


    @Test
    public void slurpCanReadAnInputStream() throws Exception {
        assertEquals("Hello, World!", slurp(stringInputStream("Hello, World!")));
        assertEquals("Hello, World!", slurp(stringInputStream("Hello, World!", "UTF-8")));
    }


}<commit_msg>Always clean your imports<commit_after>package com.tailoredshapes.underbar;

import org.junit.Test;

import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.Date;

import static com.tailoredshapes.stash.Stash.stash;
import static com.tailoredshapes.underbar.IO.*;
import static org.junit.Assert.assertEquals;

public class IOTest {


    @Test
    public void easesBuildingAWriter() throws Exception {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        BufferedWriter writer = responseWriter(outputStream, stash());
        writer.write("Hello, World!");
        writer.flush();
        close(outputStream);
        assertEquals("Hello, World!", outputStream.toString("UTF-8"));
    }

    @Test
    public void canTakeACharSetFromAStash() throws Exception {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        BufferedWriter writer = responseWriter(outputStream, stash("encoding", "UTF-8"));
        writer.write("Hello, World!");
        writer.flush();
        close(outputStream);
        assertEquals("Hello, World!", outputStream.toString("UTF-8"));
    }

    @Test
    public void canGetLastModified() throws Exception {
        File file = file(resource("/test.txt"));
        assertEquals(new Date(file.lastModified()), lastModifiedDate(file));
    }

    @Test
    public void slurpCanReadAFile() throws Exception {
        assertEquals("Hello, World!", slurp(file(resource("/test.txt"))));
    }


    @Test
    public void slurpCanReadAnInputStream() throws Exception {
        assertEquals("Hello, World!", slurp(stringInputStream("Hello, World!")));
        assertEquals("Hello, World!", slurp(stringInputStream("Hello, World!", "UTF-8")));
    }


}
{'fraction_non_alphanumeric': 0.12570965125709652, 'fraction_numerical': 0.0021627466882941336, 'mean_word_length': 3.862023653088042, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '1458944', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1006, 'n_words': 216}