/**
* 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.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Arrays;
import org.csource.ClientGlobal;
import org.csource.common.Base64;
import org.csource.common.MyException;
import org.csource.common.NameValuePair;
/**
* 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 int send(OutputStream out) throws IOException
{
//将字节流拆分写入服务端,以便断点上传
int size = 256 * 1024;
while(this.length>0){
if(this.length >= size){
out.write(this.fileBuff, this.offset, size);
this.length -= size;
this.offset += size;
}else{
out.write(this.fileBuff, this.offset, this.length);
this.length =0;
this.offset += this.length;
}
}
return 0;
}*/
public byte[] getFileBuff() {
return fileBuff;
}
public void setFileBuff(byte[] fileBuff) {
this.fileBuff = fileBuff;
}
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
}
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, d
没有合适的资源?快使用搜索试试~ 我知道了~
fastdfs断点续传代码
共122个文件
class:54个
java:45个
bak:6个
5星 · 超过95%的资源 需积分: 1 440 下载量 70 浏览量
2015-06-24
08:46:02
上传
评论 11
收藏 1005KB ZIP 举报
温馨提示
通过封装fastdfs java client的代码实现断点续传功能,FileService.upload_file
资源推荐
资源详情
资源评论
收起资源包目录
fastdfs断点续传代码 (122个子文件)
StorageClient.java.bak 67KB
StorageClient.java.bak 67KB
FileService.java.bak 4KB
FileService.java.bak 4KB
UploadStream.java.bak 1KB
UploadStream.java.bak 1KB
StorageClient.class 35KB
TrackerClient.class 16KB
StructStorageStat.class 15KB
StorageClient1.class 13KB
ProtoCommon.class 12KB
Monitor.class 11KB
TestClient.class 11KB
TestAppender.class 10KB
TestAppender1.class 10KB
TestClient1.class 9KB
FileService.class 9KB
Base64.class 6KB
StorageClient1AppendFileTest.class 6KB
StorageClient1Test.class 6KB
StorageClientDownloadFileTest.class 5KB
ClientGlobal.class 5KB
StorageClient1DownloadFileTest.class 5KB
StorageClientAppendFileTest.class 5KB
SSHTester.class 4KB
IniFileReader.class 4KB
StructGroupStat.class 4KB
StorageClientTest.class 4KB
UploadResultInfo.class 3KB
TrackerGroup.class 3KB
Test.class 3KB
Test1.class 3KB
TestLoad$DownloadThread.class 3KB
TestLoad.class 2KB
TestLoad$Uploader.class 2KB
StructBase.class 2KB
TestLoad$Downloader.class 2KB
FileInfo.class 2KB
TestLoad$UploadThread.class 2KB
AppendUploadStream.class 2KB
UploadStream.class 2KB
ProtoStructDecoder.class 2KB
TrackerServer.class 2KB
StorageClient$UploadBuff.class 1KB
DownloadFileWriter.class 1KB
FileServiceTest.class 1KB
UploadLocalFileSender.class 1KB
ServerInfo.class 1KB
StorageServer.class 1KB
NameValuePair.class 970B
DownloadStream.class 902B
WatchThread.class 883B
TestLoad$DownloadFileDiscard.class 624B
StructBase$FieldInfo.class 583B
ProtoCommon$RecvPackageInfo.class 527B
ProtoCommon$RecvHeaderInfo.class 526B
RelationMap.class 487B
MyException.class 444B
UploadCallback.class 220B
DownloadCallback.class 158B
.classpath 725B
fdfs_client.conf 410B
fdfs_client.conf 408B
fdfs_client.conf 408B
log4j-1.2.8.jar 344KB
ganymed-ssh2-build210.jar 239KB
common-toolkit-0.0.4-20130311.131623-1.jar 109KB
fastdfs_client.jar 67KB
commons-logging-1.1.jar 52KB
taokeeper-common-1.1.2.jar 41KB
StorageClient.java 69KB
StructStorageStat.java 34KB
StorageClient1.java 25KB
TrackerClient.java 24KB
ProtoCommon.java 17KB
Base64.java 16KB
TestClient.java 12KB
TestAppender.java 12KB
FileService.java 11KB
TestAppender1.java 11KB
Monitor.java 11KB
TestClient1.java 10KB
StructGroupStat.java 7KB
TestLoad.java 7KB
StorageClient1AppendFileTest.java 6KB
ClientGlobal.java 6KB
StorageClient1Test.java 5KB
StorageClientAppendFileTest.java 4KB
StorageClientDownloadFileTest.java 4KB
IniFileReader.java 4KB
StorageClient1DownloadFileTest.java 4KB
TrackerGroup.java 3KB
UploadResultInfo.java 3KB
SSHTester.java 3KB
FileInfo.java 3KB
StorageClientTest.java 2KB
Test.java 2KB
StructBase.java 2KB
AppendUploadStream.java 2KB
UploadStream.java 2KB
共 122 条
- 1
- 2
mazi2004
- 粉丝: 24
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- delphi实现DBGrid全选和反选功能
- 25C11F41-2B2A-4D1A-AAA8-7C654526B129.pdf
- Android Studio Jellyfish(android-studio-2023.3.1.18-cros.deb)
- MVC+EF框架+EasyUI实现权限管理源码程序
- python第66-75天,Day66-75.rar
- python后端服务project-of-tornado.rar
- python测验,hello-tornado.rar
- 基于SpringBoot+Vue3快速开发平台、自研工作流引擎源码设计.zip
- docker安装部署全流程
- 基于树莓派的人脸识别系统python源码+项目部署说明+超详细代码注释.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页