
io.leopard.data.dfs.DfsFileImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leopard-dfs Show documentation
Show all versions of leopard-dfs Show documentation
分布式文件系统实现,目前只是做了基于GridFS的实现,可以在本机文件系统进行缓存。
package io.leopard.data.dfs;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
public class DfsFileImpl implements Dfs, InitializingBean, DisposableBean {
protected Log logger = LogFactory.getLog(this.getClass());
private static final File rootDir = new File("/data/dfs");
@Override
public boolean create(String filename, byte[] data) {
File file = new File(rootDir, filename);
// logger.info("create:" + file.getAbsolutePath());
try {
FileUtils.writeByteArrayToFile(file, data);
return true;
}
catch (IOException e) {
logger.error(e.getMessage(), e);
return false;
}
}
@Override
public byte[] read(String filename) throws IOException {
File file = new File(rootDir, filename);
// logger.info("read:" + file.getAbsolutePath());
return FileUtils.readFileToByteArray(file);
}
@Override
public boolean delete(String filename) {
File file = new File(rootDir, filename);
FileUtils.deleteQuietly(file);
return false;
}
@Override
public void destroy() throws Exception {
}
@Override
public void afterPropertiesSet() throws Exception {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy