/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
* General Public License (LGPL).
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
*/
package org.csource.fastdfs;
import java.io.IOException;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.File;
import java.util.Arrays;
import java.net.Socket;
import org.csource.common.MyException;
import org.csource.common.NameValuePair;
import org.csource.common.Base64;
/**
* Storage client for 2 fields file id: group name and filename
* @author Happy Fish / YuQing
* @version Version 1.24
*/
public class StorageClient
{
/**
* Upload file by file buff
* @author Happy Fish / YuQing
* @version Version 1.12
*/
public static class UploadBuff implements UploadCallback
{
private byte[] fileBuff;
private int offset;
private int length;
/**
* constructor
* @param fileBuff the file buff for uploading
*/
public UploadBuff(byte[] fileBuff, int offset, int length)
{
super();
this.fileBuff = fileBuff;
this.offset = offset;
this.length = length;
}
/**
* send file content callback function, be called only once when the file uploaded
* @param out output stream for writing file content
* @return 0 success, return none zero(errno) if fail
*/
public int send(OutputStream out) throws IOException
{
out.write(this.fileBuff, this.offset, this.length);
return 0;
}
}
public final static Base64 base64 = new Base64('-', '_', '.', 0);
protected TrackerServer trackerServer;
protected StorageServer storageServer;
protected byte errno;
/**
* constructor using global settings in class ClientGlobal
*/
public StorageClient()
{
this.trackerServer = null;
this.storageServer = null;
}
/**
* constructor with tracker server and storage server
* @param trackerServer the tracker server, can be null
* @param storageServer the storage server, can be null
*/
public StorageClient(TrackerServer trackerServer, StorageServer storageServer)
{
this.trackerServer = trackerServer;
this.storageServer = storageServer;
}
/**
* get the error code of last call
* @return the error code of last call
*/
public byte getErrorCode()
{
return this.errno;
}
/**
* upload file to storage server (by file name)
* @param local_filename local filename to upload
* @param file_ext_name file ext name, do not include dot(.), null to extract ext name from the local filename
* @param meta_list meta info array
* @return 2 elements string array if success:<br>
* <ul><li>results[0]: the group name to store the file </li></ul>
* <ul><li>results[1]: the new created filename</li></ul>
* return null if fail
*/
public String[] upload_file(String local_filename, String file_ext_name,
NameValuePair[] meta_list) throws IOException, MyException
{
final String group_name = null;
return this.upload_file(group_name, local_filename, file_ext_name, meta_list);
}
/**
* upload file to storage server (by file name)
* @param group_name the group name to upload file to, can be empty
* @param local_filename local filename to upload
* @param file_ext_name file ext name, do not include dot(.), null to extract ext name from the local filename
* @param meta_list meta info array
* @return 2 elements string array if success:<br>
* <ul><li>results[0]: the group name to store the file </li></ul>
* <ul><li>results[1]: the new created filename</li></ul>
* return null if fail
*/
protected String[] upload_file(String group_name, String local_filename, String file_ext_name,
NameValuePair[] meta_list) throws IOException, MyException
{
final byte cmd = ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_FILE;
return this.upload_file(cmd, group_name, local_filename, file_ext_name, meta_list);
}
/**
* upload file to storage server (by file name)
* @param cmd the command
* @param group_name the group name to upload file to, can be empty
* @param local_filename local filename to upload
* @param file_ext_name file ext name, do not include dot(.), null to extract ext name from the local filename
* @param meta_list meta info array
* @return 2 elements string array if success:<br>
* <ul><li>results[0]: the group name to store the file </li></ul>
* <ul><li>results[1]: the new created filename</li></ul>
* return null if fail
*/
protected String[] upload_file(byte cmd, String group_name, String local_filename, String file_ext_name,
NameValuePair[] meta_list) throws IOException, MyException
{
File f = new File(local_filename);
FileInputStream fis = new FileInputStream(f);
if (file_ext_name == null)
{
int nPos = local_filename.lastIndexOf('.');
if (nPos > 0 && local_filename.length() - nPos <= ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1)
{
file_ext_name = local_filename.substring(nPos+1);
}
}
try
{
return this.do_upload_file(cmd, group_name, null, null, file_ext_name,
f.length(), new UploadStream(fis, f.length()), meta_list);
}
finally
{
fis.close();
}
}
/**
* upload file to storage server (by file buff)
* @param file_buff file content/buff
* @param offset start offset of the buff
* @param length the length of buff to upload
* @param file_ext_name file ext name, do not include dot(.)
* @param meta_list meta info array
* @return 2 elements string array if success:<br>
* <ul><li>results[0]: the group name to store the file</li></ul>
* <ul><li>results[1]: the new created filename</li></ul>
* return null if fail
*/
public String[] upload_file(byte[] file_buff, int offset, int length, String file_ext_name,
NameValuePair[] meta_list) throws IOException, MyException
{
final String group_name = null;
return this.upload_file(group_name, file_buff, offset, length, file_ext_name, meta_list);
}
/**
* upload file to storage server (by file buff)
* @param group_name the group name to upload file to, can be empty
* @param file_buff file content/buff
* @param offset start offset of the buff
* @param length the length of buff to upload
* @param file_ext_name file ext name, do not include dot(.)
* @param meta_list meta info array
* @return 2 elements string array if success:<br>
* <ul><li>results[0]: the group name to store the file</li></ul>
* <ul><li>results[1]: the new created filename</li></ul>
* return null if fail
*/
public String[] upload_file(String group_name, byte[] file_buff, int offset, int length,
String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException
{
return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_FILE, group_name, null, null, file_ext_name,
length, new UploadBuff(file_buff, offset, length), meta_list);
}
/**
* upload file to storage server (by file buff)
* @param file_buff file content/buff
* @param file_ext_name file ext name, do not include dot(.)
* @param meta_list meta info array
* @return 2 elements string array if success:<br>
* <ul><li>results[0]: the group name to store the file</li></ul>
* <ul><li>results[1]: the new created filename</li></ul>
* return null if fail
*/
public String[] upload_file(byte[] file_buff, String file_ext_name,
NameValuePair[] meta_list) throws IOException, MyException
{
final String group_name = null;
return this.upload_file(group_name, file_buff, 0, file_buff.length, file_ext_name, meta_list);
}
/**
* upload file to storage server (by file buff)
* @param group_name the group name to upload file to, can be empty
* @param file_buff file content/buff
* @param file_ext_name file ext name, do not include dot(.)
* @param meta_list meta info array
* @return 2 elements string ar
没有合适的资源?快使用搜索试试~ 我知道了~
淘淘商城图片服务器FastDFS需要的maven路径
共86个文件
class:41个
java:32个
conf:2个
需积分: 10 7 下载量 28 浏览量
2018-01-08
14:24:38
上传
评论
收藏 245KB ZIP 举报
温馨提示
亲测可用的淘淘商城图片服务器FastDFS需要的maven路径。具体使用方式请看:http://blog.csdn.net/yerenyuan_pku/article/details/72804018
资源推荐
资源详情
资源评论
收起资源包目录
fastdfs_client.zip (86个子文件)
fastdfs_client
pom.xml 361B
target
maven-status
maven-compiler-plugin
compile
default-compile
inputFiles.lst 3KB
classes
META-INF
maven
fastdfs_client
fastdfs_client
pom.xml 361B
pom.properties 239B
MANIFEST.MF 114B
org
csource
fastdfs
DownloadStream.class 872B
ProtoCommon$RecvHeaderInfo.class 526B
ClientGlobal.class 4KB
test
TestLoad$UploadThread.class 2KB
TestClient.class 10KB
Test.class 3KB
TestLoad$DownloadThread.class 2KB
TestLoad.class 2KB
Monitor.class 11KB
TestLoad$Downloader.class 2KB
TestLoad$Uploader.class 2KB
TestLoad$DownloadFileDiscard.class 624B
TestClient1.class 9KB
TestAppender.class 10KB
TestAppender1.class 9KB
UploadLocalFileSender.class 1KB
DownloadFileWriter.class 1KB
Test1.class 2KB
StorageClient$UploadBuff.class 860B
TrackerServer.class 1KB
StructBase.class 2KB
UploadCallback.class 220B
TrackerClient.class 14KB
ProtoCommon.class 11KB
ProtoCommon$RecvPackageInfo.class 527B
StorageClient1.class 12KB
ProtoStructDecoder.class 2KB
StructStorageStat.class 15KB
DownloadCallback.class 158B
StorageServer.class 1KB
StructGroupStat.class 4KB
StructBase$FieldInfo.class 583B
StorageClient.class 28KB
FileInfo.class 2KB
TrackerGroup.class 3KB
UploadStream.class 1KB
ServerInfo.class 1KB
common
MyException.class 444B
IniFileReader.class 3KB
NameValuePair.class 970B
Base64.class 6KB
fdfs_client.conf 229B
maven-archiver
pom.properties 117B
fastdfs_client-1.25.jar 89KB
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.jdt.core.prefs 243B
src
main
resources
fdfs_client.conf 229B
java
org
csource
fastdfs
StorageClient1.java 25KB
ProtoStructDecoder.java 1KB
ProtoCommon.java 17KB
UploadCallback.java 737B
DownloadStream.java 1KB
StructBase.java 2KB
DownloadCallback.java 784B
ClientGlobal.java 5KB
test
TestAppender.java 11KB
DownloadFileWriter.java 1KB
TestAppender1.java 11KB
TestClient.java 12KB
UploadLocalFileSender.java 1KB
Monitor.java 10KB
TestClient1.java 10KB
Test1.java 1KB
Test.java 2KB
TestLoad.java 7KB
TrackerGroup.java 3KB
StorageServer.java 1KB
FileInfo.java 3KB
UploadStream.java 1KB
StructStorageStat.java 34KB
TrackerServer.java 2KB
ServerInfo.java 1KB
StorageClient.java 64KB
TrackerClient.java 24KB
StructGroupStat.java 7KB
common
MyException.java 502B
NameValuePair.java 972B
Base64.java 16KB
IniFileReader.java 4KB
.project 566B
.classpath 1KB
共 86 条
- 1
资源评论
-Hermes-
- 粉丝: 164
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功