class CsvParameterEntrySerializer implements ParameterEntrySerializer {

    @Override
    public void serialize(SerializationConfig config, Writer writer, Parameter parameter, ParameterEntryBatchLoader parameterEntryLoader) throws ParamSerializationException {
        CsvListWriter csvWriter = new CsvListWriter(writer, CsvPreferenceBuilder.csvPreference(config));

        try {
            long startTime = System.currentTimeMillis();
            logger.debug("started parameter entries serialization at {}", startTime);
            csvWriter.write(extractHeader(parameter));

            int counter = 0;
            while (parameterEntryLoader.hasMore()) {
                for (ParameterEntry entry : parameterEntryLoader.nextBatch(PARAMETER_ENTRY_BATCH_SIZE)) {
                    csvWriter.write(entry.getLevels());
                    counter++;
                    csvWriter.flush();
                }
            }

            csvWriter.flush();

            long endTime = System.currentTimeMillis();
            logger.debug("serializing {} parameter entries took {}", counter, endTime - startTime);
        } catch (IOException exception) {
            throw new EntriesCSVSerializationException(exception);
        } catch (ParamBatchLoadingException batchException) {
            throw new EntriesCSVSerializationException(batchException);
        } finally {
            StreamCloser.closeStream(writer);
        }
    }

}