com.graphaware.importer.data.location.FileLocator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of programmatic-importer Show documentation
Show all versions of programmatic-importer Show documentation
Importer high-performance multi-threaded initial data load into Neo4j from CSV/SQL with custom logic
The newest version!
/*
* Copyright (c) 2013-2016 GraphAware
*
* This file is part of the GraphAware Framework.
*
* GraphAware Framework is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the
* GNU General Public License along with this program. If not, see .
*/
package com.graphaware.importer.data.location;
import com.graphaware.importer.data.Data;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.Map;
/**
* A {@link DataLocator} that translates data locations to absolute paths to files.
*/
public class FileLocator extends SimpleDataLocator {
private final String dir;
/**
* Construct a new locator.
*
* @param dir directory in which to locate files.
* @param fileNames map of data to logical file names (i.e. without suffix).
*/
public FileLocator(String dir, Map fileNames) {
super(fileNames);
this.dir = dir;
}
/**
* {@inheritDoc}
*
* @return absolute path to a file.
*/
@Override
public String locate(Data data) {
String location = super.locate(data);
try {
FileUtils.forceMkdir(new File(dir));
} catch (IOException e) {
throw new RuntimeException(e);
}
return new File(dir + File.separator + location + suffix()).getAbsolutePath();
}
/**
* Get the suffix appended to logical file names.
*
* @return suffix. ".csv" by default.
*/
protected String suffix() {
return ".csv";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy