Code Monkey home page Code Monkey logo

fastdfs-client's Introduction

fastdfs-client

fastdfs-client is a FastDFS java client based on Netty 4.

前置条件

  • Java 8 required.

maven

<dependency>
	<groupId>cn.strong</groupId>
	<artifactId>fastdfs-client</artifactId>
	<version>3.0.0</version>
</dependency>

使用说明

程序的主要入口为 SimpleFastdfsClient/FastdfsClient

FastdfsClient 后端使用 FastdfsTemplate 做实际的网络通信工作, 以及 Seed<InetSocketAddress> 来选取 tracker URL。 FastdfsTemplate 具有生命周期,它维护了一个通道连接池以及 IO 线程组等资源。

SimpleFastdfsClientFastdfsClient 做了一层封装,采用同步方式,且存储路径也使用字符串全路径。

Settings settings = new Settings();
FastdfsTemplate template = new FastdfsTemplate(settings);
try {
  SimpleFastdfsClient client = new SimpleFastdfsClient(template, TrackerAddress.createSeed("192.168.20.68:22122"));
  // do sth. with SimpleFastdfsClient
} finally {
  IOUtils.close(template);
}

得到 SimpleFastdfsClient 实例以后即可通过相应 API 进行上传下载等操作。

// 上传
byte[] bytes = "Hello Fastdfs".getBytes(UTF_8);
String path = client.upload(bytes, "txt");
System.out.println("path: " + path);

// 下载
String path = "group1/M00/15/93/wKgURFfGi4-AeRRwAAAADSghvvI390.txt";
byte[] bytes = client.download(path);
String data = new String(bytes, UTF_8);
System.out.println("downloaded: " + data);

具体 FastdfsClientSimpleFastdfsClient 的使用详见 API 及对应的集成测试用例。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.