用户综合分析系统:Java业务板块---FastDFS文件上传

分布式文件系统

概述

分布式⽂件系统(Distributed File System)是指⽂件系统管理的物理存储资源不⼀定直接连接在本地节点上,⽽是通过计算机⽹络与节点相连。

计算机通过⽂件系统管理、存储数据,⽽信息爆炸时代中⼈们可以获取的数据成指数倍的增⻓,单纯通过增加硬盘个数来扩展计算机⽂件系统的存储容量的⽅式,在容量⼤⼩、容量增⻓速度、数据备份、数据安全等⽅⾯的表现都差强⼈意。分布式⽂件系统可以有效解决数据的存储和管理难题:将固定于某个地点的某个⽂件系统,扩展到任意多个地点/多个⽂件系统,众多的节点组成⼀个⽂件系统⽹络。每个节点可以分布在不同的地点,通过⽹络进⾏节点间的通信和数据传输。⼈们在使⽤分布式⽂件系统时,⽆需关⼼数据是存储在哪个节点上、或者是从哪个节点从获取的,只需要像使⽤本地⽂件系统⼀样管理和存储⽂件系统中的数据。

⽂件系统最初设计时,仅仅是为局域⽹内的本地数据服务的。⽽分布式⽂件系统将服务范围扩展到了整个⽹络。不仅改变了数据的存储和管理⽅式,也拥有了本地⽂件系统所⽆法具备的数据备份、数据安全等优点。判断⼀个分布式⽂件系统是否优秀,取决于以下三个因素:

  • 数据的存储⽅式
    例如有1000万个数据⽂件,可以在⼀个节点存储全部数据⽂件,在其他N个节点上每个节点存储1000/N万个数据⽂件作为备份;或者平均分配到N个节点上存储,每个节点上存储1000/N万个数据⽂件。⽆论采取何种存储⽅式,⽬的都是为了保证数据的存储安全和⽅便获取。
  • 数据的读取速率
    包括响应⽤户读取数据⽂件的请求、定位数据⽂件所在的节点、读取实际硬盘中数据⽂件的时间、不同节点间的数据传输时间以及⼀部分处理器的处理时间等。各种因素决定了分布式⽂件系统的⽤户体验。即分布式⽂件系统中数据的读取速率不能与本地⽂件系统中数据的读取速率相差太⼤,否则在本地⽂件系统中打开⼀个⽂件需要2秒,⽽在分布式⽂件系统中各种因素的影响下⽤时超过10秒,就会严重影响⽤户的使⽤体验。
  • 数据的安全机制
    由于数据分散在各个节点中,必须要采取冗余、备份、镜像等⽅式保证节点出现故障的情况下,能够进⾏数据的恢复,确保数据安全。
文件系统分类
  • 块存储:
    MongoDB数据库中的GridFS、Hadoop中的HDFS,这些系统在存储⽂件的的时候会尝试先将⽂件打碎存储(拆分成Data Block)。这样存储的优点可以存储超⼤型⽂件,更加⾼效的利⽤磁盘资源。但是需要额外存储⽂件碎⽚的元数据信息。

在块存储中HDFS存储的块128MB,但是在MongoDB中默认Chunk 255 KB,虽然都⽀持块存储但是应⽤场景有很⼤差异。HDFS适用于超⼤⽂本⽇志⽂件存储。但是MongoDB适合存储超⼤的流媒体⽂件例如操⼤的⾳频和视频,可以实现流媒体数据流的区间加载。

  • ⽂件存储:GlusterFS、NFS、FastDFS等都是基于⽂件单位存储,这种存储并不会将⽂件系统打碎。⽽是⽂件存储到系统中的某⼀台服务器中。这样存储的优点可以应对⼀些⼩⽂件系统,系统维护简单,⽆需存储⽂件的元数据,系统设计和维护成本低。
FastDFS
特点

FastDFS 是⼀款开源的轻量级分布式⽂件系统如下特点:

  • L纯粹C语⾔实现,⽀持Linux、FreeBSD等unix系统。
  • 类似GoogleFS/HDFS,但是不是通⽤的⽂件系统,只能通过专有的API访问,⽬前提供了C、Java和PHPAPI 互联⽹量身定做,最求⾼性能,⾼扩展。
  • FastDFS不仅仅可以存储⽂件,还可以存储⽂件的元数据信息(可选)。
