日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

fastdfs java client_fastdfs-client-java操作fastdfs5.0.4

發(fā)布時間:2023/11/27 生活经验 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 fastdfs java client_fastdfs-client-java操作fastdfs5.0.4 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、在外鏈網(wǎng)址已屏蔽?下載客戶端,解壓后并執(zhí)行ant命令,在E:\tools\libs\fastdfs\fastdfs-client-java-master\src\build下會生成fastdfs_client.jar如圖示

二、mvn安裝fastdfs_client.jar,在cmd中執(zhí)行命令

mvn install:install-file -DgroupId=org.csource -DartifactId=fastdfs-client-java -Dversion=5.0.4 -Dpackaging=jar -Dfile=D:\fastdfs_client.jar

三、在eclipse中新建maven項目fastdfs-demo,在pom.xml中加入依賴如下

xsi:schemaLocation="外鏈網(wǎng)址已屏蔽;外鏈網(wǎng)址已屏蔽">

4.0.0

com.leech

fastdfs-demo

0.0.1-SNAPSHOT

jar

fastdfs-demo

外鏈網(wǎng)址已屏蔽;/url>

UTF-8

junit

junit

4.11

test

org.csource

fastdfs-client-java

5.0.4

commons-io

commons-io

2.4

在src/main/resources中新建fdfs_client.conf文件,內(nèi)容如下

connect_timeout = 2

network_timeout = 30

charset = UTF-8

http.tracker_http_port = 80

http.anti_steal_token = no

http.secret_key = FastDFS1234567890

tracker_server = 192.168.17.112:22122

#tracker_server = 192.168.0.119:22122

在src/main/java中創(chuàng)建TestFastDfs.java如下

package?com.leech.fastdfs.demo;

import?java.io.FileNotFoundException;

import?java.io.FileOutputStream;

import?java.io.IOException;

import?java.util.UUID;

import?mons.io.IOUtils;

import?mon.MyException;

import?mon.NameValuePair;

import?org.csource.fastdfs.ClientGlobal;

import?org.csource.fastdfs.FileInfo;

import?org.csource.fastdfs.StorageClient;

import?org.csource.fastdfs.StorageServer;

import?org.csource.fastdfs.TrackerClient;

import?org.csource.fastdfs.TrackerServer;

import?org.junit.After;

import?org.junit.Before;

import?org.junit.Test;

public?class?TestFastDfs?{

public?String?conf_filename?=?"D:\\stsworkspace\\fastdfs-demo\\src\\main\\resources\\fdfs_client.conf";

//public?String?local_filename?=?"D:\\stsworkspace\\fastdfs-demo\\src\\main\\resources\\fdfs_client.conf";

public?String?local_filename?=?"D:\\stsworkspace\\fastdfs-demo\\src\\main\\resources\\sprites.png";

@Before

public?void?setUp()?throws?Exception?{

}

@After

public?void?tearDown()?throws?Exception?{

}

@Test

public?void?testUpload()?{

try?{

ClientGlobal.init(conf_filename);

TrackerClient?tracker?=?new?TrackerClient();

TrackerServer?trackerServer?=?tracker.getConnection();

StorageServer?storageServer?=?null;

StorageClient?storageClient?=?new?StorageClient(trackerServer,?storageServer);

//??????????NameValuePair?nvp?=?new?NameValuePair("age",?"18");

NameValuePair?nvp?[]?=?new?NameValuePair[]{

new?NameValuePair("age",?"18"),

new?NameValuePair("sex",?"male")

};

String?fileIds[]?=?storageClient.upload_file(local_filename,?"png",?nvp);

System.out.println(fileIds.length);

System.out.println("組名:"?+?fileIds[0]);

System.out.println("路徑:?"?+?fileIds[1]);

}?catch?(FileNotFoundException?e)?{

e.printStackTrace();

}?catch?(IOException?e)?{

e.printStackTrace();

}?catch?(MyException?e)?{

e.printStackTrace();

}

}

@Test

public?void?testDownload()?{

try?{

ClientGlobal.init(conf_filename);

TrackerClient?tracker?=?new?TrackerClient();

TrackerServer?trackerServer?=?tracker.getConnection();

StorageServer?storageServer?=?null;

StorageClient?storageClient?=?new?StorageClient(trackerServer,?storageServer);

byte[]?b?=?storageClient.download_file("group1",?"M00/00/00/wKgRcFV_08OAK_KCAAAA5fm_sy874.conf");

System.out.println(b);

IOUtils.write(b,?new?FileOutputStream("D:/"+UUID.randomUUID().toString()+".conf"));

}?catch?(Exception?e)?{

e.printStackTrace();

}

}

@Test

public?void?testGetFileInfo(){

try?{

ClientGlobal.init(conf_filename);

TrackerClient?tracker?=?new?TrackerClient();

TrackerServer?trackerServer?=?tracker.getConnection();

StorageServer?storageServer?=?null;

StorageClient?storageClient?=?new?StorageClient(trackerServer,?storageServer);

FileInfo?fi?=?storageClient.get_file_info("group1",?"M00/00/00/wKgRcFV_08OAK_KCAAAA5fm_sy874.conf");

System.out.println(fi.getSourceIpAddr());

System.out.println(fi.getFileSize());

System.out.println(fi.getCreateTimestamp());

System.out.println(fi.getCrc32());

}?catch?(Exception?e)?{

e.printStackTrace();

}

}

@Test

public?void?testGetFileMate(){

try?{

ClientGlobal.init(conf_filename);

TrackerClient?tracker?=?new?TrackerClient();

TrackerServer?trackerServer?=?tracker.getConnection();

StorageServer?storageServer?=?null;

StorageClient?storageClient?=?new?StorageClient(trackerServer,

storageServer);

NameValuePair?nvps?[]?=?storageClient.get_metadata("group1",?"M00/00/00/wKgRcFV_08OAK_KCAAAA5fm_sy874.conf");

for(NameValuePair?nvp?:?nvps){

System.out.println(nvp.getName()?+?":"?+?nvp.getValue());

}

}?catch?(Exception?e)?{

e.printStackTrace();

}

}

@Test

public?void?testDelete(){

try?{

ClientGlobal.init(conf_filename);

TrackerClient?tracker?=?new?TrackerClient();

TrackerServer?trackerServer?=?tracker.getConnection();

StorageServer?storageServer?=?null;

StorageClient?storageClient?=?new?StorageClient(trackerServer,

storageServer);

int?i?=?storageClient.delete_file("group1",?"M00/00/00/wKgRcFV_08OAK_KCAAAA5fm_sy874.conf");

System.out.println(?i==0???"刪除成功"?:?"刪除失敗:"+i);

}?catch?(Exception?e)?{

e.printStackTrace();

}

}

}

總結(jié)

以上是生活随笔為你收集整理的fastdfs java client_fastdfs-client-java操作fastdfs5.0.4的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。