47 lines
1.1 KiB
Java
47 lines
1.1 KiB
Java
|
package eu.dnetlib.apps.oai2ftp.utils;
|
||
|
|
||
|
import java.io.File;
|
||
|
import java.io.FileWriter;
|
||
|
import java.io.IOException;
|
||
|
|
||
|
import org.apache.commons.io.FileUtils;
|
||
|
import org.apache.commons.io.IOUtils;
|
||
|
import org.apache.commons.logging.Log;
|
||
|
import org.apache.commons.logging.LogFactory;
|
||
|
|
||
|
public class LocalStorage implements StorageClient {
|
||
|
|
||
|
private static final Log log = LogFactory.getLog(LocalStorage.class);
|
||
|
|
||
|
@Override
|
||
|
public void login(final String user, final String password) {}
|
||
|
|
||
|
@Override
|
||
|
public void disconnect() {}
|
||
|
|
||
|
public String currDir = "/tmp";
|
||
|
|
||
|
@Override
|
||
|
public boolean changeDir(final String dir) {
|
||
|
try {
|
||
|
final File d = new File(dir.startsWith("/") ? dir : currDir + "/" + dir);
|
||
|
FileUtils.forceMkdir(d);
|
||
|
currDir = d.getAbsolutePath();
|
||
|
return true;
|
||
|
} catch (final IOException e) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void saveFile(final String filename, final String body) {
|
||
|
try {
|
||
|
IOUtils.write(body, new FileWriter(currDir + "/" + filename));
|
||
|
} catch (final IOException e) {
|
||
|
log.error("Error saving info file");
|
||
|
throw new RuntimeException("Error saving info file", e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|