架构

整个FastDFS架构中有Client、Tracker和Storage服务。其中Client⽤于提交⽂件给FastDFS集群。Storage 服务负责实际数据的存储,Tracker服务负责监控和调度Storage服务,起到负载均衡器的作⽤。

在这里插入图片描述
如果Storage的中 是⼀样的也就意味着这些服务彼此数据相互备份,实现数据的冗余备份。不同 存储整个集群中的部分⽂件,类似于传统单机⽂件系统的的分区概念(C盘、D盘、…)Tracker Server 主要做⼯作调度,在访问上起负载均衡的作⽤。在内存中记录集群中group/ 和Storage server的状态信息,是连接Client和Storage Server的枢纽。因为相关信息存储在内存中,所以Tracker Server性能⾮常⾼,⼀个较⼤的集群(上百个group/ )中3台就够了。

StorageServer :存储服务器,⽂件和⽂件属性信息(meta数据)都存储在服务器的磁盘上。

上传、下载机制

在这里插入图片描述

  • Storage Server会定期的向Tracker服务器汇报⾃身状态信息,例如健康状态和存储容量。
  • Client连接Tracker Server发送⽂件请求。
  • Tracker Server根据注册的Storage Server的信息返回⼀台可⽤的Storage Server的调⽤信息。
  • Client拿到信息后直接连接对应的Storage Server进⾏点到点的⽂件上传(附加元数据-可
    选)。
  • Storage Server收到⽂件请求后会根据⾃⼰位置信息⽣成File_ID信息,并且将File_ID和⽤户携带的元数据信息进⾏关联,然后将File_ID返回给Client。
  • 返回的File_ID⽂件服务器并不会存储,需要Client端保留在外围数据库中,以后Client端可以
    通过File_ID下载对应的⽂件或者元数据。

在这里插入图片描述

  • Storage Server会定期的向Tracker服务器汇报⾃身状态信息,例如健康状态和存储容量。
  • Client连接Tracker Server携带File_ID参数发送⽂件下载请求。
  • Tracker Server根据注册的Storage Server的信息返回⼀台可⽤的Storage Server的调⽤信息(主从服务器)。
  • Client拿到信息后直接连接对应的Storage Server进⾏点到点的⽂件下载(读取元数据)。
  • Storage Server收到⽂件请求后解析File_ID信息,读取本地的⽂件流,将数据写会Client端。

File_ID组成
File_ID是由Storage Server⽣成并返回给Client端。File_ID包含了组/ 卷 和⽂件路径。Storage Server可以直接根据该⽂件名定位到该⽂件。
在这里插入图片描述

FastDFS集群搭建

资源下载安装

进⼊ https://github.com/happyfish100 ⽹站下载FastDFS相关资源。建议使⽤⼩编给⼤家处理过的安装包。

[root@CentOSX ~]# yum install -y gcc-c++
[root@CentOSX ~]# tar -zxf V1.0.35.tar.gz
[root@CentOSX ~]# cd libfastcommon-1.0.35
[root@CentOSX libfastcommon-1.0.35]# ./make.sh
[root@CentOSX libfastcommon-1.0.35]# ./make.sh install
[root@CentOSX ~]# yum install -y perl-devel
[root@CentOSX ~]# tar -zxf fastdfs-5.11.tar.gz
[root@CentOSX ~]# cd fastdfs-5.11
[root@CentOSX fastdfs-5.11]# ./make.sh
[root@CentOSX fastdfs-5.11]# ./make.sh install

提示:当软件安装结束后,默认FastDFS启动所需的配置⽂件放置在/etc/fdfs⽬录下。

[root@CentOSX ~]# yum install -y tree
[root@CentOSX ~]# tree /etc/fdfs/
/etc/fdfs/
!"" client.conf.sample
!"" storage.conf.sample
!"" storage_ids.conf.sample
#"" tracker.conf.sample
0 directories, 4 files

# 可运⾏脚本
[root@CentOSX ~]# ls -l /etc/init.d/fdfs_*
-rwxr-xr-x. 1 root root 961 Jun 30 20:22 /etc/init.d/fdfs_storaged
-rwxr-xr-x. 1 root root 963 Jun 30 20:22 /etc/init.d/fdfs_trackerd
# 执⾏程序
[root@CentOSX ~]# whereis fdfs_storaged fdfs_trackerd
fdfs_storaged: /usr/bin/fdfs_storaged
fdfs_trackerd: /usr/bin/fdfs_trackerd

配置服务

  • 创建fdfs运⾏所需的数据⽬录
[root@CentOSX ~]# mkdir -p /data/fdfs/{tracker,storage/store01,storage/store02}
[root@CentOSX ~]# tree /data/
/data/
#"" fdfs
 !"" storage
 $ #"" store01
 | #"" store02
 #"" tracker
  • 创建启动所需的配置⽂件
[root@CentOSX ~]# cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
[root@CentOSX ~]# cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
[root@CentOSX ~]# cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
[root@CentOSX ~]# tree /etc/fdfs/
/etc/fdfs/
!"" client.conf
!"" client.conf.sample
!"" storage.conf
!"" storage.conf.sample
!"" storage_ids.conf.sample
!"" tracker.conf
#"" tracker.conf.sample
  • 配置Tracker Server
[root@CentOSX ~]# vi /etc/fdfs/tracker.conf
base_path=/data/fdfs/tracker
  • 配置Storage Server
[root@CentOSX ~]# vi /etc/fdfs/storage.conf
group_name=group`[1,2,3]`
base_path=/data/fdfs/storage
store_path_count=2
store_path0=/data/fdfs/storage/store01
store_path1=/data/fdfs/storage/store02
tracker_server=CentOSA:22122
tracker_server=CentOSB:22122
tracker_server=CentOSC:22122
  • 修改Client端
[root@CentOSX ~]# vi /etc/fdfs/client.conf
base_path=/tmp
tracker_server=CentOSA:22122
tracker_server=CentOSB:22122
tracker_server=CentOSC:22122

启动服务器

[root@CentOSX ~]# /etc/init.d/fdfs_trackerd start|stop|restart
Starting FastDFS tracker server:
[root@CentOSX ~]# /etc/init.d/fdfs_storaged start|stop|restart
Starting FastDFS storage server:
[root@CentOSX ~]# ps -aux | grep fdfs
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 78950 0.0 0.1 144784 2040 ? Sl 21:06 0:00
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root 79000 13.0 3.2 83520 67144 ? Sl 21:06 0:06
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
root 79324 0.0 0.0 103320 884 pts/0 S+ 21:07 0:00 grep fdfs
[root@CentOSX ~]#
FastDFS Shell-测试
  • 上传文件
[root@CentOSX ~]# fdfs_upload_file /etc/fdfs/client.conf install.log
group1/M00/00/01/wKikgV0YtQ2AfmozAAAixZ60QfI792.log
  • 下载
[root@CentOSX ~]# fdfs_download_file /etc/fdfs/client.conf
group1/M00/00/01/wKikgV0YtQ2AfmozAAAixZ60QfI792.log
  • 信息
[root@CentOSX ~]# fdfs_file_info /etc/fdfs/client.conf
group1/M00/00/01/wKikgV0YtQ2AfmozAAAixZ60QfI792.log
source storage id: 0
source ip address: 192.168.164.129
file create timestamp: 2019-06-30 21:11:41
file size: 8901
file crc32: 2662613490 (0x9EB441F2)
  • 删除文件
[root@CentOSX ~]# fdfs_delete_file /etc/fdfs/client.conf
group1/M00/00/01/wKikgV0YtQ2AfmozAAAixZ60QfI792.log
  • 文件追加
