class FormatAnalysis implements SynchronousDataSetAnalyzer {

    @Override
    public void analyze(String dataSetId) {

        if (StringUtils.isEmpty(dataSetId)) {
            throw new IllegalArgumentException("Data set id cannot be null or empty.");
        }

        final Marker marker = Markers.dataset(dataSetId);

        DistributedLock datasetLock = repository.createDatasetMetadataLock(dataSetId);
        datasetLock.lock();
        try {
            DataSetMetadata metadata = repository.get(dataSetId);
            if (metadata != null) {

                Format detectedFormat = null;
                for (byte[] bom : BOMS) {
                    try (InputStream content = store.getAsRaw(metadata, 10)) { // 10 line should be enough to detect format

                        detectedFormat = detector.detect(addBOM(content, bom));
                    } catch (IOException e) {
                        throw new TDPException(DataSetErrorCodes.UNABLE_TO_READ_DATASET_CONTENT, e);
                    }
                    if (detectedFormat != null
                            && !(detectedFormat.getFormatFamily() instanceof UnsupportedFormatFamily)) {
                        break;
                    }
                }

                LOG.debug(marker, "using {} to parse the dataset", detectedFormat);

                verifyFormat(detectedFormat);

                internalUpdateMetadata(metadata, detectedFormat);

                LOG.debug(marker, "format analysed for dataset");
            } else {
                LOG.info(marker, "Data set no longer exists.");
            }
        } finally {
            datasetLock.unlock();
        }
    }

}