@Override
    public Iterable<Header> headers(final String key) {
        checkKey(key);
        return () -> new FilterByKeyIterator(headers.iterator(), key);
    }
@Test
    public void testHeaders() throws IOException {
        RecordHeaders headers = new RecordHeaders();
        headers.add(new RecordHeader("key", "value".getBytes()));
        headers.add(new RecordHeader("key1", "key1value".getBytes()));
        headers.add(new RecordHeader("key", "value2".getBytes()));
        headers.add(new RecordHeader("key2", "key2value".getBytes()));


        Iterator<Header> keyHeaders = headers.headers("key").iterator();
        assertHeader("key", "value", keyHeaders.next());
        assertHeader("key", "value2", keyHeaders.next());
        assertFalse(keyHeaders.hasNext());

        keyHeaders = headers.headers("key1").iterator();
        assertHeader("key1", "key1value", keyHeaders.next());
        assertFalse(keyHeaders.hasNext());

        keyHeaders = headers.headers("key2").iterator();
        assertHeader("key2", "key2value", keyHeaders.next());
        assertFalse(keyHeaders.hasNext());

    }