[root@CentOSX ~]# clear
[root@CentOSX ~]# echo "hello" > 1.txt
[root@CentOSX ~]# echo "word" > 2.txt
[root@CentOSX ~]# fdfs_upload_appender /etc/fdfs/client.conf /root/1.txt
group2/M00/00/00/wKikgl0qX4KEep_PAAAAAIpZx2Y751.txt
[root@CentOSX ~]# fdfs_append_file /etc/fdfs/client.conf
group2/M00/00/00/wKikgl0qX4KEep_PAAAAAIpZx2Y751.txt 2.txt
[root@CentOSX ~]# fdfs_download_file /etc/fdfs/client.conf
group2/M00/00/00/wKikgl0qX4KEep_PAAAAAIpZx2Y751.txt
[root@CentOSX ~]# cat wKikgl0qX4KEep_PAAAAAIpZx2Y751.txt
hello
word
  • 监视状态
[root@CentOSX ~]# fdfs_monitor /etc/fdfs/client.conf
  • 文件校验和
[root@CentOSX ~]# fdfs_crc32 /etc/fdfs/client.conf
group2/M00/00/00/wKikgl0qX4KEep_PAAAAAIpZx2Y751.txt
2911662598
Nginx集成FastDFS

在这里插入图片描述
FastDFS的HTTP服务较为简单,无法提供负载均衡等高性能的服务,所以FastDFS的开发者——淘宝的架构师余庆同学,为我们提供了Nginx上使用的FastDFS模块(也可以叫FastDFS的Nginx模块)。其使用非常简单。

FastDFS通过Tracker服务器,将文件放在Storage服务器存储,但是同组之间的服务器需要复制文件,有延迟的问题.假设Tracker服务器将文件上传到了192.168.1.80,文件ID已经返回客户端,这时,后台会将这个文件复制到192.168.1.30,如果复制没有完成,客户端就用这个ID在192.168.1.30取文件,肯定会出现错误。这个fastdfs-nginx-module可以重定向连接到源服务器取文件,避免客户端由于复制延迟的问题,出现错误。

其用意在于利用web服务器直接对本机storage数据文件提供http服务,以提高文件下载的性能。

Nginx配置安装
  • 下载fastdfs-nginx-module(不建议使⽤github上,因为编译有问题)
[root@CentOSX ~]# tar -zxf fastdfs-nginx-module.tar.gz
[root@CentOSX ~]# yum install -y pcre-devel
[root@CentOSX ~]# yum install -y openssl-devel
[root@CentOSX ~]# wget http://nginx.org/download/nginx-1.11.1.tar.gz
[root@CentOSX ~]# tar -zxf nginx-1.11.1.tar.gz
[root@CentOSX nginx-1.11.1]# ./configure --prefix=/usr/local/nginx-1.11.1/ --addmodule=/root/fastdfs-nginx-module/src
[root@CentOSX nginx-1.11.1]# make
[root@CentOSX nginx-1.11.1]# make install
  • 拷⻉配置
[root@CentOSX ~]# cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
[root@CentOSX ~]# cd /root/fastdfs-5.11/conf/
[root@CentOSX conf]# cp http.conf mime.types anti-steal.jpg /etc/fdfs/
  • 配置nginx.conf
[root@CentOSA ~]# vi /usr/local/nginx-1.11.1/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;

#access_log logs/host.access.log main;
 //添加以下两个location即可
 location ~ /group[0-9]+/M00 {
 root /data/fdfs/storage/store01;
 ngx_fastdfs_module;
 }
 location ~ /group[0-9]+/M01 {
 root /data/fdfs/storage/store02;
 ngx_fastdfs_module;
 }
 
 location / {
 root html;
 index index.html index.htm;
 }
  • 修改mod_fastdfs.conf
[root@CentOSX ~]# vi /etc/fdfs/mod_fastdfs.conf
tracker_server=CentOSA:22122
tracker_server=CentOSB:22122
tracker_server=CentOSC:22122
group_name=group`[1,2,3]`
url_have_group_name = true
store_path_count=2
store_path0=/data/fdfs/storage/store01
store_path1=/data/fdfs/storage/store02
  • 启动nginx
[root@CentOSX ~]# cd /usr/local/nginx-1.11.1/
[root@CentOSX nginx-1.11.1]# ./sbin/nginx -t
ngx_http_fastdfs_set pid=116305
ngx_http_fastdfs_set pid=116305
nginx: the configuration file /usr/local/nginx-1.11.1//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.11.1//conf/nginx.conf test is successful
[root@CentOSX nginx-1.11.1]# ./sbin/nginx
  • 测试下载
