public int bytesRead() {
        if (buffer == null)
            return size.position();
        return buffer.position() + size.position();
    }
@Test
    public void testBytesRead() throws IOException {
        NetworkReceive receive = new NetworkReceive(128, "0");
        assertEquals(0, receive.bytesRead());

        ScatteringByteChannel channel = Mockito.mock(ScatteringByteChannel.class);

        ArgumentCaptor<ByteBuffer> bufferCaptor = ArgumentCaptor.forClass(ByteBuffer.class);
        Mockito.when(channel.read(bufferCaptor.capture())).thenAnswer(invocation -> {
            bufferCaptor.getValue().putInt(128);
            return 4;
        }).thenReturn(0);

        assertEquals(4, receive.readFrom(channel));
        assertEquals(4, receive.bytesRead());
        assertFalse(receive.complete());

        Mockito.reset(channel);
        Mockito.when(channel.read(bufferCaptor.capture())).thenAnswer(invocation -> {
            bufferCaptor.getValue().put(TestUtils.randomBytes(64));
            return 64;
        });

        assertEquals(64, receive.readFrom(channel));
        assertEquals(68, receive.bytesRead());
        assertFalse(receive.complete());

        Mockito.reset(channel);
        Mockito.when(channel.read(bufferCaptor.capture())).thenAnswer(invocation -> {
            bufferCaptor.getValue().put(TestUtils.randomBytes(64));
            return 64;
        });

        assertEquals(64, receive.readFrom(channel));
        assertEquals(132, receive.bytesRead());
        assertTrue(receive.complete());
    }