Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sfewfsaf
spring-boot-examples
提交
43c7a6f0
S
spring-boot-examples
项目概览
sfewfsaf
/
spring-boot-examples
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-boot-examples
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
43c7a6f0
编写于
5月 15, 2018
作者:
微笑很纯洁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
m
上级
bbf8a777
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
24 addition
and
14 deletion
+24
-14
spring-boot-fastDFS/src/main/java/com/neo/fastdfs/FastDFSClient.java
...-fastDFS/src/main/java/com/neo/fastdfs/FastDFSClient.java
+24
-14
未找到文件。
spring-boot-fastDFS/src/main/java/com/neo/fastdfs/FastDFSClient.java
浏览文件 @
43c7a6f0
...
...
@@ -10,18 +10,11 @@ import java.io.*;
public
class
FastDFSClient
{
private
static
org
.
slf4j
.
Logger
logger
=
LoggerFactory
.
getLogger
(
FastDFSClient
.
class
);
private
static
TrackerClient
trackerClient
;
private
static
TrackerServer
trackerServer
;
private
static
StorageClient
storageClient
;
private
static
StorageServer
storageServer
;
static
{
try
{
String
filePath
=
new
ClassPathResource
(
"fdfs_client.conf"
).
getFile
().
getAbsolutePath
();;
ClientGlobal
.
init
(
filePath
);
trackerClient
=
new
TrackerClient
();
trackerServer
=
trackerClient
.
getConnection
();
storageServer
=
trackerClient
.
getStoreStorage
(
trackerServer
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"FastDFS Client Init Fail!"
,
e
);
}
...
...
@@ -35,8 +28,9 @@ public class FastDFSClient {
long
startTime
=
System
.
currentTimeMillis
();
String
[]
uploadResults
=
null
;
StorageClient
storageClient
=
null
;
try
{
storageClient
=
new
StorageClient
(
trackerServer
,
storageServer
);
storageClient
=
getTrackerClient
(
);
uploadResults
=
storageClient
.
upload_file
(
file
.
getContent
(),
file
.
getExt
(),
meta_list
);
}
catch
(
IOException
e
)
{
logger
.
error
(
"IO Exception when uploadind the file:"
+
file
.
getName
(),
e
);
...
...
@@ -45,7 +39,7 @@ public class FastDFSClient {
}
logger
.
info
(
"upload_file time used:"
+
(
System
.
currentTimeMillis
()
-
startTime
)
+
" ms"
);
if
(
uploadResults
==
null
)
{
if
(
uploadResults
==
null
&&
storageClient
!=
null
)
{
logger
.
error
(
"upload file fail, error code:"
+
storageClient
.
getErrorCode
());
}
String
groupName
=
uploadResults
[
0
];
...
...
@@ -57,7 +51,7 @@ public class FastDFSClient {
public
static
FileInfo
getFile
(
String
groupName
,
String
remoteFileName
)
{
try
{
storageClient
=
new
StorageClient
(
trackerServer
,
storageServer
);
StorageClient
storageClient
=
getTrackerClient
(
);
return
storageClient
.
get_file_info
(
groupName
,
remoteFileName
);
}
catch
(
IOException
e
)
{
logger
.
error
(
"IO Exception: Get File from Fast DFS failed"
,
e
);
...
...
@@ -69,7 +63,7 @@ public class FastDFSClient {
public
static
InputStream
downFile
(
String
groupName
,
String
remoteFileName
)
{
try
{
storageClient
=
new
StorageClient
(
trackerServer
,
storageServer
);
StorageClient
storageClient
=
getTrackerClient
(
);
byte
[]
fileByte
=
storageClient
.
download_file
(
groupName
,
remoteFileName
);
InputStream
ins
=
new
ByteArrayInputStream
(
fileByte
);
return
ins
;
...
...
@@ -83,22 +77,38 @@ public class FastDFSClient {
public
static
void
deleteFile
(
String
groupName
,
String
remoteFileName
)
throws
Exception
{
storageClient
=
new
StorageClient
(
trackerServer
,
storageServer
);
StorageClient
storageClient
=
getTrackerClient
(
);
int
i
=
storageClient
.
delete_file
(
groupName
,
remoteFileName
);
logger
.
info
(
"delete file successfully!!!"
+
i
);
}
public
static
StorageServer
[]
getStoreStorages
(
String
groupName
)
throws
IOException
{
TrackerClient
trackerClient
=
new
TrackerClient
();
TrackerServer
trackerServer
=
trackerClient
.
getConnection
();
return
trackerClient
.
getStoreStorages
(
trackerServer
,
groupName
);
}
public
static
ServerInfo
[]
getFetchStorages
(
String
groupName
,
String
remoteFileName
)
throws
IOException
{
TrackerClient
trackerClient
=
new
TrackerClient
();
TrackerServer
trackerServer
=
trackerClient
.
getConnection
();
return
trackerClient
.
getFetchStorages
(
trackerServer
,
groupName
,
remoteFileName
);
}
public
static
String
getTrackerUrl
()
{
return
"http://"
+
trackerServer
.
getInetSocketAddress
().
getHostString
()+
":"
+
ClientGlobal
.
getG_tracker_http_port
()+
"/"
;
public
static
String
getTrackerUrl
()
throws
IOException
{
return
"http://"
+
getTrackerServer
().
getInetSocketAddress
().
getHostString
()+
":"
+
ClientGlobal
.
getG_tracker_http_port
()+
"/"
;
}
private
static
StorageClient
getTrackerClient
()
throws
IOException
{
TrackerServer
trackerServer
=
getTrackerServer
();
StorageClient
storageClient
=
new
StorageClient
(
trackerServer
,
null
);
return
storageClient
;
}
private
static
TrackerServer
getTrackerServer
()
throws
IOException
{
TrackerClient
trackerClient
=
new
TrackerClient
();
TrackerServer
trackerServer
=
trackerClient
.
getConnection
();
return
trackerServer
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录