[root@CentOSA ~]# fdfs_upload_file /etc/fdfs/client.conf install.log
group2/M01/00/00/wKikgl0p_4-AIqGJAAAixZ60QfI693.log
  • 随便访问⼀个nginx服务查看效果
http://CentOS[A|B|C]/group2/M01/00/00/wKikgl0p_4-AIqGJAAAixZ60QfI693.log?
filename=install.log

⽤户在请求的时候,可以选择性添加⽂件名,⽤于修改下载的⽂件名。

FastDHT文件去重

FastDFS除了提供了与nginx的集成,已提供了去重的⽂件解决⽅案。该解决⽅案FastDFS的作者余庆也 在github上以FastDHT分⽀贡献出来了。
在这里插入图片描述
在这里插入图片描述

安装
  • 安装BerkeleyDB 下载db-4.7.25.tar.gz
[root@CentOSX ~]# tar -zxf db-4.7.25.tar.gz
[root@CentOSX ~]# cd db-4.7.25
[root@CentOSX db-4.7.25]# cd build_unix/
[root@CentOSX build_unix]# ./../dist/configure
[root@CentOSX build_unix]# make
[root@CentOSX build_unix]# make install
  • 安装FastDHT
[root@CentOSX ~]# tar zxf FastDHT_v2.01.tar.gz
[root@CentOSX ~]# cd FastDHT
[root@CentOSX FastDHT]# ./make.sh
[root@CentOSX FastDHT]# ./make.sh install

安装结束后会在/etc⽬录下产⽣fdht⽂件夹

[root@CentOSX FastDHT]# tree /etc/fdht/
/etc/fdht/
!"" fdht_client.conf
!"" fdhtd.conf
#"" fdht_servers.conf
  • 修改fdhtd.conf
[root@CentOSX ~]# mkdir /data/fastdht
[root@CentOSX ~]# vi /etc/fdht/fdhtd.conf
base_path=/data/fastdht
  • 修改fdht_servers.conf
[root@CentOSX ~]# vi /etc/fdht/fdht_servers.conf
group_count = 3
group0 = CentOSA:11411
group1 = CentOSB:11411
group2 = CentOSC:11411
  • 修改fdht_client.conf配置⽂件
[root@CentOSX ~]# vi /etc/fdht/fdht_client.conf
base_path=/tmp/
  • 启动FDHT服务
[root@CentOSX ~]# fdhtd /etc/fdht/fdhtd.conf start|stop|restart
[root@CentOSX ~]# ps -axu| grep fd
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 29127 0.0 0.8 195200 17504 ? Sl 00:38 0:00 fdhtd
/etc/fdht/fdhtd.conf start
root 29193 0.0 0.0 103320 884 pts/0 S+ 00:39 0:00 grep fd
root 128672 0.2 0.1 275856 2204 ? Sl 00:14 0:03
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root 128710 1.8 3.2 85584 67188 ? Sl 00:14 0:27
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

操作FastDHT服务

  • 设置值
[root@CentOSX ~]# fdht_set /etc/fdht/fdht_client.conf jiangzz:user001
name='jiangzz',age=18;
This is FastDHT client test program v2.01
Copyright (C) 2008, Happy Fish / YuQing
FastDHT may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDHT source kit.
Please visit the FastDHT Home Page http://www.csource.org/
for more detail.
success set key count: 2, fail count: 0
  • 读取值
[root@CentOSX ~]# fdht_get /etc/fdht/fdht_client.conf jiangzz:user001 name,age
This is FastDHT client test program v2.01
Copyright (C) 2008, Happy Fish / YuQing
FastDHT may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDHT source kit.
Please visit the FastDHT Home Page http://www.csource.org/
for more detail.
name=jiangzz
age=18
success get key count: 2, fail count: 0
  • 删除值
