/*******************************************************************************
 * Copyright (c) 2021 Eclipse RDF4J contributors.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Distribution License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *******************************************************************************/

package org.eclipse.rdf4j.spring.support;

import java.lang.invoke.MethodHandles;
import java.util.Objects;

import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.spring.dao.exception.RDF4JSpringException;
import org.eclipse.rdf4j.spring.support.connectionfactory.RepositoryConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @since 4.0.0
 * @author Florian Kleedorfer
 */
@Component
public class DataInserter {

	private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

	@Autowired
	RepositoryConnectionFactory connectionFactory;

	@Transactional(propagation = Propagation.REQUIRED)
	public void insertData(Resource dataFile) {
		Objects.requireNonNull(dataFile);
		logger.debug("Loading data from {}...", dataFile);
		try {
			RepositoryConnection con = connectionFactory.getConnection();
			con.add(dataFile.getInputStream(), "", RDFFormat.TURTLE);
		} catch (Exception e) {
			throw new RDF4JSpringException("Unable to load test data", e);
		}
		logger.debug("\tdone loading data");
	}
}

@@ -574,16 +574,38 @@
 Objects;
+%0Aimport java.util.Set;
 %0A%0Aimport
@@ -1710,16 +1710,348 @@
 tion();%0A
+%09%09%09RDFFormat fmt = RDFFormat.matchFileName(%0A%09%09%09%09%09dataFile.getFilename(),%0A%09%09%09%09%09Set.of(%0A%09%09%09%09%09%09%09RDFFormat.TURTLE,%0A%09%09%09%09%09%09%09RDFFormat.TRIG,%0A%09%09%09%09%09%09%09RDFFormat.NTRIPLES,%0A%09%09%09%09%09%09%09RDFFormat.NQUADS))%0A%09%09%09%09%09.orElseThrow(%0A%09%09%09%09%09%09%09() -%3E new IllegalArgumentException(%0A%09%09%09%09%09%09%09%09%09%22Failed to determine file format of input file %22%0A%09%09%09%09%09%09%09%09%09%09%09+ dataFile));%0A
 %09%09%09con.a
@@ -2084,32 +2084,19 @@
 (), %22%22, 
-RDFFormat.TURTLE
+fmt
 );%0A%09%09%7D c

Make DataInserter more versatile