package com.paritytrading.nassau.binaryfile;

import static com.paritytrading.nassau.Strings.*;
import static java.util.Arrays.*;
import static org.junit.Assert.*;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.List;
import org.junit.Test;

public class BinaryFILEWriterTest {

    @Test
    public void write() throws Exception {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();

        BinaryFILEWriter writer = new BinaryFILEWriter(stream);

        List<String> messages = asList("foo", "bar", "baz", "quux", "");

        for (String message : messages)
            writer.write(wrap(message));

        byte[] writtenBytes  = stream.toByteArray();
        byte[] expectedBytes = toByteArray(getClass().getResourceAsStream("/binaryfile.dat"));

        assertArrayEquals(expectedBytes, writtenBytes);
    }

    private byte[] toByteArray(InputStream input) throws Exception {
        ByteArrayOutputStream output = new ByteArrayOutputStream();

        int b;

        while ((b = input.read()) != -1)
            output.write(b);

        return output.toByteArray();
    }

}

@@ -212,22 +212,50 @@
 ava.
+n
 io.
-InputStream
+file.Files;%0Aimport java.nio.file.Paths
 ;%0Aim
@@ -763,27 +763,44 @@
 Bytes = 
-toByteArray
+Files.readAllBytes(Paths.get
 (getClas
@@ -818,16 +818,8 @@
 urce
-AsStream
 (%22/b
@@ -833,16 +833,25 @@
 le.dat%22)
+.toURI())
 );%0A%0A    
@@ -913,275 +913,6 @@
  %7D%0A%0A
-    private byte%5B%5D toByteArray(InputStream input) throws Exception %7B%0A        ByteArrayOutputStream output = new ByteArrayOutputStream();%0A%0A        int b;%0A%0A        while ((b = input.read()) != -1)%0A            output.write(b);%0A%0A        return output.toByteArray();%0A    %7D%0A%0A
 %7D%0A

Clean up test for BinaryFILE writer