use of com.bonree.brfs.disknode.server.handler.data.FileInfo in project BRFS by zhangnianli.
the class ListFileMessageHandler method traverse.
private void traverse(int level, ArrayList<FileInfo> fileInfoList) {
while (!fileList.isEmpty()) {
FileInfo fileInfo = fileList.remove();
if (fileInfo.getType() == FileInfo.TYPE_DIR && fileInfo.getLevel() < level) {
File[] subFiles = new File(fileInfo.getPath()).listFiles();
if (subFiles != null && subFiles.length > 0) {
for (File subFile : subFiles) {
FileInfo info = new FileInfo();
info.setLevel(fileInfo.getLevel() + 1);
info.setType(subFile.isDirectory() ? FileInfo.TYPE_DIR : FileInfo.TYPE_FILE);
info.setPath(subFile.getAbsolutePath());
fileList.addLast(info);
}
}
}
fileInfo.setPath(context.getLogicFilePath(fileInfo.getPath()));
fileInfoList.add(fileInfo);
}
}
use of com.bonree.brfs.disknode.server.handler.data.FileInfo in project BRFS by zhangnianli.
the class ListMessageHandler method handle.
@Override
public void handle(HttpMessage msg, HandleResultCallback callback) {
HandleResult result = new HandleResult();
String dirPath = null;
try {
dirPath = context.getConcreteFilePath(msg.getPath());
int level = Integer.parseInt(msg.getParams().getOrDefault("level", "1"));
File dir = new File(dirPath);
if (!dir.exists()) {
result.setSuccess(false);
result.setCause(new FileNotFoundException(msg.getPath()));
return;
}
if (!dir.isDirectory()) {
result.setSuccess(false);
result.setCause(new IllegalAccessException("[" + msg.getPath() + "] is not directory"));
return;
}
FileInfo dirInfo = new FileInfo();
dirInfo.setLevel(0);
dirInfo.setType(FileInfo.TYPE_DIR);
dirInfo.setPath(dirPath);
fileList.addLast(dirInfo);
ArrayList<FileInfo> fileInfoList = new ArrayList<FileInfo>();
traverse(level, fileInfoList);
result.setSuccess(true);
result.setData(JsonUtils.toJsonBytes(fileInfoList));
} catch (Exception e) {
LOG.error("list dir[{}] error", dirPath, e);
result.setSuccess(false);
} finally {
callback.completed(result);
}
}
use of com.bonree.brfs.disknode.server.handler.data.FileInfo in project BRFS by zhangnianli.
the class CopyCountCheck method converToStringList.
/**
* 概述:转换集合为str集合
* @param files
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static List<String> converToStringList(SecondIDParser parser, List<FileInfo> files, String dir, String sid) {
List<String> strs = new ArrayList<>();
String path;
String fileName;
List<String> errorFiles = new ArrayList<>();
String[] checks;
for (FileInfo file : files) {
if (file.getType() == FileInfo.TYPE_DIR) {
continue;
}
path = file.getPath();
fileName = getFileName(path);
// 排除rd文件
if (fileName.indexOf(".rd") > 0) {
fileName = fileName.substring(0, fileName.indexOf(".rd"));
errorFiles.add(fileName);
LOG.warn("file: [{}] contain rd file !! skip ", fileName);
continue;
}
// 排除非法数据
checks = BrStringUtils.getSplit(fileName, "_");
if (checks == null || checks.length <= 1) {
errorFiles.add(fileName);
LOG.warn("file: [{}] is unlaw file !! skip ", fileName);
continue;
}
if (isUnlaw(sid, parser, fileName)) {
LOG.warn("file: [{}] is not [{}] file", fileName, sid);
continue;
}
strs.add(fileName);
}
return filterErrors(strs, errorFiles);
}
use of com.bonree.brfs.disknode.server.handler.data.FileInfo in project BRFS by zhangnianli.
the class ListMessageHandler method traverse.
private void traverse(int level, ArrayList<FileInfo> fileInfoList) {
while (!fileList.isEmpty()) {
FileInfo fileInfo = fileList.remove();
if (fileInfo.getType() == FileInfo.TYPE_DIR && fileInfo.getLevel() < level) {
File[] subFiles = new File(fileInfo.getPath()).listFiles();
if (subFiles != null && subFiles.length > 0) {
for (File subFile : subFiles) {
FileInfo info = new FileInfo();
info.setLevel(fileInfo.getLevel() + 1);
info.setType(subFile.isDirectory() ? FileInfo.TYPE_DIR : FileInfo.TYPE_FILE);
info.setPath(subFile.getAbsolutePath());
fileList.addLast(info);
}
}
}
fileInfo.setPath(context.getLogicFilePath(fileInfo.getPath()));
fileInfoList.add(fileInfo);
}
}
use of com.bonree.brfs.disknode.server.handler.data.FileInfo in project BRFS by zhangnianli.
the class ListFileMessageHandler method handleMessage.
@Override
public void handleMessage(BaseMessage baseMessage, ResponseWriter<BaseResponse> writer) {
ListFileMessage message = ProtoStuffUtils.deserialize(baseMessage.getBody(), ListFileMessage.class);
if (message == null) {
writer.write(new BaseResponse(ResponseCode.ERROR_PROTOCOL));
return;
}
String dirPath = null;
try {
dirPath = context.getConcreteFilePath(message.getPath());
File dir = new File(dirPath);
if (!dir.exists()) {
writer.write(new BaseResponse(ResponseCode.ERROR));
return;
}
if (!dir.isDirectory()) {
writer.write(new BaseResponse(ResponseCode.ERROR));
return;
}
FileInfo dirInfo = new FileInfo();
dirInfo.setLevel(0);
dirInfo.setType(FileInfo.TYPE_DIR);
dirInfo.setPath(dirPath);
fileList.addLast(dirInfo);
ArrayList<FileInfo> fileInfoList = new ArrayList<FileInfo>();
traverse(message.getLevel(), fileInfoList);
BaseResponse response = new BaseResponse(ResponseCode.OK);
response.setBody(JsonUtils.toJsonBytes(fileInfoList));
writer.write(response);
} catch (Exception e) {
LOG.error("list dir[{}] error", dirPath, e);
writer.write(new BaseResponse(ResponseCode.ERROR));
}
}
Aggregations