提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.infra.framework.file.core.client.local; |
H |
2 |
|
|
3 |
import cn.hutool.core.io.FileUtil; |
|
4 |
import com.iailab.module.infra.framework.file.core.client.AbstractFileClient; |
|
5 |
|
|
6 |
import java.io.File; |
|
7 |
|
|
8 |
/** |
|
9 |
* 本地文件客户端 |
|
10 |
* |
|
11 |
* @author iailab |
|
12 |
*/ |
|
13 |
public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> { |
|
14 |
|
|
15 |
public LocalFileClient(Long id, LocalFileClientConfig config) { |
|
16 |
super(id, config); |
|
17 |
} |
|
18 |
|
|
19 |
@Override |
|
20 |
protected void doInit() { |
|
21 |
// 补全风格。例如说 Linux 是 /,Windows 是 \ |
|
22 |
if (!config.getBasePath().endsWith(File.separator)) { |
|
23 |
config.setBasePath(config.getBasePath() + File.separator); |
|
24 |
} |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public String upload(byte[] content, String path, String type) { |
|
29 |
// 执行写入 |
|
30 |
String filePath = getFilePath(path); |
|
31 |
FileUtil.writeBytes(content, filePath); |
|
32 |
// 拼接返回路径 |
|
33 |
return super.formatFileUrl(config.getDomain(), path); |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public void delete(String path) { |
|
38 |
String filePath = getFilePath(path); |
|
39 |
FileUtil.del(filePath); |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
public byte[] getContent(String path) { |
|
44 |
String filePath = getFilePath(path); |
|
45 |
return FileUtil.readBytes(filePath); |
|
46 |
} |
|
47 |
|
|
48 |
private String getFilePath(String path) { |
|
49 |
return config.getBasePath() + path; |
|
50 |
} |
|
51 |
|
|
52 |
} |