[root@CentOSX ~]# fdht_delete /etc/fdht/fdht_client.conf jiangzz:user001 name;
This is FastDHT client test program v2.01
Copyright (C) 2008, Happy Fish / YuQing
FastDHT may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDHT source kit.
Please visit the FastDHT Home Page http://www.csource.org/
for more detail.
success delete keys: name
success delete key count: 1, fail count: 0
集成FastDHT
  • 修改etc/fdfs/storage.conf配置⽂件
[root@CentOSX ~]# vi /etc/fdfs/storage.conf
check_file_duplicate=1
keep_alive=1
#include /etc/fdht/fdht_servers.conf
  • 分别启动fdhtd服务、fastfs
[root@CentOSX usr]# /usr/local/bin/fdhtd /etc/fdht/fdhtd.conf restart
[root@CentOSX usr]# /etc/init.d/fdfs_trackerd restart
[root@CentOSX usr]# /etc/init.d/fdfs_storaged restart
  • 上传⽂件测试
[root@CentOSA ~]# fdfs_upload_file /etc/fdfs/client.conf install.log
group2/M00/00/00/wKikgl0qC4KAErBTAAAixXWAIyY133.log
[root@CentOSA ~]# fdfs_upload_file /etc/fdfs/client.conf install.log
group2/M00/00/00/wKikgl0qDAqAa0XwAAAixWB5m1c851.log
[root@CentOSB ~]# ls -l /data/fdfs/storage/store01/data/00/00/
total 20
lrwxrwxrwx. 1 root root 72 Jul 14 00:49 wKikgl0qC4KAErBTAAAixXWAIyY133.log ->
/data/fdfs/storage/store01/data/00/00/wKikgl0qC4KARrYBAAAixZ60QfI755.log
-rw-r--r--. 1 root root 8901 Jul 14 00:49 wKikgl0qC4KARrYBAAAixZ60QfI755.log
lrwxrwxrwx. 1 root root 72 Jul 14 00:51 wKikgl0qDAqAa0XwAAAixWB5m1c851.log ->
/data/fdfs/storage/store01/data/00/00/wKikgl0qC4KARrYBAAAixZ60QfI755.log

可以看出系统产⽣了wKikgl0qC4KAErBTAAAixXWAIyY133.log的两个链接

SpringBoot集成FastDFS
引⼊依赖
<dependency>
 <groupId>com.github.tobato</groupId>
 <artifactId>fastdfs-client</artifactId>
 <version>1.26.6</version>
</dependency>
配置application.properties
fdfs.tracker-list=CentOSA:22122,CentOSB:22122,CentOSC:22122
# 配置默认缩略图
fdfs.thumb-image.height=80
fdfs.thumb-image.width=80
测试⽂件上传
@Autowired
private FastFileStorageClient fastFileStorageClient;
  • ⽂件上传
FileInputStream inputStream = new FileInputStream("G:/素材资料/61850.png");
FastImageFile fastImageFile=new
FastImageFile(inputStream,inputStream.available(),"png",new HashSet<MetaData>());
StorePath storePath = fastFileStorageClient.uploadImage(fastImageFile);
System.out.println(storePath.getFullPath());
  • 图⽚上传(缩略图)
FileInputStream inputStream = new FileInputStream("G:/素材资料/61850.png");
FastImageFile fastImageFile=new
FastImageFile(inputStream,inputStream.available(),"png",new HashSet<MetaData>(),new
ThumbImage(150,150));
StorePath storePath = fastFileStorageClient.uploadImage(fastImageFile);
System.out.println(storePath.getFullPath());
  • 删除⽂件
fastFileStorageClient.deleteFile("group3","M00/00/00/wKjvgl0prl6AX6ygAL26hh1kYdE312_80
x80.png");
  • ⽂件下载(⽤不到)
ByteArrayOutputStream baos = fastFileStorageClient.downloadFile("group3",
"M00/00/00/wKjvgl0prTSAMjeTAL26hhzQmiQ959.png", new
DownloadCallback<ByteArrayOutputStream>() {
 @Override
 public ByteArrayOutputStream recv(InputStream ins) throws IOException {
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 IOUtils.copy(ins, baos);
 return baos;
 }
 });
IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()),new FileOutputStream("G:/素材
资料/baby.png"));
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值