class MetadataDownloadManager {

    public InputStream getInputStream(final Long folderId,
                                      final String entityClass,
                                      final String fileExtension) {
        final MetadataFileFormat fileFormat = retrieveMetadataFileFormat(fileExtension);
        final List<MetadataEntity> entities = retrieveMetadataEntities(folderId, entityClass);
        final StringWriter stringWriter = new StringWriter();
        final MetadataWriter metadataWriter = metadataWriterProvider.getMetadataWriter(stringWriter, fileFormat);
        metadataWriter.writeEntities(entityClass, entities);
        try {
            return new StringInputStream(stringWriter.toString());
        } catch (IOException e) {
            throw new MetadataWriterException(
                    messageHelper.getMessage(MessageConstants.ERROR_METADATA_ENTITY_WRITING_BAD_ENCODING), e);
        }
    }

}