Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyuan
byit-myth-job
Commits
b8389a87
Commit
b8389a87
authored
Feb 14, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fastdfs组件封装
parent
4058490d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
264 additions
and
0 deletions
+264
-0
pom.xml
byit-myth-core/myth-executor-core/pom.xml
+11
-0
FileSystemContext.java
...c/main/java/com/byit/executor/conf/FileSystemContext.java
+43
-0
FastDfsFileSystem.java
.../java/com/byit/executor/filesystem/FastDfsFileSystem.java
+87
-0
FileSystem.java
...rc/main/java/com/byit/executor/filesystem/FileSystem.java
+50
-0
fdfs_client.conf
...re/myth-executor-core/src/main/resources/fdfs_client.conf
+14
-0
FastDFSTest.java
...yth-executor-core/src/test/java/com/test/FastDFSTest.java
+49
-0
pom.xml
pom.xml
+10
-0
No files found.
byit-myth-core/myth-executor-core/pom.xml
View file @
b8389a87
...
...
@@ -46,6 +46,17 @@
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
</dependency>
<dependency>
<groupId>
net.oschina.zcx7878
</groupId>
<artifactId>
fastdfs-client-java
</artifactId>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
...
...
byit-myth-core/myth-executor-core/src/main/java/com/byit/executor/conf/FileSystemContext.java
0 → 100644
View file @
b8389a87
package
com
.
byit
.
executor
.
conf
;
import
com.byit.executor.filesystem.FileSystem
;
import
org.apache.commons.io.FileUtils
;
import
org.csource.common.MyException
;
import
java.io.IOException
;
import
java.util.Map
;
/**
* 文件系统上下文对象
* @author huangfu
*/
public
class
FileSystemContext
{
private
FileSystem
fileSystem
;
public
FileSystemContext
(
FileSystem
fileSystem
)
{
this
.
fileSystem
=
fileSystem
;
}
public
String
uploadFile
(
byte
[]
fileBuffer
,
String
fileExtName
,
Map
<
String
,
String
>
mateDaTA
)
throws
IOException
,
MyException
{
return
fileSystem
.
uploadFile
(
fileBuffer
,
fileExtName
,
mateDaTA
);
}
public
byte
[]
downloaderFile
(
String
remPath
)
throws
IOException
,
MyException
{
return
fileSystem
.
downloaderFile
(
remPath
);
}
public
void
fileRemove
(
String
remPath
)
throws
IOException
,
MyException
{
fileSystem
.
fileRemove
(
remPath
);
}
public
void
fileAppend
(
String
filePath
,
byte
[]
fileBuffer
)
throws
IOException
,
MyException
{
fileSystem
.
fileAppend
(
filePath
,
fileBuffer
);
}
public
Map
<
String
,
String
>
getFileMate
(
String
filePath
)
throws
IOException
,
MyException
{
return
fileSystem
.
getFileMate
(
filePath
);
}
}
byit-myth-core/myth-executor-core/src/main/java/com/byit/executor/filesystem/FastDfsFileSystem.java
0 → 100644
View file @
b8389a87
package
com
.
byit
.
executor
.
filesystem
;
import
cn.hutool.core.collection.CollectionUtil
;
import
org.csource.common.MyException
;
import
org.csource.common.NameValuePair
;
import
org.csource.fastdfs.*
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Set
;
/**
* FastDFS设计模式
* @author huangfu
*/
public
class
FastDfsFileSystem
implements
FileSystem
{
static
{
try
{
ClientGlobal
.
init
(
"fdfs_client.conf"
);
}
catch
(
IOException
|
MyException
e
)
{
e
.
printStackTrace
();
}
}
@Override
public
String
uploadFile
(
byte
[]
fileBuffer
,
String
fileExtName
,
Map
<
String
,
String
>
mateDaTa
)
throws
IOException
,
MyException
{
TrackerClient
trackerClient
=
new
TrackerClient
();
TrackerServer
trackerServer
=
trackerClient
.
getConnection
();
StorageClient1
storageClient1
=
new
StorageClient1
(
trackerServer
,
null
);
NameValuePair
[]
mathList
=
new
NameValuePair
[
mateDaTa
.
size
()];
if
(
CollectionUtil
.
isNotEmpty
(
mateDaTa
)){
Set
<
Map
.
Entry
<
String
,
String
>>
mateSet
=
mateDaTa
.
entrySet
();
int
i
=
0
;
for
(
Map
.
Entry
<
String
,
String
>
mate
:
mateSet
)
{
mathList
[
i
]
=
new
NameValuePair
(
mate
.
getKey
(),
mate
.
getValue
());
i
++;
}
}
String
fileId
=
storageClient1
.
upload_file1
(
fileBuffer
,
fileExtName
,
mathList
);
trackerServer
.
close
();
return
fileId
;
}
@Override
public
byte
[]
downloaderFile
(
String
remPath
)
throws
IOException
,
MyException
{
TrackerClient
trackerClient
=
new
TrackerClient
();
TrackerServer
trackerServer
=
trackerClient
.
getConnection
();
StorageClient1
storageClient1
=
new
StorageClient1
(
trackerServer
,
null
);
byte
[]
bytes
=
storageClient1
.
download_file1
(
remPath
);
trackerServer
.
close
();
return
bytes
;
}
@Override
public
void
fileRemove
(
String
remPath
)
throws
IOException
,
MyException
{
TrackerClient
trackerClient
=
new
TrackerClient
();
TrackerServer
trackerServer
=
trackerClient
.
getConnection
();
StorageClient1
storageClient1
=
new
StorageClient1
(
trackerServer
,
null
);
storageClient1
.
delete_file1
(
remPath
);
trackerServer
.
close
();
}
@Override
public
void
fileAppend
(
String
filePath
,
byte
[]
fileBuffer
)
throws
IOException
,
MyException
{
TrackerClient
trackerClient
=
new
TrackerClient
();
TrackerServer
trackerServer
=
trackerClient
.
getConnection
();
StorageClient1
storageClient1
=
new
StorageClient1
(
trackerServer
,
null
);
storageClient1
.
append_file1
(
filePath
,
fileBuffer
);
trackerServer
.
close
();
}
@Override
public
Map
<
String
,
String
>
getFileMate
(
String
filePath
)
throws
IOException
,
MyException
{
TrackerClient
trackerClient
=
new
TrackerClient
();
TrackerServer
trackerServer
=
trackerClient
.
getConnection
();
StorageClient1
storageClient1
=
new
StorageClient1
(
trackerServer
,
null
);
NameValuePair
[]
metadata1
=
storageClient1
.
get_metadata1
(
filePath
);
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>(
5
);
for
(
int
i
=
0
;
i
<
metadata1
.
length
;
i
++)
{
map
.
put
(
metadata1
[
i
].
getName
(),
metadata1
[
i
].
getValue
());
}
return
map
;
}
}
byit-myth-core/myth-executor-core/src/main/java/com/byit/executor/filesystem/FileSystem.java
0 → 100644
View file @
b8389a87
package
com
.
byit
.
executor
.
filesystem
;
import
org.csource.common.MyException
;
import
java.io.IOException
;
import
java.util.Map
;
/**
* 文件系统 所有类型的文件系统都必须继承这个文件系统接口
* @author huangfu
*/
public
interface
FileSystem
{
/**
* 文件上传接口
* @param fileBuffer 文件的字节流
* @param fileExtName 文件的扩展名称
* @param mateDaTA 文件的元信息
* @return
*/
String
uploadFile
(
byte
[]
fileBuffer
,
String
fileExtName
,
Map
<
String
,
String
>
mateDaTA
)
throws
IOException
,
MyException
;
/**
* 文件下载操作
* @param remPath 远程文件地址
* @return 文件流
*/
byte
[]
downloaderFile
(
String
remPath
)
throws
IOException
,
MyException
;
/**
* 文件删除
* @param remPath 远程地址
*/
void
fileRemove
(
String
remPath
)
throws
IOException
,
MyException
;
/**
* 数据追加
* @param filePath
* @param fileBuffer
*/
void
fileAppend
(
String
filePath
,
byte
[]
fileBuffer
)
throws
IOException
,
MyException
;
/**
* 查询文件原信息
* @param filePath
* @return
*/
Map
<
String
,
String
>
getFileMate
(
String
filePath
)
throws
IOException
,
MyException
;
}
byit-myth-core/myth-executor-core/src/main/resources/fdfs_client.conf
0 → 100644
View file @
b8389a87
connect_timeout
=
2
network_timeout
=
30
charset
=
UTF
-
8
http
.
tracker_http_port
=
8080
http
.
anti_steal_token
=
no
http
.
secret_key
=
FastDFS1234567890
tracker_server
=
10
.
0
.
120
.
2
:
22122
connection_pool
.
enabled
=
true
connection_pool
.
max_count_per_entry
=
500
connection_pool
.
max_idle_time
=
3600
connection_pool
.
max_wait_time_in_ms
=
1000
\ No newline at end of file
byit-myth-core/myth-executor-core/src/test/java/com/test/FastDFSTest.java
0 → 100644
View file @
b8389a87
package
com
.
test
;
import
com.byit.executor.conf.FileSystemContext
;
import
com.byit.executor.filesystem.FastDfsFileSystem
;
import
org.apache.commons.io.FileUtils
;
import
org.csource.common.MyException
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
FastDFSTest
{
private
FileSystemContext
fileSystemContext
;
@Before
public
void
init
(){
fileSystemContext
=
new
FileSystemContext
(
new
FastDfsFileSystem
());
}
@Test
public
void
testUpload
()
throws
IOException
,
MyException
{
byte
[]
bytes
=
FileUtils
.
readFileToByteArray
(
new
File
(
"E:\\image/20180101.log"
));
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>(
10
);
map
.
put
(
"filename"
,
"20180101.log"
);
//ddmp/M00/00/00/CgB4Al5GY5GAMGVaAAAHa9wlKKc755.log
System
.
out
.
println
(
fileSystemContext
.
uploadFile
(
bytes
,
"log"
,
map
));
}
@Test
public
void
downLoad
()
throws
IOException
,
MyException
{
String
filePath
=
"ddmp/M00/00/00/CgB4Al5GY5GAMGVaAAAHa9wlKKc755.log"
;
Map
<
String
,
String
>
fileMate
=
fileSystemContext
.
getFileMate
(
filePath
);
String
filename
=
fileMate
.
get
(
"filename"
);
byte
[]
bytes
=
fileSystemContext
.
downloaderFile
(
filePath
);
File
file
=
new
File
(
"E:\\image\\down/"
+
filename
);
if
(
file
.
exists
()){
file
.
delete
();
}
FileUtils
.
writeByteArrayToFile
(
file
,
bytes
);
}
@Test
public
void
appendTest
()
throws
IOException
,
MyException
{
String
filePath
=
"ddmp/M00/00/00/CgB4Al5GY5GAMGVaAAAHa9wlKKc755.log"
;
byte
[]
bytes
=
FileUtils
.
readFileToByteArray
(
new
File
(
"E:\\image/20180101.log"
));
fileSystemContext
.
fileAppend
(
filePath
,
bytes
);
}
}
pom.xml
View file @
b8389a87
...
...
@@ -67,12 +67,22 @@
<guava.version>
21.0
</guava.version>
<springfox-swagger-ui.version>
2.9.2
</springfox-swagger-ui.version>
<org-apache-commons.version>
1.3
</org-apache-commons.version>
<fastdfs-client-java-version>
1.27.0.0
</fastdfs-client-java-version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
net.oschina.zcx7878
</groupId>
<artifactId>
fastdfs-client-java
</artifactId>
<version>
${fastdfs-client-java-version}
</version>
</dependency>
<!-- 外部脚本执行器 -->
<dependency>
<groupId>
org.apache.commons
</groupId>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment